Fixed CryptoWritableFile errors when reading from moved file

* CryptoWritableFile no longer writes header with zero size if file is
opened for writing
* Refactored FileContentDecryptor: Using Supplier<Mac> instead of
ThreadLocal<Mac>
* Fixed InMemoryWritableFile: No longer open after moveTo
This commit is contained in:
Markus Kreusch
2016-02-21 21:33:35 +01:00
parent 023e7d70e5
commit 391d8013b5
3 changed files with 17 additions and 7 deletions
@@ -47,11 +47,21 @@ public class InMemoryWritableFile implements WritableFile {
@Override
public void moveTo(WritableFile other) throws UncheckedIOException {
if (other instanceof InMemoryWritableFile) {
InMemoryWritableFile destination = (InMemoryWritableFile) other;
internalMoveTo((InMemoryWritableFile) other);
} else {
throw new IllegalArgumentException("Can only move an InMemoryWritableFile to another InMemoryWritableFile");
}
}
private void internalMoveTo(InMemoryWritableFile destination) {
try {
destination.contentSetter.accept(this.contentGetter.get());
destination.contentGetter.get().rewind();
deleter.run();
} finally {
open = false;
destination.open = false;
}
deleter.run();
}
@Override
@@ -84,8 +94,8 @@ public class InMemoryWritableFile implements WritableFile {
ByteBuffers.copy(old, destination);
contentSetter.accept(destination);
}
destination.position(position);
destination.limit(newFileSize);
destination.position(position);
int numWritten = ByteBuffers.copy(source, destination);
this.position += numWritten;
return numWritten;