Hello,

I understand the technical reason for main() there, but logically this
belongs to an external utility class, I think.



Otis you are right, i already thought about it. It could be simply moved to a newly created class in org.apache.lucene.util package. But then we have to change the visibility of CompoundFileReader to public. I have no problems with a public CompoundFileReader class. Does anybody see a reason that the visibility of CompoundFileReader should not be changed to public ?

Bernhard


--- Bernhard Messer <[EMAIL PROTECTED]> wrote:



hi,

i already had a look at Garrett's implementation. I made some smaller

changes to improve the performance when extracting the files from the

compound. All tests work fine and the index is usable after
extraction. The new functionality is added as a public static void main () to CompoundFileReader because of the reduced visibility (package) of CompoundFileReader itself. It will be committed this afternoon.


Bernhard



Doug Cutting wrote:



It would be useful to have a command-line utility (i.e., a static main(String[]) method somewhere) that lists the files and sizes contained inside a CFS file, and perhaps even an option to unpack


it.

Anyone care to contribute this method?


Here's a diff to add this functionality to CompoundFileReader. Comments are of course welcome, as I'm not that fantastic a Java


hacker.


-garrett



------------------------------------------------------------------------


Index: src/java/org/apache/lucene/index/CompoundFileReader.java
===================================================================
RCS file:


/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/index/CompoundFileReader.java,v


retrieving revision 1.14
diff -u -r1.14 CompoundFileReader.java
--- src/java/org/apache/lucene/index/CompoundFileReader.java 28 Sep


2004 18:15:52 -0000 1.14


+++ src/java/org/apache/lucene/index/CompoundFileReader.java 25 Dec


2004 04:25:11 -0000


@@ -17,12 +17,14 @@
*/

import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.BufferedIndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.Lock;
import java.util.HashMap;
import java.io.IOException;
+import java.io.FileOutputStream;


/** @@ -233,5 +235,61 @@ }


+ }
+
+ 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 directory


cfsfile");


+ System.out.println("");
+ System.out.println("Prints the filename and size of


each file "


+ + "within cfsfile.");
+ System.out.println("");
+ System.out.println("Add the -extract flag to extract


files to the "


+ + "current working directory.");
+
+ return;
+ }
+
+ try {
+ Directory dir = FSDirectory.getDirectory(dirname,


false);


+
+ CompoundFileReader cfr = new CompoundFileReader(dir,


filename);


+
+ String [] files = cfr.list();
+
+ for (int i = 0; i < files.length; ++i) {
+ long len = cfr.fileLength(files[i]);
+
+ System.out.println(files[i] + "\t: " + len + "


bytes");


+
+ if (extract) {
+ IndexInput ii = cfr.openInput(files[i]);
+
+ FileOutputStream f = new


FileOutputStream(files[i]);


+
+                    while (len-- != 0) {
+                        byte b = ii.readByte();
+                        f.write(b);
+                    }
+
+                    f.close();
+                }
+            }
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+        }
   }
}





------------------------------------------------------------------------


---------------------------------------------------------------------


To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






Reply via email to