diff --git a/src/java/org/apache/lucene/index/IndexReader.java b/src/java/org/apache/lucene/index/IndexReader.java
index aff527eed12..2b02efd19bb 100644
--- a/src/java/org/apache/lucene/index/IndexReader.java
+++ b/src/java/org/apache/lucene/index/IndexReader.java
@@ -23,6 +23,7 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.Lock;
+import org.apache.lucene.util.Constants;
import java.io.File;
import java.io.FileOutputStream;
@@ -199,7 +200,7 @@ public abstract class IndexReader {
* @deprecated Replaced by {@link #getCurrentVersion(File)}
* */
public static long lastModified(File directory) throws IOException {
- return FSDirectory.fileModified(directory, "segments");
+ return FSDirectory.fileModified(directory, Constants.INDEX_SEGMENTS_FILENAME);
}
/**
@@ -214,7 +215,7 @@ public abstract class IndexReader {
* @deprecated Replaced by {@link #getCurrentVersion(Directory)}
* */
public static long lastModified(Directory directory) throws IOException {
- return directory.fileModified("segments");
+ return directory.fileModified(Constants.INDEX_SEGMENTS_FILENAME);
}
/**
@@ -316,7 +317,7 @@ public abstract class IndexReader {
* @return true
if an index exists; false
otherwise
*/
public static boolean indexExists(String directory) {
- return (new File(directory, "segments")).exists();
+ return (new File(directory, Constants.INDEX_SEGMENTS_FILENAME)).exists();
}
/**
@@ -326,7 +327,7 @@ public abstract class IndexReader {
* @return true
if an index exists; false
otherwise
*/
public static boolean indexExists(File directory) {
- return (new File(directory, "segments")).exists();
+ return (new File(directory, Constants.INDEX_SEGMENTS_FILENAME)).exists();
}
/**
@@ -337,7 +338,7 @@ public abstract class IndexReader {
* @throws IOException if there is a problem with accessing the index
*/
public static boolean indexExists(Directory directory) throws IOException {
- return directory.fileExists("segments");
+ return directory.fileExists(Constants.INDEX_SEGMENTS_FILENAME);
}
/** Returns the number of documents in this index. */
diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java
index 3bacea207de..24550566938 100644
--- a/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/src/java/org/apache/lucene/index/IndexWriter.java
@@ -28,6 +28,7 @@ import org.apache.lucene.store.Lock;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.search.Similarity;
+import org.apache.lucene.util.Constants;
import org.apache.lucene.document.Document;
import org.apache.lucene.analysis.Analyzer;
@@ -789,10 +790,10 @@ public class IndexWriter {
private final Vector readDeleteableFiles() throws IOException {
Vector result = new Vector();
- if (!directory.fileExists("deletable"))
+ if (!directory.fileExists(Constants.INDEX_DELETABLE_FILENAME))
return result;
- IndexInput input = directory.openInput("deletable");
+ IndexInput input = directory.openInput(Constants.INDEX_DELETABLE_FILENAME);
try {
for (int i = input.readInt(); i > 0; i--) // read file names
result.addElement(input.readString());
@@ -811,6 +812,6 @@ public class IndexWriter {
} finally {
output.close();
}
- directory.renameFile("deleteable.new", "deletable");
+ directory.renameFile("deleteable.new", Constants.INDEX_DELETABLE_FILENAME);
}
}
diff --git a/src/java/org/apache/lucene/index/SegmentInfos.java b/src/java/org/apache/lucene/index/SegmentInfos.java
index 418c6333b56..e0feb0c4754 100644
--- a/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.Constants;
final class SegmentInfos extends Vector {
@@ -41,7 +42,7 @@ final class SegmentInfos extends Vector {
public final void read(Directory directory) throws IOException {
- IndexInput input = directory.openInput("segments");
+ IndexInput input = directory.openInput(Constants.INDEX_SEGMENTS_FILENAME);
try {
int format = input.readInt();
if(format < 0){ // file contains explicit format info
@@ -91,7 +92,7 @@ final class SegmentInfos extends Vector {
}
// install new segment info
- directory.renameFile("segments.new", "segments");
+ directory.renameFile("segments.new", Constants.INDEX_SEGMENTS_FILENAME);
}
/**
@@ -107,7 +108,7 @@ final class SegmentInfos extends Vector {
public static long readCurrentVersion(Directory directory)
throws IOException {
- IndexInput input = directory.openInput("segments");
+ IndexInput input = directory.openInput(Constants.INDEX_SEGMENTS_FILENAME);
int format = 0;
long version = 0;
try {
diff --git a/src/java/org/apache/lucene/store/FSDirectory.java b/src/java/org/apache/lucene/store/FSDirectory.java
index bf6020d8625..d57d1a9dd3c 100644
--- a/src/java/org/apache/lucene/store/FSDirectory.java
+++ b/src/java/org/apache/lucene/store/FSDirectory.java
@@ -52,8 +52,8 @@ public class FSDirectory extends Directory {
if (name.endsWith("."+IndexReader.FILENAME_EXTENSIONS[i]))
return true;
}
- if (name.equals("deletable")) return true;
- else if (name.equals("segments")) return true;
+ if (name.equals(Constants.INDEX_DELETABLE_FILENAME)) return true;
+ else if (name.equals(Constants.INDEX_SEGMENTS_FILENAME)) return true;
else if (name.matches(".+\\.f\\d+")) return true;
return false;
}
diff --git a/src/java/org/apache/lucene/util/Constants.java b/src/java/org/apache/lucene/util/Constants.java
index 5ee313b11c0..987f0176ae5 100644
--- a/src/java/org/apache/lucene/util/Constants.java
+++ b/src/java/org/apache/lucene/util/Constants.java
@@ -26,6 +26,11 @@ package org.apache.lucene.util;
public final class Constants {
private Constants() {} // can't construct
+ /** Name of the index segment file */
+ public static final String INDEX_SEGMENTS_FILENAME = "segments";
+ /** Name of the index deletable file */
+ public static final String INDEX_DELETABLE_FILENAME = "deletable";
+
/** The value of System.getProperty("java.version"). **/
public static final String JAVA_VERSION = System.getProperty("java.version");
/** True iff this is Java version 1.1. */