comparison src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1473:6c6ce14db6a8

add goodjava.io
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 17 Apr 2020 13:56:57 -0600
parents 5e3870618377
children c7b86342857f
comparison
equal deleted inserted replaced
1472:60f6741f000a 1473:6c6ce14db6a8
20 import org.apache.lucene.search.Query; 20 import org.apache.lucene.search.Query;
21 import org.apache.lucene.search.MatchAllDocsQuery; 21 import org.apache.lucene.search.MatchAllDocsQuery;
22 import org.apache.lucene.search.TopDocs; 22 import org.apache.lucene.search.TopDocs;
23 import org.apache.lucene.store.Directory; 23 import org.apache.lucene.store.Directory;
24 import org.apache.lucene.store.FSDirectory; 24 import org.apache.lucene.store.FSDirectory;
25 import goodjava.io.IoUtils;
25 import goodjava.lucene.api.GoodIndexWriter; 26 import goodjava.lucene.api.GoodIndexWriter;
26 import goodjava.lucene.api.LuceneIndexWriter; 27 import goodjava.lucene.api.LuceneIndexWriter;
27 import goodjava.lucene.api.GoodCollector; 28 import goodjava.lucene.api.GoodCollector;
28 import goodjava.lucene.api.LuceneUtils; 29 import goodjava.lucene.api.LuceneUtils;
29 import goodjava.logging.Logger; 30 import goodjava.logging.Logger;
112 file = new File(logDir,"_"+rnd.nextInt(100)+".log"); 113 file = new File(logDir,"_"+rnd.nextInt(100)+".log");
113 } while( file.exists() ); 114 } while( file.exists() );
114 return new LogFile(file,"rwd"); 115 return new LogFile(file,"rwd");
115 } 116 }
116 117
117 private void deleteUnusedFiles() { 118 private void deleteUnusedFiles() throws IOException {
118 Set<String> used = new HashSet<String>(); 119 Set<String> used = new HashSet<String>();
119 used.add( index.getName() ); 120 used.add( index.getName() );
120 for( LogFile lf : logs ) { 121 for( LogFile lf : logs ) {
121 used.add( lf.file.getName() ); 122 used.add( lf.file.getName() );
122 } 123 }
125 deleteFile(f); 126 deleteFile(f);
126 } 127 }
127 } 128 }
128 } 129 }
129 130
130 private static void deleteFile(File file) { 131 private static void deleteFile(File file) throws IOException {
131 if( file.isDirectory() ) { 132 if( file.isDirectory() ) {
132 for( File f : file.listFiles() ) { 133 for( File f : file.listFiles() ) {
133 deleteFile(f); 134 deleteFile(f);
134 } 135 }
135 } 136 }
136 if( !file.delete() ) 137 IoUtils.delete(file);
137 throw new RuntimeException(file.getName());
138 } 138 }
139 139
140 private void writeIndex() throws IOException { 140 private void writeIndex() throws IOException {
141 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 141 ByteArrayOutputStream baos = new ByteArrayOutputStream();
142 DataOutputStream dos = new DataOutputStream(baos); 142 DataOutputStream dos = new DataOutputStream(baos);