Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
  • Loading branch information
overheadhunter committed Oct 30, 2019
2 parents 4b6c348 + ea8356f commit fb67c46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ public void force(boolean metaData) throws IOException {
}

private void forceInternal(boolean metaData) throws IOException {
if (isWritable()) {
writeHeaderIfNeeded();
chunkCache.invalidateAll(); // TODO performance: write chunks but keep them cached
exceptionsDuringWrite.throwIfPresent();
}
flush();
ciphertextFileChannel.force(metaData);
if (metaData) {
FileTime lastModifiedTime = isWritable() ? FileTime.from(lastModified.get()) : null;
Expand All @@ -221,6 +217,18 @@ private void forceInternal(boolean metaData) throws IOException {
}
}

/**
* Writes in-memory contents to the ciphertext file
* @throws IOException
*/
private void flush() throws IOException {
if (isWritable()) {
writeHeaderIfNeeded();
chunkCache.invalidateAll(); // TODO performance: write chunks but keep them cached
exceptionsDuringWrite.throwIfPresent();
}
}

@Override
public MappedByteBuffer map(MapMode mode, long position, long size) {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -285,7 +293,7 @@ long beginOfChunk(long cleartextPos) {
@Override
protected void implCloseChannel() throws IOException {
try {
forceInternal(true);
flush();
} finally {
super.implCloseChannel();
closeListener.closed(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
@OpenFileScoped
public class ExceptionsDuringWrite {

private final List<IOException> exceptions = new ArrayList<>();
private final IOException e = new IOException("Exceptions occured while writing");

@Inject
public ExceptionsDuringWrite() {
}

public synchronized void add(IOException e) {
exceptions.add(e);
e.addSuppressed(e);
}

public synchronized void throwIfPresent() throws IOException {
if (!exceptions.isEmpty()) {
IOException e = new IOException("Exceptions occured while writing");
exceptions.forEach(e::addSuppressed);
if (e.getSuppressed().length > 0) {
e.fillInStackTrace();
throw e;
}
}
Expand Down

0 comments on commit fb67c46

Please sign in to comment.