Created
September 20, 2014 11:48
-
-
Save timrobertson100/031bbe37d79d82f7c1fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Writes the custom fixed length footer to the stream. | |
*/ | |
@Override | |
public void finish() throws IOException { | |
flush(); // make sure deflater flushes, and counts are accurate | |
// Push the custom footer to the output stream | |
ByteBuffer footer = ByteBuffer.allocate(26); | |
footer.put(FOOTER_CLOSE_DEFLATE); // 2 bytes: which means the deflate stream can be read in isolation | |
footer.putLong(def.getBytesRead()); // 8 bytes: uncompressed length | |
footer.putLong(def.getBytesWritten()); // 8 bytes: compressed length | |
footer.putLong(getCRC32()); // 8 bytes: CRC 32 | |
out.write(footer.array()); // Straight to the underlying stream, no deflation (Important!) | |
out.flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment