diff --git a/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java b/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java index 3679cdaa..5acb9db7 100644 --- a/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java +++ b/cassandra-executor/src/main/java/com/mesosphere/dcos/cassandra/executor/backup/azure/PageBlobOutputStream.java @@ -30,6 +30,7 @@ public class PageBlobOutputStream extends FilterOutputStream { private long currentPageSize = PAGE_BLOB_PAGE_SIZE; private volatile IOException lastError; + private boolean closed = false; /** * Creates an output stream filter built on top of the Azure @@ -63,10 +64,17 @@ public void write(int b) throws IOException { internalWrite(b); } + @Override + public void flush() throws IOException { + // cannot flush untill close + } + @Override public void close() throws IOException { this.checkStreamState(); + if(closed) + return; // top off page size // flush write does NOT occur unless full page is written @@ -74,11 +82,16 @@ public void close() throws IOException { byte[] pad = new byte[(int) (currentPageSize - count)]; writePad(pad); } - super.close(); - + try { + super.flush(); + super.close(); + } finally { + closed = true; + } uploadMetadata(); } + private void writePad(byte[] pad) throws IOException { out.write(pad); }