lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmes...@apache.org
Subject svn commit: r180349 - in /lucene/java/trunk/src/java/org/apache/lucene: index/IndexReader.java index/IndexWriter.java index/SegmentInfos.java store/FSDirectory.java util/Constants.java
Date Mon, 06 Jun 2005 17:52:13 GMT
Author: bmesser
Date: Mon Jun  6 10:52:12 2005
New Revision: 180349

URL: http://svn.apache.org/viewcvs?rev=180349&view=rev
Log:
Implement names for "segments" and "deletable" files in Constants. This removes "hardcoded"
filenames and makes code cleaner and easier to maintain.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
    lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?rev=180349&r1=180348&r2=180349&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Mon Jun  6 10:52:12
2005
@@ -23,6 +23,7 @@
 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 @@
    * @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 @@
    * @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 @@
    * @return <code>true</code> if an index exists; <code>false</code>
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 @@
    * @return <code>true</code> if an index exists; <code>false</code>
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 @@
    * @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. */

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?rev=180349&r1=180348&r2=180349&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Mon Jun  6 10:52:12
2005
@@ -28,6 +28,7 @@
 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 @@
 
   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 @@
     } finally {
       output.close();
     }
-    directory.renameFile("deleteable.new", "deletable");
+    directory.renameFile("deleteable.new", Constants.INDEX_DELETABLE_FILENAME);
   }
 }

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java?rev=180349&r1=180348&r2=180349&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/SegmentInfos.java Mon Jun  6 10:52:12
2005
@@ -21,6 +21,7 @@
 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 @@
 
   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 @@
     }
 
     // install new segment info
-    directory.renameFile("segments.new", "segments");
+    directory.renameFile("segments.new", Constants.INDEX_SEGMENTS_FILENAME);
   }
 
   /**
@@ -107,7 +108,7 @@
   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 {

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=180349&r1=180348&r2=180349&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Mon Jun  6 10:52:12
2005
@@ -52,8 +52,8 @@
         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;
     }

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java?rev=180349&r1=180348&r2=180349&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/Constants.java Mon Jun  6 10:52:12 2005
@@ -26,6 +26,11 @@
 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 <tt>System.getProperty("java.version")<tt>. **/
   public static final String JAVA_VERSION = System.getProperty("java.version");
   /** True iff this is Java version 1.1. */



Mime
View raw message