Mercurial Hosting > luan
view src/goodjava/lucene/backup/BackupIndexWriter.java @ 1489:fe237d72b234
improve BufferedInputStream
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 02 May 2020 16:28:24 -0600 |
parents | af55cfad6e12 |
children | 22e15cf73040 |
line wrap: on
line source
package goodjava.lucene.backup; import java.io.File; import java.io.IOException; import java.util.List; import java.util.ArrayList; import goodjava.io.IoUtils; import goodjava.lucene.api.LuceneIndexWriter; import goodjava.lucene.logging.LoggingIndexWriter; import goodjava.lucene.logging.LogFile; public class BackupIndexWriter extends LoggingIndexWriter { private final String name; private final File dir; public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,String name) throws IOException { super(indexWriter,logDir); this.name = name; File f = new File(System.getProperty("java.io.tmpdir")); dir = new File(f,"goodjava.lucene/"+name); dir.mkdirs(); } public synchronized void commit() throws IOException { super.commit(); sync(); } private void sync() throws IOException { for( File f : dir.listFiles() ) { IoUtils.delete(f); } List<LogFile> logs = new ArrayList<LogFile>(); for( LogFile log : this.logs ) { File f = new File(dir,log.file.getName()); IoUtils.link(log.file,f); logs.add( new LogFile(f) ); } } }