1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 17:28:51 -05:00

* better account for large history files

This commit is contained in:
Reinhard Pointner 2013-11-17 19:05:45 +00:00
parent 1c89f8c3ef
commit f4070a4c07

View File

@ -1,7 +1,5 @@
package net.sourceforge.filebot; package net.sourceforge.filebot;
import static net.sourceforge.filebot.Settings.*; import static net.sourceforge.filebot.Settings.*;
import java.io.File; import java.io.File;
@ -19,12 +17,10 @@ import net.sourceforge.filebot.History.Element;
import net.sourceforge.tuned.ByteBufferInputStream; import net.sourceforge.tuned.ByteBufferInputStream;
import net.sourceforge.tuned.ByteBufferOutputStream; import net.sourceforge.tuned.ByteBufferOutputStream;
public final class HistorySpooler { public final class HistorySpooler {
private static final HistorySpooler instance = new HistorySpooler(); private static final HistorySpooler instance = new HistorySpooler();
public static HistorySpooler getInstance() { public static HistorySpooler getInstance() {
return instance; return instance;
} }
@ -35,7 +31,6 @@ public final class HistorySpooler {
private History sessionHistory = new History(); private History sessionHistory = new History();
public synchronized History getCompleteHistory() throws IOException { public synchronized History getCompleteHistory() throws IOException {
if (!persistentHistoryEnabled || persistentHistoryFile.length() <= 0) { if (!persistentHistoryEnabled || persistentHistoryFile.length() <= 0) {
return new History(); return new History();
@ -58,7 +53,6 @@ public final class HistorySpooler {
} }
} }
public synchronized void commit() { public synchronized void commit() {
if (!persistentHistoryEnabled || sessionHistory.sequences().isEmpty()) { if (!persistentHistoryEnabled || sessionHistory.sequences().isEmpty()) {
return; return;
@ -72,7 +66,7 @@ public final class HistorySpooler {
FileChannel channel = f.getChannel(); FileChannel channel = f.getChannel();
FileLock lock = channel.lock(); FileLock lock = channel.lock();
try { try {
ByteBufferOutputStream data = new ByteBufferOutputStream(f.length()); ByteBufferOutputStream data = new ByteBufferOutputStream((int) (f.length() > 0 ? f.length() : 1024), 0.2f);
int read = data.transferFully(channel); int read = data.transferFully(channel);
History history = read > 0 ? History.importHistory(new ByteBufferInputStream(data.getByteBuffer())) : new History(); History history = read > 0 ? History.importHistory(new ByteBufferInputStream(data.getByteBuffer())) : new History();
@ -98,7 +92,6 @@ public final class HistorySpooler {
} }
} }
public synchronized void append(Iterable<Entry<File, File>> elements) { public synchronized void append(Iterable<Entry<File, File>> elements) {
List<Element> sequence = new ArrayList<Element>(); List<Element> sequence = new ArrayList<Element>();
@ -112,17 +105,14 @@ public final class HistorySpooler {
} }
} }
public History getSessionHistory() { public History getSessionHistory() {
return sessionHistory; return sessionHistory;
} }
public int getPersistentHistoryTotalSize() { public int getPersistentHistoryTotalSize() {
return persistentHistoryTotalSize; return persistentHistoryTotalSize;
} }
public void setPersistentHistoryEnabled(boolean persistentHistoryEnabled) { public void setPersistentHistoryEnabled(boolean persistentHistoryEnabled) {
this.persistentHistoryEnabled = persistentHistoryEnabled; this.persistentHistoryEnabled = persistentHistoryEnabled;
} }