From e2761fed4426ce8916289693e5707c966af2f2e2 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Wed, 20 Aug 2014 09:40:48 +0000 Subject: [PATCH] LUCENE-5893: use Files.createTempDirectory git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1619057 13f79535-47bb-0310-9956-ffa450edef68 --- .../suggest/analyzing/FreeTextSuggester.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java index aa4719406c9..c294dac8b31 100644 --- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java +++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/analyzing/FreeTextSuggester.java @@ -51,14 +51,10 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRefBuilder; -import org.apache.lucene.util.CharsRef; import org.apache.lucene.util.CharsRefBuilder; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IntsRef; import org.apache.lucene.util.IntsRefBuilder; -import org.apache.lucene.util.OfflineSorter; -import org.apache.lucene.util.UnicodeUtil; -import org.apache.lucene.util.Version; import org.apache.lucene.util.fst.Builder; import org.apache.lucene.util.fst.FST; import org.apache.lucene.util.fst.FST.Arc; @@ -71,12 +67,12 @@ import org.apache.lucene.util.fst.Util.TopResults; import java.io.File; import java.io.IOException; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; -import java.util.Random; import java.util.Set; //import java.io.PrintWriter; @@ -296,17 +292,7 @@ public class FreeTextSuggester extends Lookup { } String prefix = getClass().getSimpleName(); - File directory = OfflineSorter.defaultTempDir(); - // TODO: messy ... java7 has Files.createTempDirectory - // ... but 4.x is java6: - File tempIndexPath = null; - Random random = new Random(); - while (true) { - tempIndexPath = new File(directory, prefix + ".index." + random.nextInt(Integer.MAX_VALUE)); - if (tempIndexPath.mkdir()) { - break; - } - } + File tempIndexPath = Files.createTempDirectory(prefix + ".index.").toFile(); Directory dir = FSDirectory.open(tempIndexPath);