46
46
import java .io .FileOutputStream ;
47
47
import java .io .IOException ;
48
48
import java .nio .charset .StandardCharsets ;
49
- import java .nio .file .Files ;
50
49
import java .nio .file .Path ;
50
+ import java .nio .file .Paths ;
51
51
import java .util .Collection ;
52
52
import java .util .Collections ;
53
53
import java .util .HashMap ;
66
66
*/
67
67
class SuggesterProjectData implements Closeable {
68
68
69
+ private static final String TMP_DIR_PROPERTY = "java.io.tmpdir" ;
70
+
69
71
private static final Logger logger = Logger .getLogger (SuggesterProjectData .class .getName ());
70
72
71
73
private static final int MAX_TERM_SIZE = Short .MAX_VALUE - 3 ;
72
74
73
- private static final String TEMP_DIR_PREFIX = "opengrok_suggester " ;
75
+ private static final String WFST_TEMP_FILE_PREFIX = "opengrok_suggester_wfst " ;
74
76
75
77
private static final String WFST_FILE_SUFFIX = ".wfst" ;
76
78
@@ -98,7 +100,7 @@ class SuggesterProjectData implements Closeable {
98
100
99
101
private Set <String > fields ;
100
102
101
- private final Path tempDir ;
103
+ private final Directory tempDir ;
102
104
103
105
SuggesterProjectData (
104
106
final Directory indexDir ,
@@ -110,7 +112,7 @@ class SuggesterProjectData implements Closeable {
110
112
this .suggesterDir = suggesterDir ;
111
113
this .allowMostPopular = allowMostPopular ;
112
114
113
- tempDir = Files . createTempDirectory ( TEMP_DIR_PREFIX );
115
+ tempDir = FSDirectory . open ( Paths . get ( System . getProperty ( TMP_DIR_PROPERTY )) );
114
116
115
117
initFields (fields );
116
118
}
@@ -210,8 +212,8 @@ private WFSTCompletionLookup loadStoredWFST(final File file) throws IOException
210
212
}
211
213
}
212
214
213
- private WFSTCompletionLookup createWFST () throws IOException {
214
- return new WFSTCompletionLookup (FSDirectory . open ( tempDir ), TEMP_DIR_PREFIX );
215
+ private WFSTCompletionLookup createWFST () {
216
+ return new WFSTCompletionLookup (tempDir , WFST_TEMP_FILE_PREFIX );
215
217
}
216
218
217
219
private File getWFSTFile (final String field ) {
@@ -451,7 +453,7 @@ public void close() throws IOException {
451
453
});
452
454
indexDir .close ();
453
455
454
- FileUtils . deleteDirectory ( tempDir .toFile () );
456
+ tempDir .close ( );
455
457
} finally {
456
458
lock .writeLock ().unlock ();
457
459
}
0 commit comments