simplify usage of the main method: directory doesn't need to be specified explicitly anymore

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@208904 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2005-07-03 10:33:33 +00:00
parent d9c75bfad0
commit 899c7a2bfb
1 changed files with 7 additions and 8 deletions

View File

@ -23,7 +23,6 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory; import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.Lock; import org.apache.lucene.store.Lock;
import org.apache.lucene.util.Constants;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
@ -687,24 +686,22 @@ public abstract class IndexReader {
* Add the -extract flag to extract files to the current working directory. * 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 * 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. * the segments file from the compound index into the directory where the extracted files are stored.
* @param args * @param args Usage: org.apache.lucene.index.IndexReader [-extract] <cfsfile>
*/ */
public static void main(String [] args) { public static void main(String [] args) {
String dirname = null, filename = null; String filename = null;
boolean extract = false; boolean extract = false;
for (int i = 0; i < args.length; ++i) { for (int i = 0; i < args.length; ++i) {
if (args[i].equals("-extract")) { if (args[i].equals("-extract")) {
extract = true; extract = true;
} else if (dirname == null) {
dirname = args[i];
} else if (filename == null) { } else if (filename == null) {
filename = args[i]; filename = args[i];
} }
} }
if (dirname == null || filename == null) { if (filename == null) {
System.out.println("Usage: org.apache.lucene.index.IndexReader [-extract] <directory> <cfsfile>"); System.out.println("Usage: org.apache.lucene.index.IndexReader [-extract] <cfsfile>");
return; return;
} }
@ -712,8 +709,10 @@ public abstract class IndexReader {
CompoundFileReader cfr = null; CompoundFileReader cfr = null;
try { try {
File file = new File(filename);
String dirname = file.getAbsoluteFile().getParent();
filename = file.getName();
dir = FSDirectory.getDirectory(dirname, false); dir = FSDirectory.getDirectory(dirname, false);
cfr = new CompoundFileReader(dir, filename); cfr = new CompoundFileReader(dir, filename);
String [] files = cfr.list(); String [] files = cfr.list();