You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/09/13 23:46:36 UTC
svn commit: r1624784 [5/7] - in /lucene/dev/trunk: lucene/
lucene/analysis/common/src/java/org/apache/lucene/analysis/charfilter/
lucene/analysis/common/src/java/org/apache/lucene/analysis/compound/
lucene/analysis/common/src/java/org/apache/lucene/ana...
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/directory/DirectoryTaxonomyWriter.java Sat Sep 13 21:46:29 2014
@@ -4,12 +4,9 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
@@ -891,14 +888,14 @@ public class DirectoryTaxonomyWriter imp
* {@link OrdinalMap} maintained on file system
*/
public static final class DiskOrdinalMap implements OrdinalMap {
- File tmpfile;
+ Path tmpfile;
DataOutputStream out;
/** Sole constructor. */
- public DiskOrdinalMap(File tmpfile) throws FileNotFoundException {
+ public DiskOrdinalMap(Path tmpfile) throws IOException {
this.tmpfile = tmpfile;
out = new DataOutputStream(new BufferedOutputStream(
- new FileOutputStream(tmpfile)));
+ Files.newOutputStream(tmpfile)));
}
@Override
@@ -929,7 +926,7 @@ public class DirectoryTaxonomyWriter imp
}
addDone(); // in case this wasn't previously called
DataInputStream in = new DataInputStream(new BufferedInputStream(
- new FileInputStream(tmpfile)));
+ Files.newInputStream(tmpfile)));
map = new int[in.readInt()];
// NOTE: The current code assumes here that the map is complete,
// i.e., every ordinal gets one and exactly one value. Otherwise,
@@ -942,7 +939,7 @@ public class DirectoryTaxonomyWriter imp
in.close();
// Delete the temporary file, which is no longer needed.
- Files.delete(tmpfile.toPath());
+ Files.delete(tmpfile);
return map;
}
Modified: lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java (original)
+++ lucene/dev/trunk/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/writercache/CompactLabelToOrdinal.java Sat Sep 13 21:46:29 2014
@@ -21,10 +21,10 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Iterator;
import org.apache.lucene.facet.taxonomy.FacetLabel;
@@ -352,9 +352,9 @@ public class CompactLabelToOrdinal exten
/**
* Opens the file and reloads the CompactLabelToOrdinal. The file it expects
- * is generated from the {@link #flush(File)} command.
+ * is generated from the {@link #flush(Path)} command.
*/
- static CompactLabelToOrdinal open(File file, float loadFactor,
+ static CompactLabelToOrdinal open(Path file, float loadFactor,
int numHashArrays) throws IOException {
/**
* Part of the file is the labelRepository, which needs to be rehashed
@@ -369,7 +369,7 @@ public class CompactLabelToOrdinal exten
DataInputStream dis = null;
try {
dis = new DataInputStream(new BufferedInputStream(
- new FileInputStream(file)));
+ Files.newInputStream(file)));
// TaxiReader needs to load the "counter" or occupancy (L2O) to know
// the next unique facet. we used to load the delimiter too, but
@@ -433,8 +433,8 @@ public class CompactLabelToOrdinal exten
}
- void flush(File file) throws IOException {
- FileOutputStream fos = new FileOutputStream(file);
+ void flush(Path file) throws IOException {
+ OutputStream fos = Files.newOutputStream(file);
try {
BufferedOutputStream os = new BufferedOutputStream(fos);
Modified: lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCharBlockArray.java Sat Sep 13 21:46:29 2014
@@ -2,13 +2,12 @@ package org.apache.lucene.facet.taxonomy
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.lucene.facet.FacetTestCase;
import org.apache.lucene.util.TestUtil;
@@ -85,14 +84,14 @@ public class TestCharBlockArray extends
assertEqualsInternal("GrowingCharArray<->StringBuilder mismatch.", builder, array);
- File tempDir = createTempDir("growingchararray");
- File f = new File(tempDir, "GrowingCharArrayTest.tmp");
- BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
+ Path tempDir = createTempDir("growingchararray");
+ Path f = tempDir.resolve("GrowingCharArrayTest.tmp");
+ BufferedOutputStream out = new BufferedOutputStream(Files.newOutputStream(f));
array.flush(out);
out.flush();
out.close();
- BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
+ BufferedInputStream in = new BufferedInputStream(Files.newInputStream(f));
array = CharBlockArray.open(in);
assertEqualsInternal("GrowingCharArray<->StringBuilder mismatch after flush/load.", builder, array);
in.close();
Modified: lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java (original)
+++ lucene/dev/trunk/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/writercache/TestCompactLabelToOrdinal.java Sat Sep 13 21:46:29 2014
@@ -1,18 +1,17 @@
package org.apache.lucene.facet.taxonomy.writercache;
-import java.io.File;
import java.nio.ByteBuffer;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import org.apache.lucene.facet.FacetTestCase;
import org.apache.lucene.facet.taxonomy.FacetLabel;
-import org.apache.lucene.util.TestUtil;
import org.junit.Test;
@@ -69,15 +68,15 @@ public class TestCompactLabelToOrdinal e
}
}
- File tmpDir = createTempDir("testLableToOrdinal");
- File f = new File(tmpDir, "CompactLabelToOrdinalTest.tmp");
+ Path tmpDir = createTempDir("testLableToOrdinal");
+ Path f = tmpDir.resolve("CompactLabelToOrdinalTest.tmp");
int flushInterval = 10;
for (int i = 0; i < n; i++) {
if (i > 0 && i % flushInterval == 0) {
compact.flush(f);
compact = CompactLabelToOrdinal.open(f, 0.15f, 3);
- Files.delete(f.toPath());
+ Files.delete(f);
if (flushInterval < (n / 10)) {
flushInterval *= 10;
}
Modified: lucene/dev/trunk/lucene/misc/build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/build.xml?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/build.xml (original)
+++ lucene/dev/trunk/lucene/misc/build.xml Sat Sep 13 21:46:29 2014
@@ -23,6 +23,11 @@
Index tools and other miscellaneous code
</description>
+ <property name="forbidden-base-excludes" value="
+ org/apache/lucene/store/NativeUnixDirectory$NativeUnixIndexInput.class
+ org/apache/lucene/store/NativeUnixDirectory$NativeUnixIndexOutput.class
+ "/>
+
<property name="forbidden-sysout-excludes" value="
org/apache/lucene/index/CompoundFileExtractor.class
org/apache/lucene/index/IndexSplitter.class
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/CompoundFileExtractor.java Sat Sep 13 21:46:29 2014
@@ -25,9 +25,11 @@ package org.apache.lucene.index;
* @param args Usage: org.apache.lucene.index.IndexReader [-extract] <cfsfile>
*/
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.apache.lucene.store.CompoundFileDirectory;
import org.apache.lucene.store.Directory;
@@ -75,13 +77,13 @@ public class CompoundFileExtractor {
IOContext context = IOContext.READ;
try {
- File file = new File(filename);
- String dirname = file.getAbsoluteFile().getParent();
- filename = file.getName();
+ Path file = Paths.get(filename);
+ Path directory = file.toAbsolutePath().getParent();
+ filename = file.getFileName().toString();
if (dirImpl == null) {
- dir = FSDirectory.open(new File(dirname));
+ dir = FSDirectory.open(directory);
} else {
- dir = CommandLineUtil.newFSDirectory(dirImpl, new File(dirname));
+ dir = CommandLineUtil.newFSDirectory(dirImpl, directory);
}
cfr = new CompoundFileDirectory(dir, filename, IOContext.DEFAULT, false);
@@ -96,7 +98,7 @@ public class CompoundFileExtractor {
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]);
+ OutputStream f = Files.newOutputStream(Paths.get(files[i]));
// read and write with a small buffer, which is more effective than reading byte by byte
byte[] buffer = new byte[1024];
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/IndexSplitter.java Sat Sep 13 21:46:29 2014
@@ -16,12 +16,10 @@
*/
package org.apache.lucene.index;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
@@ -53,7 +51,7 @@ public class IndexSplitter {
FSDirectory fsDir;
- File dir;
+ Path dir;
public static void main(String[] args) throws Exception {
if (args.length < 2) {
@@ -64,10 +62,10 @@ public class IndexSplitter {
.println("IndexSplitter <srcDir> -d (delete the following segments)");
return;
}
- File srcDir = new File(args[0]);
+ Path srcDir = Paths.get(args[0]);
IndexSplitter is = new IndexSplitter(srcDir);
- if (!srcDir.exists()) {
- throw new Exception("srcdir:" + srcDir.getAbsolutePath()
+ if (!Files.exists(srcDir)) {
+ throw new Exception("srcdir:" + srcDir.toAbsolutePath()
+ " doesn't exist");
}
if (args[1].equals("-l")) {
@@ -79,7 +77,7 @@ public class IndexSplitter {
}
is.remove(segs.toArray(new String[0]));
} else {
- File targetDir = new File(args[1]);
+ Path targetDir = Paths.get(args[1]);
List<String> segs = new ArrayList<>();
for (int x = 2; x < args.length; x++) {
segs.add(args[x]);
@@ -88,7 +86,7 @@ public class IndexSplitter {
}
}
- public IndexSplitter(File dir) throws IOException {
+ public IndexSplitter(Path dir) throws IOException {
this.dir = dir;
fsDir = FSDirectory.open(dir);
infos = new SegmentInfos();
@@ -129,8 +127,8 @@ public class IndexSplitter {
infos.commit(fsDir);
}
- public void split(File destDir, String[] segs) throws IOException {
- destDir.mkdirs();
+ public void split(Path destDir, String[] segs) throws IOException {
+ Files.createDirectories(destDir);
FSDirectory destFSDir = FSDirectory.open(destDir);
SegmentInfos destInfos = new SegmentInfos();
destInfos.counter = infos.counter;
@@ -146,26 +144,13 @@ public class IndexSplitter {
// now copy files over
Collection<String> files = infoPerCommit.files();
for (final String srcName : files) {
- File srcFile = new File(dir, srcName);
- File destFile = new File(destDir, srcName);
- copyFile(srcFile, destFile);
+ Path srcFile = dir.resolve(srcName);
+ Path destFile = destDir.resolve(srcName);
+ Files.copy(srcFile, destFile);
}
}
destInfos.changed();
destInfos.commit(destFSDir);
// System.out.println("destDir:"+destDir.getAbsolutePath());
}
-
- private static final byte[] copyBuffer = new byte[32*1024];
-
- private static void copyFile(File src, File dst) throws IOException {
- InputStream in = new FileInputStream(src);
- OutputStream out = new FileOutputStream(dst);
- int len;
- while ((len = in.read(copyBuffer)) > 0) {
- out.write(copyBuffer, 0, len);
- }
- in.close();
- out.close();
- }
}
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/index/MultiPassIndexSplitter.java Sat Sep 13 21:46:29 2014
@@ -17,8 +17,10 @@ package org.apache.lucene.index;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@@ -128,12 +130,12 @@ public class MultiPassIndexSplitter {
} else if (args[i].equals("-seq")) {
seq = true;
} else {
- File file = new File(args[i]);
- if (!file.exists() || !file.isDirectory()) {
+ Path file = Paths.get(args[i]);
+ if (!Files.isDirectory(file)) {
System.err.println("Invalid input path - skipping: " + file);
continue;
}
- Directory dir = FSDirectory.open(new File(args[i]));
+ Directory dir = FSDirectory.open(file);
try {
if (!DirectoryReader.indexExists(dir)) {
System.err.println("Invalid input index - skipping: " + file);
@@ -155,13 +157,11 @@ public class MultiPassIndexSplitter {
if (indexes.size() == 0) {
throw new Exception("No input indexes to process");
}
- File out = new File(outDir);
- if (!out.mkdirs()) {
- throw new Exception("Can't create output directory: " + out);
- }
+ Path out = Paths.get(outDir);
+ Files.createDirectories(out);
Directory[] dirs = new Directory[numParts];
for (int i = 0; i < numParts; i++) {
- dirs[i] = FSDirectory.open(new File(out, "part-" + i));
+ dirs[i] = FSDirectory.open(out.resolve("part-" + i));
}
MultiPassIndexSplitter splitter = new MultiPassIndexSplitter();
IndexReader input;
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/GetTermInfo.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/GetTermInfo.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/GetTermInfo.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/GetTermInfo.java Sat Sep 13 21:46:29 2014
@@ -17,7 +17,7 @@ package org.apache.lucene.misc;
* limitations under the License.
*/
-import java.io.File;
+import java.nio.file.Paths;
import java.util.Locale;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
@@ -37,7 +37,7 @@ public class GetTermInfo {
String field = null;
if (args.length == 3) {
- dir = FSDirectory.open(new File(args[0]));
+ dir = FSDirectory.open(Paths.get(args[0]));
field = args[1];
inputStr = args[2];
} else {
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java Sat Sep 13 21:46:29 2014
@@ -28,8 +28,8 @@ import org.apache.lucene.store.FSDirecto
import org.apache.lucene.util.PriorityQueue;
import org.apache.lucene.util.BytesRef;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Paths;
import java.util.Comparator;
import java.util.Locale;
@@ -56,7 +56,7 @@ public class HighFreqTerms {
System.exit(1);
}
- Directory dir = FSDirectory.open(new File(args[0]));
+ Directory dir = FSDirectory.open(Paths.get(args[0]));
Comparator<TermStats> comparator = new DocFreqComparator();
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/IndexMergeTool.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/IndexMergeTool.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/IndexMergeTool.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/misc/IndexMergeTool.java Sat Sep 13 21:46:29 2014
@@ -22,8 +22,8 @@ import org.apache.lucene.index.IndexWrit
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Paths;
/**
* Merges indices specified on the command line into the index
@@ -35,14 +35,14 @@ public class IndexMergeTool {
System.err.println("Usage: IndexMergeTool <mergedIndex> <index1> <index2> [index3] ...");
System.exit(1);
}
- FSDirectory mergedIndex = FSDirectory.open(new File(args[0]));
+ FSDirectory mergedIndex = FSDirectory.open(Paths.get(args[0]));
IndexWriter writer = new IndexWriter(mergedIndex, new IndexWriterConfig(null)
.setOpenMode(OpenMode.CREATE));
Directory[] indexes = new Directory[args.length - 1];
for (int i = 1; i < args.length; i++) {
- indexes[i - 1] = FSDirectory.open(new File(args[i]));
+ indexes[i - 1] = FSDirectory.open(Paths.get(args[i]));
}
System.out.println("Merging...");
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/NativeUnixDirectory.java Sat Sep 13 21:46:29 2014
@@ -18,13 +18,13 @@ package org.apache.lucene.store;
*/
import java.io.EOFException;
-import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.nio.file.Path;
import org.apache.lucene.store.Directory; // javadoc
import org.apache.lucene.store.IOContext.Context;
@@ -99,7 +99,7 @@ public class NativeUnixDirectory extends
* @param delegate fallback Directory for non-merges
* @throws IOException If there is a low-level I/O error
*/
- public NativeUnixDirectory(File path, int mergeBufferSize, long minBytesDirect, Directory delegate) throws IOException {
+ public NativeUnixDirectory(Path path, int mergeBufferSize, long minBytesDirect, Directory delegate) throws IOException {
super(path, delegate.getLockFactory());
if ((mergeBufferSize & ALIGN) != 0) {
throw new IllegalArgumentException("mergeBufferSize must be 0 mod " + ALIGN + " (got: " + mergeBufferSize + ")");
@@ -115,7 +115,7 @@ public class NativeUnixDirectory extends
* @param delegate fallback Directory for non-merges
* @throws IOException If there is a low-level I/O error
*/
- public NativeUnixDirectory(File path, Directory delegate) throws IOException {
+ public NativeUnixDirectory(Path path, Directory delegate) throws IOException {
this(path, DEFAULT_MERGE_BUFFER_SIZE, DEFAULT_MIN_BYTES_DIRECT, delegate);
}
@@ -125,7 +125,7 @@ public class NativeUnixDirectory extends
if (context.context != Context.MERGE || context.mergeInfo.estimatedMergeBytes < minBytesDirect || fileLength(name) < minBytesDirect) {
return delegate.openInput(name, context);
} else {
- return new NativeUnixIndexInput(new File(getDirectory(), name), mergeBufferSize);
+ return new NativeUnixIndexInput(getDirectory().resolve(name), mergeBufferSize);
}
}
@@ -136,7 +136,7 @@ public class NativeUnixDirectory extends
return delegate.createOutput(name, context);
} else {
ensureCanWrite(name);
- return new NativeUnixIndexOutput(new File(getDirectory(), name), mergeBufferSize);
+ return new NativeUnixIndexOutput(getDirectory().resolve(name), mergeBufferSize);
}
}
@@ -153,7 +153,7 @@ public class NativeUnixDirectory extends
private long fileLength;
private boolean isOpen;
- public NativeUnixIndexOutput(File path, int bufferSize) throws IOException {
+ public NativeUnixIndexOutput(Path path, int bufferSize) throws IOException {
//this.path = path;
final FileDescriptor fd = NativePosixUtil.open_direct(path.toString(), false);
fos = new FileOutputStream(fd);
@@ -271,8 +271,8 @@ public class NativeUnixDirectory extends
private long filePos;
private int bufferPos;
- public NativeUnixIndexInput(File path, int bufferSize) throws IOException {
- super("NativeUnixIndexInput(path=\"" + path.getPath() + "\")");
+ public NativeUnixIndexInput(Path path, int bufferSize) throws IOException {
+ super("NativeUnixIndexInput(path=\"" + path + "\")");
final FileDescriptor fd = NativePosixUtil.open_direct(path.toString(), true);
fis = new FileInputStream(fd);
channel = fis.getChannel();
Modified: lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/WindowsDirectory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/WindowsDirectory.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/WindowsDirectory.java (original)
+++ lucene/dev/trunk/lucene/misc/src/java/org/apache/lucene/store/WindowsDirectory.java Sat Sep 13 21:46:29 2014
@@ -17,9 +17,9 @@ package org.apache.lucene.store;
* the License.
*/
-import java.io.File;
import java.io.IOException;
import java.io.EOFException;
+import java.nio.file.Path;
import org.apache.lucene.store.Directory; // javadoc
import org.apache.lucene.store.NativeFSLockFactory; // javadoc
@@ -56,7 +56,7 @@ public class WindowsDirectory extends FS
* ({@link NativeFSLockFactory});
* @throws IOException If there is a low-level I/O error
*/
- public WindowsDirectory(File path, LockFactory lockFactory) throws IOException {
+ public WindowsDirectory(Path path, LockFactory lockFactory) throws IOException {
super(path, lockFactory);
}
@@ -65,14 +65,14 @@ public class WindowsDirectory extends FS
* @param path the path of the directory
* @throws IOException If there is a low-level I/O error
*/
- public WindowsDirectory(File path) throws IOException {
+ public WindowsDirectory(Path path) throws IOException {
super(path, null);
}
@Override
public IndexInput openInput(String name, IOContext context) throws IOException {
ensureOpen();
- return new WindowsIndexInput(new File(getDirectory(), name), Math.max(BufferedIndexInput.bufferSize(context), DEFAULT_BUFFERSIZE));
+ return new WindowsIndexInput(getDirectory().resolve(name), Math.max(BufferedIndexInput.bufferSize(context), DEFAULT_BUFFERSIZE));
}
static class WindowsIndexInput extends BufferedIndexInput {
@@ -81,9 +81,9 @@ public class WindowsDirectory extends FS
boolean isClone;
boolean isOpen;
- public WindowsIndexInput(File file, int bufferSize) throws IOException {
- super("WindowsIndexInput(path=\"" + file.getPath() + "\")", bufferSize);
- fd = WindowsDirectory.open(file.getPath());
+ public WindowsIndexInput(Path file, int bufferSize) throws IOException {
+ super("WindowsIndexInput(path=\"" + file + "\")", bufferSize);
+ fd = WindowsDirectory.open(file.toString());
length = WindowsDirectory.length(fd);
isOpen = true;
}
Modified: lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java (original)
+++ lucene/dev/trunk/lucene/misc/src/test/org/apache/lucene/index/TestIndexSplitter.java Sat Sep 13 21:46:29 2014
@@ -16,7 +16,7 @@
*/
package org.apache.lucene.index;
-import java.io.File;
+import java.nio.file.Path;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
@@ -27,8 +27,8 @@ import org.apache.lucene.util.LuceneTest
public class TestIndexSplitter extends LuceneTestCase {
public void test() throws Exception {
- File dir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
- File destDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ Path dir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ Path destDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
Directory fsDir = newFSDirectory(dir);
// IndexSplitter.split makes its own commit directly with SIPC/SegmentInfos,
// so the unreferenced files are expected.
@@ -75,17 +75,17 @@ public class TestIndexSplitter extends L
fsDirDest.close();
// now test cmdline
- File destDir2 = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
- IndexSplitter.main(new String[] {dir.getAbsolutePath(), destDir2.getAbsolutePath(), splitSegName});
- assertEquals(4, destDir2.listFiles().length);
+ Path destDir2 = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ IndexSplitter.main(new String[] {dir.toAbsolutePath().toString(), destDir2.toAbsolutePath().toString(), splitSegName});
Directory fsDirDest2 = newFSDirectory(destDir2);
+ assertEquals(4, fsDirDest2.listAll().length);
r = DirectoryReader.open(fsDirDest2);
assertEquals(50, r.maxDoc());
r.close();
fsDirDest2.close();
// now remove the copied segment from src
- IndexSplitter.main(new String[] {dir.getAbsolutePath(), "-d", splitSegName});
+ IndexSplitter.main(new String[] {dir.toAbsolutePath().toString(), "-d", splitSegName});
r = DirectoryReader.open(fsDir);
assertEquals(2, r.leaves().size());
r.close();
Modified: lucene/dev/trunk/lucene/replicator/src/java/org/apache/lucene/replicator/PerSessionDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/replicator/src/java/org/apache/lucene/replicator/PerSessionDirectoryFactory.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/replicator/src/java/org/apache/lucene/replicator/PerSessionDirectoryFactory.java (original)
+++ lucene/dev/trunk/lucene/replicator/src/java/org/apache/lucene/replicator/PerSessionDirectoryFactory.java Sat Sep 13 21:46:29 2014
@@ -17,8 +17,9 @@ package org.apache.lucene.replicator;
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.lucene.replicator.ReplicationClient.SourceDirectoryFactory;
import org.apache.lucene.store.Directory;
@@ -34,23 +35,19 @@ import org.apache.lucene.util.IOUtils;
*/
public class PerSessionDirectoryFactory implements SourceDirectoryFactory {
- private final File workDir;
+ private final Path workDir;
/** Constructor with the given sources mapping. */
- public PerSessionDirectoryFactory(File workDir) {
+ public PerSessionDirectoryFactory(Path workDir) {
this.workDir = workDir;
}
@Override
public Directory getDirectory(String sessionID, String source) throws IOException {
- File sessionDir = new File(workDir, sessionID);
- if (!sessionDir.exists() && !sessionDir.mkdirs()) {
- throw new IOException("failed to create session directory " + sessionDir);
- }
- File sourceDir = new File(sessionDir, source);
- if (!sourceDir.mkdirs()) {
- throw new IOException("failed to create source directory " + sourceDir);
- }
+ Path sessionDir = workDir.resolve(sessionID);
+ Files.createDirectories(sessionDir);
+ Path sourceDir = sessionDir.resolve(source);
+ Files.createDirectories(sourceDir);
return FSDirectory.open(sourceDir);
}
@@ -59,7 +56,7 @@ public class PerSessionDirectoryFactory
if (sessionID.isEmpty()) { // protect against deleting workDir entirely!
throw new IllegalArgumentException("sessionID cannot be empty");
}
- IOUtils.rm(new File(workDir, sessionID));
+ IOUtils.rm(workDir.resolve(sessionID));
}
}
Modified: lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java (original)
+++ lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/IndexAndTaxonomyReplicationClientTest.java Sat Sep 13 21:46:29 2014
@@ -19,9 +19,9 @@ package org.apache.lucene.replicator;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -138,7 +138,7 @@ public class IndexAndTaxonomyReplication
private SnapshotDirectoryTaxonomyWriter publishTaxoWriter;
private FacetsConfig config;
private IndexAndTaxonomyReadyCallback callback;
- private File clientWorkDir;
+ private Path clientWorkDir;
private static final String VERSION_ID = "version";
Modified: lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java (original)
+++ lucene/dev/trunk/lucene/replicator/src/test/org/apache/lucene/replicator/http/HttpReplicatorTest.java Sat Sep 13 21:46:29 2014
@@ -17,8 +17,8 @@ package org.apache.lucene.replicator.htt
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Collections;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
@@ -52,7 +52,7 @@ public class HttpReplicatorTest extends
public TestRule testRules =
RuleChain.outerRule(new SystemPropertiesRestoreRule());
- private File clientWorkDir;
+ private Path clientWorkDir;
private Replicator serverReplicator;
private IndexWriter writer;
private DirectoryReader reader;
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/spell/PlainTextDictionary.java Sat Sep 13 21:46:29 2014
@@ -18,11 +18,12 @@ package org.apache.lucene.search.spell;
*/
import java.io.BufferedReader;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.lucene.search.suggest.InputIterator;
import org.apache.lucene.util.BytesRef;
@@ -44,12 +45,12 @@ public class PlainTextDictionary impleme
private BufferedReader in;
/**
- * Creates a dictionary based on a File.
+ * Creates a dictionary based on a Path.
* <p>
* NOTE: content is treated as UTF-8
*/
- public PlainTextDictionary(File file) throws IOException {
- in = new BufferedReader(IOUtils.getDecodingReader(file, StandardCharsets.UTF_8));
+ public PlainTextDictionary(Path path) throws IOException {
+ in = Files.newBufferedReader(path, StandardCharsets.UTF_8);
}
/**
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedInputIterator.java Sat Sep 13 21:46:29 2014
@@ -17,8 +17,9 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
@@ -40,8 +41,8 @@ import org.apache.lucene.util.OfflineSor
public class SortedInputIterator implements InputIterator {
private final InputIterator source;
- private File tempInput;
- private File tempSorted;
+ private Path tempInput;
+ private Path tempSorted;
private final ByteSequencesReader reader;
private final Comparator<BytesRef> comparator;
private final boolean hasPayloads;
@@ -168,9 +169,9 @@ public class SortedInputIterator impleme
private ByteSequencesReader sort() throws IOException {
String prefix = getClass().getSimpleName();
- File directory = OfflineSorter.defaultTempDir();
- tempInput = File.createTempFile(prefix, ".input", directory);
- tempSorted = File.createTempFile(prefix, ".sorted", directory);
+ Path directory = OfflineSorter.defaultTempDir();
+ tempInput = Files.createTempFile(directory, prefix, ".input");
+ tempSorted = Files.createTempFile(directory, prefix, ".sorted");
final OfflineSorter.ByteSequencesWriter writer = new OfflineSorter.ByteSequencesWriter(tempInput);
boolean success = false;
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggester.java Sat Sep 13 21:46:29 2014
@@ -18,9 +18,9 @@ package org.apache.lucene.search.suggest
*/
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -222,7 +222,7 @@ public class AnalyzingInfixSuggester ext
/** Subclass can override to choose a specific {@link
* Directory} implementation. */
- protected Directory getDirectory(File path) throws IOException {
+ protected Directory getDirectory(Path path) throws IOException {
return FSDirectory.open(path);
}
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggester.java Sat Sep 13 21:46:29 2014
@@ -17,9 +17,9 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -416,9 +416,9 @@ public class AnalyzingSuggester extends
throw new IllegalArgumentException("this suggester doesn't support contexts");
}
String prefix = getClass().getSimpleName();
- File directory = OfflineSorter.defaultTempDir();
- File tempInput = File.createTempFile(prefix, ".input", directory);
- File tempSorted = File.createTempFile(prefix, ".sorted", directory);
+ Path directory = OfflineSorter.defaultTempDir();
+ Path tempInput = Files.createTempFile(directory, prefix, ".input");
+ Path tempSorted = Files.createTempFile(directory, prefix, ".sorted");
hasPayloads = iterator.hasPayloads();
@@ -501,7 +501,7 @@ public class AnalyzingSuggester extends
new OfflineSorter(new AnalyzingComparator(hasPayloads)).sort(tempInput, tempSorted);
// Free disk space:
- Files.delete(tempInput.toPath());
+ Files.delete(tempInput);
reader = new OfflineSorter.ByteSequencesReader(tempSorted);
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java Sat Sep 13 21:46:29 2014
@@ -68,6 +68,7 @@ import org.apache.lucene.util.fst.Util.T
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -292,7 +293,7 @@ public class FreeTextSuggester extends L
}
String prefix = getClass().getSimpleName();
- File tempIndexPath = Files.createTempDirectory(prefix + ".index.").toFile();
+ Path tempIndexPath = Files.createTempDirectory(prefix + ".index.");
Directory dir = FSDirectory.open(tempIndexPath);
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/ExternalRefSorter.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/ExternalRefSorter.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/ExternalRefSorter.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/ExternalRefSorter.java Sat Sep 13 21:46:29 2014
@@ -18,9 +18,9 @@ package org.apache.lucene.search.suggest
*/
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Comparator;
import org.apache.lucene.util.BytesRef;
@@ -36,16 +36,15 @@ import org.apache.lucene.util.OfflineSor
public class ExternalRefSorter implements BytesRefSorter, Closeable {
private final OfflineSorter sort;
private OfflineSorter.ByteSequencesWriter writer;
- private File input;
- private File sorted;
+ private Path input;
+ private Path sorted;
/**
* Will buffer all sequences to a temporary file and then sort (all on-disk).
*/
public ExternalRefSorter(OfflineSorter sort) throws IOException {
this.sort = sort;
- this.input = File.createTempFile("RefSorter-", ".raw",
- OfflineSorter.defaultTempDir());
+ this.input = Files.createTempFile(OfflineSorter.defaultTempDir(), "RefSorter-", ".raw");
this.writer = new OfflineSorter.ByteSequencesWriter(input);
}
@@ -60,15 +59,14 @@ public class ExternalRefSorter implement
if (sorted == null) {
closeWriter();
- sorted = File.createTempFile("RefSorter-", ".sorted",
- OfflineSorter.defaultTempDir());
+ sorted = Files.createTempFile(OfflineSorter.defaultTempDir(), "RefSorter-", ".sorted");
boolean success = false;
try {
sort.sort(input, sorted);
success = true;
} finally {
if (success) {
- Files.delete(input.toPath());
+ Files.delete(input);
} else {
IOUtils.deleteFilesIgnoringExceptions(input);
}
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java Sat Sep 13 21:46:29 2014
@@ -17,9 +17,9 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -158,10 +158,10 @@ public class FSTCompletionLookup extends
if (iterator.hasContexts()) {
throw new IllegalArgumentException("this suggester doesn't support contexts");
}
- File tempInput = File.createTempFile(
- FSTCompletionLookup.class.getSimpleName(), ".input", OfflineSorter.defaultTempDir());
- File tempSorted = File.createTempFile(
- FSTCompletionLookup.class.getSimpleName(), ".sorted", OfflineSorter.defaultTempDir());
+ Path tempInput = Files.createTempFile(
+ OfflineSorter.defaultTempDir(), FSTCompletionLookup.class.getSimpleName(), ".input");
+ Path tempSorted = Files.createTempFile(
+ OfflineSorter.defaultTempDir(), FSTCompletionLookup.class.getSimpleName(), ".sorted");
OfflineSorter.ByteSequencesWriter writer = new OfflineSorter.ByteSequencesWriter(tempInput);
OfflineSorter.ByteSequencesReader reader = null;
@@ -190,7 +190,7 @@ public class FSTCompletionLookup extends
// We don't know the distribution of scores and we need to bucket them, so we'll sort
// and divide into equal buckets.
SortInfo info = new OfflineSorter().sort(tempInput, tempSorted);
- Files.delete(tempInput.toPath());
+ Files.delete(tempInput);
FSTCompletionBuilder builder = new FSTCompletionBuilder(
buckets, sorter = new ExternalRefSorter(new OfflineSorter()), sharedTailLength);
@@ -235,7 +235,7 @@ public class FSTCompletionLookup extends
IOUtils.closeWhileHandlingException(reader, writer, sorter);
if (success) {
- Files.delete(tempSorted.toPath());
+ Files.delete(tempSorted);
} else {
IOUtils.deleteFilesIgnoringExceptions(tempInput, tempSorted);
}
Modified: lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/jaspell/JaspellTernarySearchTrie.java Sat Sep 13 21:46:29 2014
@@ -30,10 +30,10 @@ package org.apache.lucene.search.suggest
*/
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
@@ -198,16 +198,16 @@ public class JaspellTernarySearchTrie im
}
/**
- * Constructs a Ternary Search Trie and loads data from a <code>File</code>
+ * Constructs a Ternary Search Trie and loads data from a <code>Path</code>
* into the Trie. The file is a normal text document, where each line is of
* the form word TAB float.
*
*@param file
- * The <code>File</code> with the data to load into the Trie.
+ * The <code>Path</code> with the data to load into the Trie.
*@exception IOException
* A problem occured while reading the data.
*/
- public JaspellTernarySearchTrie(File file) throws IOException {
+ public JaspellTernarySearchTrie(Path file) throws IOException {
this(file, false);
}
@@ -224,15 +224,14 @@ public class JaspellTernarySearchTrie im
*@exception IOException
* A problem occured while reading the data.
*/
- public JaspellTernarySearchTrie(File file, boolean compression)
+ public JaspellTernarySearchTrie(Path file, boolean compression)
throws IOException {
this();
BufferedReader in;
if (compression)
in = new BufferedReader(IOUtils.getDecodingReader(new GZIPInputStream(
- new FileInputStream(file)), StandardCharsets.UTF_8));
- else in = new BufferedReader(IOUtils.getDecodingReader((new FileInputStream(
- file)), StandardCharsets.UTF_8));
+ Files.newInputStream(file)), StandardCharsets.UTF_8));
+ else in = Files.newBufferedReader(file, StandardCharsets.UTF_8);
String word;
int pos;
Float occur, one = new Float(1);
Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/PersistenceTest.java Sat Sep 13 21:46:29 2014
@@ -16,10 +16,9 @@
*/
package org.apache.lucene.search.suggest;
-import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Random;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.util.List;
import org.apache.lucene.search.suggest.Lookup.LookupResult;
@@ -70,12 +69,12 @@ public class PersistenceTest extends Luc
lookup.build(new InputArrayIterator(keys));
// Store the suggester.
- File storeDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
- lookup.store(new FileOutputStream(new File(storeDir, "lookup.dat")));
+ Path storeDir = createTempDir(LuceneTestCase.getTestClass().getSimpleName());
+ lookup.store(Files.newOutputStream(storeDir.resolve("lookup.dat")));
// Re-read it from disk.
lookup = lookupClass.newInstance();
- lookup.load(new FileInputStream(new File(storeDir, "lookup.dat")));
+ lookup.load(Files.newInputStream(storeDir.resolve("lookup.dat")));
// Assert validity.
Random random = random();
Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingInfixSuggesterTest.java Sat Sep 13 21:46:29 2014
@@ -17,9 +17,9 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -91,7 +91,7 @@ public class AnalyzingInfixSuggesterTest
new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz")),
};
- File tempDir = createTempDir("AnalyzingInfixSuggesterTest");
+ Path tempDir = createTempDir("AnalyzingInfixSuggesterTest");
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(newFSDirectory(tempDir), a, a, 3, false);
@@ -210,7 +210,7 @@ public class AnalyzingInfixSuggesterTest
new Input("lend me your ear", 8, new BytesRef("foobar")),
new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz")),
};
- File tempDir = createTempDir("AnalyzingInfixSuggesterTest");
+ Path tempDir = createTempDir("AnalyzingInfixSuggesterTest");
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
int minPrefixLength = random().nextInt(10);
@@ -471,7 +471,7 @@ public class AnalyzingInfixSuggesterTest
}
public void testRandomNRT() throws Exception {
- final File tempDir = createTempDir("AnalyzingInfixSuggesterTest");
+ final Path tempDir = createTempDir("AnalyzingInfixSuggesterTest");
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
int minPrefixChars = random().nextInt(7);
if (VERBOSE) {
@@ -793,7 +793,7 @@ public class AnalyzingInfixSuggesterTest
public void testNRTWithParallelAdds() throws IOException, InterruptedException {
String[] keys = new String[] {"python", "java", "c", "scala", "ruby", "clojure", "erlang", "go", "swift", "lisp"};
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
- File tempDir = createTempDir("AIS_NRT_PERSIST_TEST");
+ Path tempDir = createTempDir("AIS_NRT_PERSIST_TEST");
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(newFSDirectory(tempDir), a, a, 3, false);
Thread[] multiAddThreads = new Thread[10];
try {
@@ -865,7 +865,7 @@ public class AnalyzingInfixSuggesterTest
new Input("a penny saved is a penny earned", 10, new BytesRef("foobaz"), asSet("foo", "baz"))
};
- File tempDir = createTempDir("analyzingInfixContext");
+ Path tempDir = createTempDir("analyzingInfixContext");
for(int iter=0;iter<2;iter++) {
AnalyzingInfixSuggester suggester;
Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/AnalyzingSuggesterTest.java Sat Sep 13 21:46:29 2014
@@ -17,13 +17,12 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -921,16 +920,15 @@ public class AnalyzingSuggesterTest exte
assertEquals(3, results.get(2).value);
// Try again after save/load:
- File tmpDir = createTempDir("AnalyzingSuggesterTest");
- tmpDir.mkdir();
+ Path tmpDir = createTempDir("AnalyzingSuggesterTest");
- File path = new File(tmpDir, "suggester");
+ Path path = tmpDir.resolve("suggester");
- OutputStream os = new FileOutputStream(path);
+ OutputStream os = Files.newOutputStream(path);
suggester.store(os);
os.close();
- InputStream is = new FileInputStream(path);
+ InputStream is = Files.newInputStream(path);
suggester.load(is);
is.close();
@@ -983,16 +981,15 @@ public class AnalyzingSuggesterTest exte
assertEquals(5, results.get(1).value);
// Try again after save/load:
- File tmpDir = createTempDir("AnalyzingSuggesterTest");
- tmpDir.mkdir();
+ Path tmpDir = createTempDir("AnalyzingSuggesterTest");
- File path = new File(tmpDir, "suggester");
+ Path path = tmpDir.resolve("suggester");
- OutputStream os = new FileOutputStream(path);
+ OutputStream os = Files.newOutputStream(path);
suggester.store(os);
os.close();
- InputStream is = new FileInputStream(path);
+ InputStream is = Files.newInputStream(path);
suggester.load(is);
is.close();
@@ -1053,16 +1050,15 @@ public class AnalyzingSuggesterTest exte
assertEquals(5, results.get(1).value);
// Try again after save/load:
- File tmpDir = createTempDir("AnalyzingSuggesterTest");
- tmpDir.mkdir();
+ Path tmpDir = createTempDir("AnalyzingSuggesterTest");
- File path = new File(tmpDir, "suggester");
+ Path path = tmpDir.resolve("suggester");
- OutputStream os = new FileOutputStream(path);
+ OutputStream os = Files.newOutputStream(path);
suggester.store(os);
os.close();
- InputStream is = new FileInputStream(path);
+ InputStream is = Files.newInputStream(path);
suggester.load(is);
is.close();
Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/BlendedInfixSuggesterTest.java Sat Sep 13 21:46:29 2014
@@ -17,8 +17,8 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.List;
import org.apache.lucene.analysis.Analyzer;
@@ -44,7 +44,7 @@ public class BlendedInfixSuggesterTest e
new Input("star wars: episode v - the empire strikes back", 8, payload)
};
- File tempDir = createTempDir("BlendedInfixSuggesterTest");
+ Path tempDir = createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);
BlendedInfixSuggester suggester = new BlendedInfixSuggester(newFSDirectory(tempDir), a, a,
@@ -83,7 +83,7 @@ public class BlendedInfixSuggesterTest e
new Input("top of the lake", w, pl)
};
- File tempDir = createTempDir("BlendedInfixSuggesterTest");
+ Path tempDir = createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);
// BlenderType.LINEAR is used by default (remove position*10%)
@@ -125,7 +125,7 @@ public class BlendedInfixSuggesterTest e
new Input("the returned", 10, ret),
};
- File tempDir = createTempDir("BlendedInfixSuggesterTest");
+ Path tempDir = createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);
// if factor is small, we don't get the expected element
@@ -177,7 +177,7 @@ public class BlendedInfixSuggesterTest e
new Input("the returned", 10, ret),
};
- File tempDir = createTempDir("BlendedInfixSuggesterTest");
+ Path tempDir = createTempDir("BlendedInfixSuggesterTest");
Analyzer a = new StandardAnalyzer(CharArraySet.EMPTY_SET);
// if factor is small, we don't get the expected element
Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestFreeTextSuggester.java Sat Sep 13 21:46:29 2014
@@ -17,12 +17,11 @@ package org.apache.lucene.search.suggest
* limitations under the License.
*/
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@@ -82,16 +81,15 @@ public class TestFreeTextSuggester exten
toString(sug.lookup("b", 10)));
// Try again after save/load:
- File tmpDir = createTempDir("FreeTextSuggesterTest");
- tmpDir.mkdir();
+ Path tmpDir = createTempDir("FreeTextSuggesterTest");
- File path = new File(tmpDir, "suggester");
+ Path path = tmpDir.resolve("suggester");
- OutputStream os = new FileOutputStream(path);
+ OutputStream os = Files.newOutputStream(path);
sug.store(os);
os.close();
- InputStream is = new FileInputStream(path);
+ InputStream is = Files.newInputStream(path);
sug = new FreeTextSuggester(a, a, 2, (byte) 0x20);
sug.load(is);
is.close();
Modified: lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java (original)
+++ lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/fst/LargeInputFST.java Sat Sep 13 21:46:29 2014
@@ -19,13 +19,12 @@ package org.apache.lucene.search.suggest
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.OfflineSorter;
@@ -35,7 +34,7 @@ import org.apache.lucene.util.OfflineSor
*/
public class LargeInputFST {
public static void main(String[] args) throws IOException {
- File input = new File("/home/dweiss/tmp/shuffled.dict");
+ Path input = Paths.get("/home/dweiss/tmp/shuffled.dict");
int buckets = 20;
int shareMaxTail = 10;
@@ -43,9 +42,7 @@ public class LargeInputFST {
ExternalRefSorter sorter = new ExternalRefSorter(new OfflineSorter());
FSTCompletionBuilder builder = new FSTCompletionBuilder(buckets, sorter, shareMaxTail);
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(
- new FileInputStream(input), StandardCharsets.UTF_8));
+ BufferedReader reader = Files.newBufferedReader(input, StandardCharsets.UTF_8);
BytesRefBuilder scratch = new BytesRefBuilder();
String line;
@@ -61,8 +58,8 @@ public class LargeInputFST {
System.out.println("Building FSTCompletion.");
FSTCompletion completion = builder.build();
- File fstFile = new File("completion.fst");
- System.out.println("Done. Writing automaton: " + fstFile.getAbsolutePath());
+ Path fstFile = Paths.get("completion.fst");
+ System.out.println("Done. Writing automaton: " + fstFile.toAbsolutePath());
completion.getFST().save(fstFile);
sorter.close();
}
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java Sat Sep 13 21:46:29 2014
@@ -17,16 +17,15 @@ package org.apache.lucene.analysis;
* limitations under the License.
*/
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
-import java.lang.reflect.Constructor;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CountDownLatch;
@@ -896,7 +895,7 @@ public abstract class BaseTokenStreamTes
}
protected void toDotFile(Analyzer a, String inputText, String localFileName) throws IOException {
- Writer w = new OutputStreamWriter(new FileOutputStream(localFileName), StandardCharsets.UTF_8);
+ Writer w = Files.newBufferedWriter(Paths.get(localFileName), StandardCharsets.UTF_8);
final TokenStream ts = a.tokenStream("field", inputText);
ts.reset();
new TokenStreamToDot(inputText, ts, new PrintWriter(w)).toDot();
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/VocabularyAssert.java Sat Sep 13 21:46:29 2014
@@ -18,11 +18,11 @@ package org.apache.lucene.analysis;
*/
import java.io.BufferedReader;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
import java.util.zip.ZipFile;
import org.apache.lucene.analysis.Analyzer;
@@ -61,9 +61,8 @@ public class VocabularyAssert {
}
/** Run a vocabulary test against two data files inside a zip file */
- public static void assertVocabulary(Analyzer a, File zipFile, String voc, String out)
- throws IOException {
- ZipFile zip = new ZipFile(zipFile);
+ public static void assertVocabulary(Analyzer a, Path zipFile, String voc, String out) throws IOException {
+ ZipFile zip = new ZipFile(zipFile.toFile());
InputStream v = zip.getInputStream(zip.getEntry(voc));
InputStream o = zip.getInputStream(zip.getEntry(out));
assertVocabulary(a, v, o);
@@ -73,9 +72,8 @@ public class VocabularyAssert {
}
/** Run a vocabulary test against a tab-separated data file inside a zip file */
- public static void assertVocabulary(Analyzer a, File zipFile, String vocOut)
- throws IOException {
- ZipFile zip = new ZipFile(zipFile);
+ public static void assertVocabulary(Analyzer a, Path zipFile, String vocOut) throws IOException {
+ ZipFile zip = new ZipFile(zipFile.toFile());
InputStream vo = zip.getInputStream(zip.getEntry(vocOut));
assertVocabulary(a, vo);
vo.close();
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/BasePostingsFormatTestCase.java Sat Sep 13 21:46:29 2014
@@ -19,6 +19,7 @@ package org.apache.lucene.index;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -1335,7 +1336,7 @@ public abstract class BasePostingsFormat
/** Indexes all fields/terms at the specified
* IndexOptions, and fully tests at that IndexOptions. */
private void testFull(IndexOptions options, boolean withPayloads) throws Exception {
- File path = createTempDir("testPostingsFormat.testExact");
+ Path path = createTempDir("testPostingsFormat.testExact");
Directory dir = newFSDirectory(path);
// TODO test thread safety of buildIndex too
@@ -1388,7 +1389,7 @@ public abstract class BasePostingsFormat
int iters = 5;
for(int iter=0;iter<iters;iter++) {
- File path = createTempDir("testPostingsFormat");
+ Path path = createTempDir("testPostingsFormat");
Directory dir = newFSDirectory(path);
boolean indexPayloads = random().nextBoolean();
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java Sat Sep 13 21:46:29 2014
@@ -19,6 +19,7 @@ package org.apache.lucene.index;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -436,7 +437,7 @@ public abstract class ThreadedIndexingAn
Random random = new Random(random().nextLong());
final LineFileDocs docs = new LineFileDocs(random, true);
- final File tempDir = createTempDir(testName);
+ final Path tempDir = createTempDir(testName);
dir = getDirectory(newMockFSDirectory(tempDir)); // some subclasses rely on this being MDW
if (dir instanceof BaseDirectoryWrapper) {
((BaseDirectoryWrapper) dir).setCheckIndexOnClose(false); // don't double-checkIndex, we do it ourselves.
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java Sat Sep 13 21:46:29 2014
@@ -23,6 +23,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -42,7 +43,7 @@ public abstract class BaseDirectoryTestC
/** Subclass returns the Directory to be tested; if it's
* an FS-based directory it should point to the specified
* path, else it can ignore it. */
- protected abstract Directory getDirectory(File path) throws IOException;
+ protected abstract Directory getDirectory(Path path) throws IOException;
// first some basic tests for the directory api
@@ -473,17 +474,6 @@ public abstract class BaseDirectoryTestC
dir.close();
}
- /** LUCENE-1464: just creating a Directory should not
- * mkdir the underling directory in the filesystem. */
- public void testDontCreate() throws Throwable {
- File path = createTempDir("doesnotexist");
- IOUtils.rm(path);
- assertTrue(!path.exists());
- Directory dir = getDirectory(path);
- assertTrue(!path.exists());
- dir.close();
- }
-
/** LUCENE-1468: once we create an output, we should see
* it in the dir listing and be able to open it with
* openInput. */
@@ -582,13 +572,13 @@ public abstract class BaseDirectoryTestC
// LUCENE-3382 -- make sure we get exception if the directory really does not exist.
public void testNoDir() throws Throwable {
- File tempDir = createTempDir("doesnotexist");
+ Path tempDir = createTempDir("doesnotexist");
IOUtils.rm(tempDir);
Directory dir = getDirectory(tempDir);
try {
DirectoryReader.open(dir);
fail("did not hit expected exception");
- } catch (NoSuchDirectoryException | IndexNotFoundException nsde) {
+ } catch (NoSuchFileException | IndexNotFoundException nsde) {
// expected
}
dir.close();
@@ -774,7 +764,7 @@ public abstract class BaseDirectoryTestC
// this test backdoors the directory via the filesystem. so it must actually use the filesystem
// TODO: somehow change this test to
public void testFsyncDoesntCreateNewFiles() throws Exception {
- File path = createTempDir("nocreate");
+ Path path = createTempDir("nocreate");
Directory fsdir = getDirectory(path);
// this test backdoors the directory via the filesystem. so it must be an FSDir (for now)
@@ -791,7 +781,7 @@ public abstract class BaseDirectoryTestC
out.close();
// delete it
- Files.delete(new File(path, "afile").toPath());
+ Files.delete(path.resolve("afile"));
// directory is empty
assertEquals(0, fsdir.listAll().length);
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LineFileDocs.java Sat Sep 13 21:46:29 2014
@@ -19,17 +19,17 @@ package org.apache.lucene.util;
import java.io.BufferedReader;
import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.RandomAccessFile;
import java.nio.channels.Channels;
-import java.nio.channels.FileChannel;
+import java.nio.channels.SeekableByteChannel;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPInputStream;
@@ -89,15 +89,15 @@ public class LineFileDocs implements Clo
long size = 0L, seekTo = 0L;
if (is == null) {
// if its not in classpath, we load it as absolute filesystem path (e.g. Hudson's home dir)
- File file = new File(path);
- size = file.length();
+ Path file = Paths.get(path);
+ size = Files.size(file);
if (path.endsWith(".gz")) {
// if it is a gzip file, we need to use InputStream and slowly skipTo:
- is = new FileInputStream(file);
+ is = Files.newInputStream(file);
} else {
- // optimized seek using RandomAccessFile:
+ // optimized seek using SeekableByteChannel
seekTo = randomSeekPos(random, size);
- final FileChannel channel = new RandomAccessFile(path, "r").getChannel();
+ final SeekableByteChannel channel = Files.newByteChannel(file);
if (LuceneTestCase.VERBOSE) {
System.out.println("TEST: LineFileDocs: file seek to fp=" + seekTo + " on open");
}
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java Sat Sep 13 21:46:29 2014
@@ -18,7 +18,6 @@ package org.apache.lucene.util;
*/
import java.io.Closeable;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
@@ -32,6 +31,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.NoSuchFileException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -1170,7 +1171,7 @@ public abstract class LuceneTestCase ext
return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY), false);
}
- public static MockDirectoryWrapper newMockFSDirectory(File f) {
+ public static MockDirectoryWrapper newMockFSDirectory(Path f) {
return (MockDirectoryWrapper) newFSDirectory(f, null, false);
}
@@ -1184,16 +1185,16 @@ public abstract class LuceneTestCase ext
}
/** Returns a new FSDirectory instance over the given file, which must be a folder. */
- public static BaseDirectoryWrapper newFSDirectory(File f) {
+ public static BaseDirectoryWrapper newFSDirectory(Path f) {
return newFSDirectory(f, null);
}
/** Returns a new FSDirectory instance over the given file, which must be a folder. */
- public static BaseDirectoryWrapper newFSDirectory(File f, LockFactory lf) {
+ public static BaseDirectoryWrapper newFSDirectory(Path f, LockFactory lf) {
return newFSDirectory(f, lf, rarely());
}
- private static BaseDirectoryWrapper newFSDirectory(File f, LockFactory lf, boolean bare) {
+ private static BaseDirectoryWrapper newFSDirectory(Path f, LockFactory lf, boolean bare) {
String fsdirClass = TEST_DIRECTORY;
if (fsdirClass.equals("random")) {
fsdirClass = RandomPicks.randomFrom(random(), FS_DIRECTORIES);
@@ -1408,12 +1409,10 @@ public abstract class LuceneTestCase ext
}
}
- private static Directory newFSDirectoryImpl(
- Class<? extends FSDirectory> clazz, File file)
- throws IOException {
+ private static Directory newFSDirectoryImpl(Class<? extends FSDirectory> clazz, Path path) throws IOException {
FSDirectory d = null;
try {
- d = CommandLineUtil.newFSDirectory(clazz, file);
+ d = CommandLineUtil.newFSDirectory(clazz, path);
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
Rethrow.rethrow(e);
}
@@ -1431,24 +1430,24 @@ public abstract class LuceneTestCase ext
try {
final Class<? extends Directory> clazz = CommandLineUtil.loadDirectoryClass(clazzName);
- // If it is a FSDirectory type, try its ctor(File)
+ // If it is a FSDirectory type, try its ctor(Path)
if (FSDirectory.class.isAssignableFrom(clazz)) {
- final File dir = createTempDir("index-" + clazzName);
+ final Path dir = createTempDir("index-" + clazzName);
return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir);
}
- // See if it has a File ctor even though it's not an
+ // See if it has a Path ctor even though it's not an
// FSDir subclass:
- Constructor<? extends Directory> fileCtor = null;
+ Constructor<? extends Directory> pathCtor = null;
try {
- fileCtor = clazz.getConstructor(File.class);
+ pathCtor = clazz.getConstructor(Path.class);
} catch (NoSuchMethodException nsme) {
// Ignore
}
- if (fileCtor != null) {
- final File dir = createTempDir("index");
- return fileCtor.newInstance(dir);
+ if (pathCtor != null) {
+ final Path dir = createTempDir("index");
+ return pathCtor.newInstance(dir);
}
// try empty ctor
@@ -1662,13 +1661,13 @@ public abstract class LuceneTestCase ext
}
/**
- * Gets a resource from the classpath as {@link File}. This method should only
+ * Gets a resource from the classpath as {@link Path}. This method should only
* be used, if a real file is needed. To get a stream, code should prefer
* {@link Class#getResourceAsStream} using {@code this.getClass()}.
*/
- protected File getDataFile(String name) throws IOException {
+ protected Path getDataPath(String name) throws IOException {
try {
- return new File(this.getClass().getResource(name).toURI());
+ return Paths.get(this.getClass().getResource(name).toURI());
} catch (Exception e) {
throw new IOException("Cannot find resource: " + name);
}
@@ -2364,7 +2363,7 @@ public abstract class LuceneTestCase ext
* or {@link #createTempDir(String)} or {@link #createTempFile(String, String)}.
*/
@Deprecated
- public static File getBaseTempDirForTestClass() {
+ public static Path getBaseTempDirForTestClass() {
return tempFilesCleanupRule.getPerTestClassTempDir();
}
@@ -2374,7 +2373,7 @@ public abstract class LuceneTestCase ext
*
* @see #createTempDir(String)
*/
- public static File createTempDir() {
+ public static Path createTempDir() {
return createTempDir("tempDir");
}
@@ -2386,7 +2385,7 @@ public abstract class LuceneTestCase ext
* test class completes successfully. The test should close any file handles that would prevent
* the folder from being removed.
*/
- public static File createTempDir(String prefix) {
+ public static Path createTempDir(String prefix) {
return tempFilesCleanupRule.createTempDir(prefix);
}
@@ -2398,7 +2397,7 @@ public abstract class LuceneTestCase ext
* test class completes successfully. The test should close any file handles that would prevent
* the folder from being removed.
*/
- public static File createTempFile(String prefix, String suffix) throws IOException {
+ public static Path createTempFile(String prefix, String suffix) throws IOException {
return tempFilesCleanupRule.createTempFile(prefix, suffix);
}
@@ -2407,7 +2406,7 @@ public abstract class LuceneTestCase ext
*
* @see #createTempFile(String, String)
*/
- public static File createTempFile() throws IOException {
+ public static Path createTempFile() throws IOException {
return createTempFile("tempFile", ".tmp");
}
}
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java?rev=1624784&r1=1624783&r2=1624784&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/util/RemoveUponClose.java Sat Sep 13 21:46:29 2014
@@ -1,8 +1,9 @@
package org.apache.lucene.util;
import java.io.Closeable;
-import java.io.File;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -25,12 +26,12 @@ import java.io.IOException;
* A {@link Closeable} that attempts to remove a given file/folder.
*/
final class RemoveUponClose implements Closeable {
- private final File file;
+ private final Path path;
private final TestRuleMarkFailure failureMarker;
private final String creationStack;
- public RemoveUponClose(File file, TestRuleMarkFailure failureMarker) {
- this.file = file;
+ public RemoveUponClose(Path path, TestRuleMarkFailure failureMarker) {
+ this.path = path;
this.failureMarker = failureMarker;
StringBuilder b = new StringBuilder();
@@ -44,13 +45,13 @@ final class RemoveUponClose implements C
public void close() throws IOException {
// only if there were no other test failures.
if (failureMarker.wasSuccessful()) {
- if (file.exists()) {
+ if (Files.exists(path)) {
try {
- IOUtils.rm(file);
+ IOUtils.rm(path);
} catch (IOException e) {
throw new IOException(
"Could not remove temporary location '"
- + file.getAbsolutePath() + "', created at stack trace:\n" + creationStack, e);
+ + path.toAbsolutePath() + "', created at stack trace:\n" + creationStack, e);
}
}
}