lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bmes...@apache.org
Subject svn commit: r151381 - in lucene/java/trunk/src/java/org/apache/lucene/index: CompoundFileReader.java IndexReader.java
Date Fri, 04 Feb 2005 17:45:18 GMT
Author: bmesser
Date: Fri Feb  4 09:45:16 2005
New Revision: 151381

URL: http://svn.apache.org/viewcvs?view=rev&rev=151381
Log:
move static main method to list and optionally extract the individual file from a compound
index from CompoundFileReader to IndexReader. It is more cleaner to have the method in IndexReader
because it is well documented and public available.

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java?view=diff&r1=151380&r2=151381
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/CompoundFileReader.java Fri Feb  4
09:45:16 2005
@@ -238,82 +238,5 @@
 
 
     }
-
-    /**
-     * Prints the filename and size of each file within a given compound file.
-     * Add the -extract flag to extract files to the current working directory.
-     * In order to make the extracted version of the index work, you have to copy
-     * the segments file from the compound index into the directory where the extracted files
are stored.
-     * @param args
-     */
-    public static void main(String [] args) {
-      String dirname = null, filename = null;
-      boolean extract = false;
-
-      for (int i = 0; i < args.length; ++i) {
-        if (args[i].equals("-extract")) {
-          extract = true;
-        } else if (dirname == null) {
-          dirname = args[i];
-        } else if (filename == null) {
-          filename = args[i];
-        }
-      }
-
-      if (dirname == null || filename == null) {
-        System.out.println("Usage: CompoundFileReader [-extract] <directory> <cfsfile>");
-        return;
-      }
-
-      Directory dir = null;
-      CompoundFileReader cfr = null;
-        
-      try {
-        dir = FSDirectory.getDirectory(dirname, false);
-
-        cfr = new CompoundFileReader(dir, filename);
-
-        String [] files = cfr.list();
-        Arrays.sort(files);   // sort the array of filename so that the output is more readable
-        
-        for (int i = 0; i < files.length; ++i) {
-          long len = cfr.fileLength(files[i]);
-
-          if (extract) {
-            System.out.println("extract " + files[i] + " with " + len + " bytes to local
directory...");
-            IndexInput ii = cfr.openInput(files[i]);
-
-            FileOutputStream f = new FileOutputStream(files[i]);
-            
-            // read and write with a small buffer, which is more effectiv than reading byte
by byte
-            byte[] buffer = new byte[1024];
-            int chunk = buffer.length;
-            while(len > 0) {
-              final int bufLen = (int) Math.min(chunk, len);
-              ii.readBytes(buffer, 0, bufLen);
-              f.write(buffer, 0, bufLen);
-              len -= bufLen;
-            }
-            
-            f.close();
-            ii.close();
-          }
-          else
-            System.out.println(files[i] + ": " + len + " bytes");
-        }
-      } catch (IOException ioe) {
-        ioe.printStackTrace();
-      }
-      finally {
-        try {
-          if (dir != null)
-            dir.close();
-          if (cfr != null)
-            cfr.close();
-        }
-        catch (IOException ioe) {
-          ioe.printStackTrace();
-        }
-      }
-    }
+    
 }

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?view=diff&r1=151380&r2=151381
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Fri Feb  4 09:45:16
2005
@@ -21,10 +21,13 @@
 import org.apache.lucene.search.Similarity;
 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 java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
@@ -667,5 +670,83 @@
   public static void unlock(Directory directory) throws IOException {
     directory.makeLock(IndexWriter.WRITE_LOCK_NAME).release();
     directory.makeLock(IndexWriter.COMMIT_LOCK_NAME).release();
+  }
+  
+  /**
+   * Prints the filename and size of each file within a given compound file.
+   * Add the -extract flag to extract files to the current working directory.
+   * In order to make the extracted version of the index work, you have to copy
+   * the segments file from the compound index into the directory where the extracted files
are stored.
+   * @param args
+   */
+  public static void main(String [] args) {
+    String dirname = null, filename = null;
+    boolean extract = false;
+
+    for (int i = 0; i < args.length; ++i) {
+      if (args[i].equals("-extract")) {
+        extract = true;
+      } else if (dirname == null) {
+        dirname = args[i];
+      } else if (filename == null) {
+        filename = args[i];
+      }
+    }
+
+    if (dirname == null || filename == null) {
+      System.out.println("Usage: org.apache.lucene.index.IndexReader [-extract] <directory>
<cfsfile>");
+      return;
+    }
+
+    Directory dir = null;
+    CompoundFileReader cfr = null;
+      
+    try {
+      dir = FSDirectory.getDirectory(dirname, false);
+
+      cfr = new CompoundFileReader(dir, filename);
+
+      String [] files = cfr.list();
+      Arrays.sort(files);   // sort the array of filename so that the output is more readable
+      
+      for (int i = 0; i < files.length; ++i) {
+        long len = cfr.fileLength(files[i]);
+
+        if (extract) {
+          System.out.println("extract " + files[i] + " with " + len + " bytes to local directory...");
+          IndexInput ii = cfr.openInput(files[i]);
+
+          FileOutputStream f = new FileOutputStream(files[i]);
+          
+          // read and write with a small buffer, which is more effectiv than reading byte
by byte
+          byte[] buffer = new byte[1024];
+          int chunk = buffer.length;
+          while(len > 0) {
+            final int bufLen = (int) Math.min(chunk, len);
+            ii.readBytes(buffer, 0, bufLen);
+            f.write(buffer, 0, bufLen);
+            len -= bufLen;
+          }
+          
+          f.close();
+          ii.close();
+        }
+        else
+          System.out.println(files[i] + ": " + len + " bytes");
+      }
+    } catch (IOException ioe) {
+      ioe.printStackTrace();
+    }
+    finally {
+      try {
+        if (dir != null)
+          dir.close();
+        if (cfr != null)
+          cfr.close();
+      }
+      catch (IOException ioe) {
+        ioe.printStackTrace();
+      }
+    }
   }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-dev-help@jakarta.apache.org


Mime
View raw message