Index: modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishQueryMaker.java
===================================================================
--- modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishQueryMaker.java (revision 1221266)
+++ modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishQueryMaker.java (working copy)
@@ -1,3 +1,5 @@
+package org.apache.lucene.benchmark.byTask.feeds;
+
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -15,7 +17,7 @@
* limitations under the License.
*/
-package org.apache.lucene.benchmark.byTask.feeds;
+import java.util.Locale;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
@@ -23,10 +25,9 @@
import org.apache.lucene.benchmark.byTask.utils.Config;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.Query;
-import org.apache.lucene.util.English;
import org.apache.lucene.util.Version;
+import com.ibm.icu.text.RuleBasedNumberFormat;
-
/**
*
*
@@ -35,13 +36,16 @@
long counter = Long.MIN_VALUE + 10;
protected QueryParser parser;
+ // TODO: we could take param to specify locale...
+ private final RuleBasedNumberFormat rnbf = new RuleBasedNumberFormat(Locale.ENGLISH,
+ RuleBasedNumberFormat.SPELLOUT);
+
public Query makeQuery(int size) throws Exception {
throw new UnsupportedOperationException();
}
public synchronized Query makeQuery() throws Exception {
-
- return parser.parse("" + English.longToEnglish(getNextCounter()) + "");
+ return parser.parse("" + rnbf.format(getNextCounter()) + "");
}
private synchronized long getNextCounter() {
Index: modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishContentSource.java
===================================================================
--- modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishContentSource.java (revision 1221266)
+++ modules/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/LongToEnglishContentSource.java (working copy)
@@ -17,11 +17,12 @@
* limitations under the License.
*/
-import org.apache.lucene.util.English;
-
import java.io.IOException;
import java.util.Date;
+import java.util.Locale;
+import com.ibm.icu.text.RuleBasedNumberFormat;
+
/**
* Creates documents whose content is a long number starting from
* {@link Long#MIN_VALUE} + 10.
@@ -32,7 +33,10 @@
@Override
public void close() throws IOException {
}
-
+
+ // TODO: we could take param to specify locale...
+ private final RuleBasedNumberFormat rnbf = new RuleBasedNumberFormat(Locale.ENGLISH,
+ RuleBasedNumberFormat.SPELLOUT);
@Override
public synchronized DocData getNextDocData(DocData docData) throws NoMoreDataException, IOException {
docData.clear();
@@ -46,7 +50,8 @@
++counter;
}
}
- docData.setBody(English.longToEnglish(curCounter));
+
+ docData.setBody(rnbf.format(curCounter));
docData.setName("doc_" + String.valueOf(curCounter));
docData.setTitle("title_" + String.valueOf(curCounter));
docData.setDate(new Date());
Index: modules/benchmark/build.xml
===================================================================
--- modules/benchmark/build.xml (revision 1221266)
+++ modules/benchmark/build.xml (working copy)
@@ -154,6 +154,7 @@
+
Index: lucene/CHANGES.txt
===================================================================
--- lucene/CHANGES.txt (revision 1221266)
+++ lucene/CHANGES.txt (working copy)
@@ -737,6 +737,10 @@
* LUCENE-3586: CheckIndex and IndexUpgrader allow you to specify the
specific FSDirectory implementation to use (with the new -dir-impl
command-line option). (Luca Cavanna via Mike McCandless)
+
+* LUCENE-3634: IndexReader's static main method was moved to a new
+ tool, CompoundFileExtractor, in contrib/misc. (Robert Muir, Mike
+ McCandless)
Bug fixes
Index: lucene/src/test/org/apache/lucene/TestSearch.java
===================================================================
--- lucene/src/test/org/apache/lucene/TestSearch.java (revision 1221266)
+++ lucene/src/test/org/apache/lucene/TestSearch.java (working copy)
@@ -24,8 +24,6 @@
import java.io.StringWriter;
import org.apache.lucene.util.LuceneTestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
import org.apache.lucene.store.*;
import org.apache.lucene.document.*;
@@ -36,11 +34,6 @@
/** JUnit adaptation of an older test case SearchTest. */
public class TestSearch extends LuceneTestCase {
- /** Main for running test case by itself. */
- public static void main(String args[]) {
- TestRunner.run (new TestSuite(TestSearch.class));
- }
-
/** This test performs a number of searches. It also compares output
* of searches using multi-file index segments with single-file
* index segments.
Index: lucene/src/test/org/apache/lucene/index/TestDoc.java
===================================================================
--- lucene/src/test/org/apache/lucene/index/TestDoc.java (revision 1221266)
+++ lucene/src/test/org/apache/lucene/index/TestDoc.java (working copy)
@@ -26,8 +26,6 @@
import java.util.LinkedList;
import java.util.Collection;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.codecs.Codec;
@@ -45,11 +43,6 @@
/** JUnit adaptation of an older test case DocTest. */
public class TestDoc extends LuceneTestCase {
- /** Main for running test case by itself. */
- public static void main(String args[]) {
- TestRunner.run (new TestSuite(TestDoc.class));
- }
-
private File workDir;
private File indexDir;
private LinkedList files;
Index: lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java
===================================================================
--- lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java (revision 1221266)
+++ lucene/src/test/org/apache/lucene/TestSearchForDuplicates.java (working copy)
@@ -28,18 +28,9 @@
import org.apache.lucene.index.*;
import org.apache.lucene.search.*;
import org.apache.lucene.util.LuceneTestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
public class TestSearchForDuplicates extends LuceneTestCase {
- /** Main for running test case by itself. */
- public static void main(String args[]) {
- TestRunner.run (new TestSuite(TestSearchForDuplicates.class));
- }
-
-
-
static final String PRIORITY_FIELD ="priority";
static final String ID_FIELD ="id";
static final String HIGH_PRIORITY ="high";
Index: lucene/src/test/org/apache/lucene/util/TestSortedVIntList.java
===================================================================
--- lucene/src/test/org/apache/lucene/util/TestSortedVIntList.java (revision 1221266)
+++ lucene/src/test/org/apache/lucene/util/TestSortedVIntList.java (working copy)
@@ -20,16 +20,10 @@
import java.io.IOException;
import java.util.BitSet;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
import org.apache.lucene.search.DocIdSetIterator;
public class TestSortedVIntList extends LuceneTestCase {
- /** Main for running test case by itself. */
- public static void main(String args[]) {
- TestRunner.run(new TestSuite(TestSortedVIntList.class));
- }
void tstIterator (
SortedVIntList vintList,
Index: lucene/src/java/org/apache/lucene/index/IndexReader.java
===================================================================
--- lucene/src/java/org/apache/lucene/index/IndexReader.java (revision 1221266)
+++ lucene/src/java/org/apache/lucene/index/IndexReader.java (working copy)
@@ -18,8 +18,6 @@
*/
import java.io.Closeable;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
@@ -32,10 +30,8 @@
import org.apache.lucene.document.DocumentStoredFieldVisitor;
import org.apache.lucene.search.SearcherManager; // javadocs
import org.apache.lucene.store.*;
-import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
-import org.apache.lucene.util.CommandLineUtil;
import org.apache.lucene.util.MapBackedSet;
import org.apache.lucene.util.ReaderUtil; // for javadocs
@@ -947,101 +943,6 @@
throw new UnsupportedOperationException("This reader does not support this method.");
}
- /**
- * 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 Usage: org.apache.lucene.index.IndexReader [-extract] <cfsfile>
- */
- public static void main(String [] args) {
- String filename = null;
- boolean extract = false;
- String dirImpl = null;
-
- int j = 0;
- while(j < args.length) {
- String arg = args[j];
- if ("-extract".equals(arg)) {
- extract = true;
- } else if ("-dir-impl".equals(arg)) {
- if (j == args.length - 1) {
- System.out.println("ERROR: missing value for -dir-impl option");
- System.exit(1);
- }
- j++;
- dirImpl = args[j];
- } else if (filename == null) {
- filename = arg;
- }
- j++;
- }
-
- if (filename == null) {
- System.out.println("Usage: org.apache.lucene.index.IndexReader [-extract] [-dir-impl X] ");
- return;
- }
-
- Directory dir = null;
- CompoundFileDirectory cfr = null;
- IOContext context = IOContext.READ;
-
- try {
- File file = new File(filename);
- String dirname = file.getAbsoluteFile().getParent();
- filename = file.getName();
- if (dirImpl == null) {
- dir = FSDirectory.open(new File(dirname));
- } else {
- dir = CommandLineUtil.newFSDirectory(dirImpl, new File(dirname));
- }
-
- cfr = new CompoundFileDirectory(dir, filename, IOContext.DEFAULT, false);
-
- String [] files = cfr.listAll();
- ArrayUtil.mergeSort(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], context);
-
- FileOutputStream f = new FileOutputStream(files[i]);
-
- // read and write with a small buffer, which is more effective 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();
- }
- }
- }
-
/** Returns all commit points that exist in the Directory.
* Normally, because the default is {@link
* KeepOnlyLastCommitDeletionPolicy}, there would be only
Index: lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java
===================================================================
--- lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java (revision 1221266)
+++ lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java (working copy)
@@ -310,17 +310,4 @@
utf8StateCount++;
return s;
}
-
- public static void main(String[] args) {
- final int startCode = Integer.parseInt(args[0]);
- final int endCode = Integer.parseInt(args[1]);
-
- Automaton a = new Automaton();
- State start = a.getInitialState();
- State end = new State();
- end.setAccept(true);
-
- UTF32ToUTF8 converter = new UTF32ToUTF8();
- converter.convertOneEdge(start, end, startCode, endCode);
- }
}
Index: lucene/src/java/org/apache/lucene/util/English.java
===================================================================
--- lucene/src/java/org/apache/lucene/util/English.java (revision 1221266)
+++ lucene/src/java/org/apache/lucene/util/English.java (working copy)
@@ -1,190 +0,0 @@
-package org.apache.lucene.util;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * @lucene.internal
- */
-public final class English {
-
- private English() {} // no instance
-
- public static String longToEnglish(long i) {
- StringBuilder result = new StringBuilder();
- longToEnglish(i, result);
- return result.toString();
- }
-
- public static void longToEnglish(long i, StringBuilder result) {
- if (i == 0) {
- result.append("zero");
- return;
- }
- if (i < 0) {
- result.append("minus ");
- i = -i;
- }
- if (i >= 1000000000000000000l) { // quadrillion
- longToEnglish(i / 1000000000000000000l, result);
- result.append("quintillion, ");
- i = i % 1000000000000000000l;
- }
- if (i >= 1000000000000000l) { // quadrillion
- longToEnglish(i / 1000000000000000l, result);
- result.append("quadrillion, ");
- i = i % 1000000000000000l;
- }
- if (i >= 1000000000000l) { // trillions
- longToEnglish(i / 1000000000000l, result);
- result.append("trillion, ");
- i = i % 1000000000000l;
- }
- if (i >= 1000000000) { // billions
- longToEnglish(i / 1000000000, result);
- result.append("billion, ");
- i = i % 1000000000;
- }
- if (i >= 1000000) { // millions
- longToEnglish(i / 1000000, result);
- result.append("million, ");
- i = i % 1000000;
- }
- if (i >= 1000) { // thousands
- longToEnglish(i / 1000, result);
- result.append("thousand, ");
- i = i % 1000;
- }
- if (i >= 100) { // hundreds
- longToEnglish(i / 100, result);
- result.append("hundred ");
- i = i % 100;
- }
- //we know we are smaller here so we can cast
- if (i >= 20) {
- switch (((int) i) / 10) {
- case 9:
- result.append("ninety");
- break;
- case 8:
- result.append("eighty");
- break;
- case 7:
- result.append("seventy");
- break;
- case 6:
- result.append("sixty");
- break;
- case 5:
- result.append("fifty");
- break;
- case 4:
- result.append("forty");
- break;
- case 3:
- result.append("thirty");
- break;
- case 2:
- result.append("twenty");
- break;
- }
- i = i % 10;
- if (i == 0)
- result.append(" ");
- else
- result.append("-");
- }
- switch ((int) i) {
- case 19:
- result.append("nineteen ");
- break;
- case 18:
- result.append("eighteen ");
- break;
- case 17:
- result.append("seventeen ");
- break;
- case 16:
- result.append("sixteen ");
- break;
- case 15:
- result.append("fifteen ");
- break;
- case 14:
- result.append("fourteen ");
- break;
- case 13:
- result.append("thirteen ");
- break;
- case 12:
- result.append("twelve ");
- break;
- case 11:
- result.append("eleven ");
- break;
- case 10:
- result.append("ten ");
- break;
- case 9:
- result.append("nine ");
- break;
- case 8:
- result.append("eight ");
- break;
- case 7:
- result.append("seven ");
- break;
- case 6:
- result.append("six ");
- break;
- case 5:
- result.append("five ");
- break;
- case 4:
- result.append("four ");
- break;
- case 3:
- result.append("three ");
- break;
- case 2:
- result.append("two ");
- break;
- case 1:
- result.append("one ");
- break;
- case 0:
- result.append("");
- break;
- }
- }
-
-
- public static String intToEnglish(int i) {
- StringBuilder result = new StringBuilder();
- longToEnglish(i, result);
- return result.toString();
- }
-
- public static void intToEnglish(int i, StringBuilder result) {
- longToEnglish(i, result);
- }
-
- public static void main(String[] args) {
- System.out.println(longToEnglish(Long.parseLong(args[0])));
- }
-
-}
Index: lucene/src/test-framework/java/org/apache/lucene/util/English.java
===================================================================
--- lucene/src/test-framework/java/org/apache/lucene/util/English.java (revision 0)
+++ lucene/src/test-framework/java/org/apache/lucene/util/English.java (working copy)
@@ -0,0 +1,185 @@
+package org.apache.lucene.util;
+
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @lucene.internal
+ */
+public final class English {
+
+ private English() {} // no instance
+
+ public static String longToEnglish(long i) {
+ StringBuilder result = new StringBuilder();
+ longToEnglish(i, result);
+ return result.toString();
+ }
+
+ public static void longToEnglish(long i, StringBuilder result) {
+ if (i == 0) {
+ result.append("zero");
+ return;
+ }
+ if (i < 0) {
+ result.append("minus ");
+ i = -i;
+ }
+ if (i >= 1000000000000000000l) { // quadrillion
+ longToEnglish(i / 1000000000000000000l, result);
+ result.append("quintillion, ");
+ i = i % 1000000000000000000l;
+ }
+ if (i >= 1000000000000000l) { // quadrillion
+ longToEnglish(i / 1000000000000000l, result);
+ result.append("quadrillion, ");
+ i = i % 1000000000000000l;
+ }
+ if (i >= 1000000000000l) { // trillions
+ longToEnglish(i / 1000000000000l, result);
+ result.append("trillion, ");
+ i = i % 1000000000000l;
+ }
+ if (i >= 1000000000) { // billions
+ longToEnglish(i / 1000000000, result);
+ result.append("billion, ");
+ i = i % 1000000000;
+ }
+ if (i >= 1000000) { // millions
+ longToEnglish(i / 1000000, result);
+ result.append("million, ");
+ i = i % 1000000;
+ }
+ if (i >= 1000) { // thousands
+ longToEnglish(i / 1000, result);
+ result.append("thousand, ");
+ i = i % 1000;
+ }
+ if (i >= 100) { // hundreds
+ longToEnglish(i / 100, result);
+ result.append("hundred ");
+ i = i % 100;
+ }
+ //we know we are smaller here so we can cast
+ if (i >= 20) {
+ switch (((int) i) / 10) {
+ case 9:
+ result.append("ninety");
+ break;
+ case 8:
+ result.append("eighty");
+ break;
+ case 7:
+ result.append("seventy");
+ break;
+ case 6:
+ result.append("sixty");
+ break;
+ case 5:
+ result.append("fifty");
+ break;
+ case 4:
+ result.append("forty");
+ break;
+ case 3:
+ result.append("thirty");
+ break;
+ case 2:
+ result.append("twenty");
+ break;
+ }
+ i = i % 10;
+ if (i == 0)
+ result.append(" ");
+ else
+ result.append("-");
+ }
+ switch ((int) i) {
+ case 19:
+ result.append("nineteen ");
+ break;
+ case 18:
+ result.append("eighteen ");
+ break;
+ case 17:
+ result.append("seventeen ");
+ break;
+ case 16:
+ result.append("sixteen ");
+ break;
+ case 15:
+ result.append("fifteen ");
+ break;
+ case 14:
+ result.append("fourteen ");
+ break;
+ case 13:
+ result.append("thirteen ");
+ break;
+ case 12:
+ result.append("twelve ");
+ break;
+ case 11:
+ result.append("eleven ");
+ break;
+ case 10:
+ result.append("ten ");
+ break;
+ case 9:
+ result.append("nine ");
+ break;
+ case 8:
+ result.append("eight ");
+ break;
+ case 7:
+ result.append("seven ");
+ break;
+ case 6:
+ result.append("six ");
+ break;
+ case 5:
+ result.append("five ");
+ break;
+ case 4:
+ result.append("four ");
+ break;
+ case 3:
+ result.append("three ");
+ break;
+ case 2:
+ result.append("two ");
+ break;
+ case 1:
+ result.append("one ");
+ break;
+ case 0:
+ result.append("");
+ break;
+ }
+ }
+
+
+ public static String intToEnglish(int i) {
+ StringBuilder result = new StringBuilder();
+ longToEnglish(i, result);
+ return result.toString();
+ }
+
+ public static void intToEnglish(int i, StringBuilder result) {
+ longToEnglish(i, result);
+ }
+}
Property changes on: lucene/src/test-framework/java/org/apache/lucene/util/English.java
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.2
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
Added: svn:eol-style
## -0,0 +1 ##
+native
Index: lucene/contrib/CHANGES.txt
===================================================================
--- lucene/contrib/CHANGES.txt (revision 1221266)
+++ lucene/contrib/CHANGES.txt (working copy)
@@ -99,6 +99,9 @@
* LUCENE-3596: DirectoryTaxonomyWriter extensions can override createIndexWriterConfig()
and modify how its internal index writer is opened. (Doron Cohen)
+* LUCENE-3634: IndexReader's static main method was moved to a new
+ tool, CompoundFileExtractor, in contrib/misc. (Mike McCandless)
+
API Changes
* LUCENE-3596: DirectoryTaxonomyWriter.openIndexWriter() now takes an
Index: lucene/contrib/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java (revision 0)
+++ lucene/contrib/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java (working copy)
@@ -0,0 +1,129 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.lucene.index;
+
+/**
+ * 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 Usage: org.apache.lucene.index.IndexReader [-extract] <cfsfile>
+ */
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.lucene.store.CompoundFileDirectory;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.CommandLineUtil;
+
+public class CompoundFileExtractor {
+
+ public static void main(String [] args) {
+ String filename = null;
+ boolean extract = false;
+ String dirImpl = null;
+
+ int j = 0;
+ while(j < args.length) {
+ String arg = args[j];
+ if ("-extract".equals(arg)) {
+ extract = true;
+ } else if ("-dir-impl".equals(arg)) {
+ if (j == args.length - 1) {
+ System.out.println("ERROR: missing value for -dir-impl option");
+ System.exit(1);
+ }
+ j++;
+ dirImpl = args[j];
+ } else if (filename == null) {
+ filename = arg;
+ }
+ j++;
+ }
+
+ if (filename == null) {
+ System.out.println("Usage: org.apache.lucene.index.IndexReader [-extract] [-dir-impl X] ");
+ return;
+ }
+
+ Directory dir = null;
+ CompoundFileDirectory cfr = null;
+ IOContext context = IOContext.READ;
+
+ try {
+ File file = new File(filename);
+ String dirname = file.getAbsoluteFile().getParent();
+ filename = file.getName();
+ if (dirImpl == null) {
+ dir = FSDirectory.open(new File(dirname));
+ } else {
+ dir = CommandLineUtil.newFSDirectory(dirImpl, new File(dirname));
+ }
+
+ cfr = new CompoundFileDirectory(dir, filename, IOContext.DEFAULT, false);
+
+ String [] files = cfr.listAll();
+ ArrayUtil.mergeSort(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], context);
+
+ FileOutputStream f = new FileOutputStream(files[i]);
+
+ // read and write with a small buffer, which is more effective 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();
+ }
+ }
+ }
+}
Property changes on: lucene/contrib/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
Index: lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/DistanceCheck.java
===================================================================
--- lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/DistanceCheck.java (revision 1221266)
+++ lucene/contrib/spatial/src/test/org/apache/lucene/spatial/tier/DistanceCheck.java (working copy)
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.lucene.spatial.tier;
-
-import org.apache.lucene.spatial.DistanceUtils;
-
-import java.text.DecimalFormat;
-
-
-public class DistanceCheck {
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- double lat1 = 0;
- double long1 = 0;
- double lat2 = 0;
- double long2 = 0;
-
- for (int i =0; i < 90; i++){
- double dis = DistanceUtils.getDistanceMi(lat1, long1, lat2, long2);
- lat1 +=1;
- lat2 = lat1 + 0.001;
-
- System.out.println(lat1+","+long1+","+lat2+","+long2+","+formatDistance(dis));
-
- }
-
- }
-
- public static String formatDistance (Double d){
- DecimalFormat df1 = new DecimalFormat("####.000000");
- return df1.format(d);
- }
-
-}
Index: lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceHandler.java
===================================================================
--- lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceHandler.java (revision 1221266)
+++ lucene/contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceHandler.java (working copy)
@@ -19,7 +19,6 @@
import org.apache.lucene.spatial.DistanceUtils;
-import java.util.HashMap;
import java.util.Map;
/**
@@ -97,10 +96,4 @@
//all else fails calculate the distances
return DistanceUtils.getDistanceMi(centerLat, centerLng, lat, lng);
}
-
-
- public static void main(String args[]){
- DistanceHandler db = new DistanceHandler(new HashMap(), new HashMap(), Precision.TWOHUNDREDFEET);
- System.out.println(DistanceHandler.getPrecision(-1234.123456789, db.getPrecision()));
- }
}