mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
* fix history spooler memory issues
This commit is contained in:
parent
16d7ad513a
commit
35d343425a
@ -5,6 +5,7 @@ import static net.sourceforge.filebot.Settings.*;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.RandomAccessFile;
|
import java.io.RandomAccessFile;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.FileLock;
|
import java.nio.channels.FileLock;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -14,8 +15,9 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.sourceforge.filebot.History.Element;
|
import net.sourceforge.filebot.History.Element;
|
||||||
import net.sourceforge.tuned.ByteBufferInputStream;
|
|
||||||
import net.sourceforge.tuned.ByteBufferOutputStream;
|
import org.apache.commons.io.input.CloseShieldInputStream;
|
||||||
|
import org.apache.commons.io.output.CloseShieldOutputStream;
|
||||||
|
|
||||||
public final class HistorySpooler {
|
public final class HistorySpooler {
|
||||||
|
|
||||||
@ -40,10 +42,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());
|
History history = History.importHistory(new CloseShieldInputStream(Channels.newInputStream(channel))); // keep JAXB from closing the stream
|
||||||
data.transferFully(channel);
|
|
||||||
|
|
||||||
History history = History.importHistory(new ByteBufferInputStream(data.getByteBuffer()));
|
|
||||||
history.addAll(sessionHistory.sequences());
|
history.addAll(sessionHistory.sequences());
|
||||||
return history;
|
return history;
|
||||||
} finally {
|
} finally {
|
||||||
@ -66,17 +65,19 @@ 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((int) (f.length() > 0 ? f.length() : 1024), 0.2f);
|
History history = new History();
|
||||||
int read = data.transferFully(channel);
|
if (persistentHistoryFile.length() > 0) {
|
||||||
|
try {
|
||||||
History history = read > 0 ? History.importHistory(new ByteBufferInputStream(data.getByteBuffer())) : new History();
|
channel.position(0); // rewind
|
||||||
|
history = History.importHistory(new CloseShieldInputStream(Channels.newInputStream(channel))); // keep JAXB from closing the stream
|
||||||
|
} catch (Exception e) {
|
||||||
|
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to load rename history.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
history.addAll(sessionHistory.sequences());
|
history.addAll(sessionHistory.sequences());
|
||||||
|
|
||||||
data.rewind();
|
|
||||||
History.exportHistory(history, data);
|
|
||||||
|
|
||||||
channel.position(0);
|
channel.position(0);
|
||||||
channel.write(data.getByteBuffer());
|
History.exportHistory(history, new CloseShieldOutputStream(Channels.newOutputStream(channel))); // keep JAXB from closing the stream
|
||||||
|
|
||||||
sessionHistory.clear();
|
sessionHistory.clear();
|
||||||
persistentHistoryTotalSize = history.totalSize();
|
persistentHistoryTotalSize = history.totalSize();
|
||||||
|
Loading…
Reference in New Issue
Block a user