Skip to content

Instantly share code, notes, and snippets.

@timrobertson100
Created September 20, 2014 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timrobertson100/031bbe37d79d82f7c1fa to your computer and use it in GitHub Desktop.
Save timrobertson100/031bbe37d79d82f7c1fa to your computer and use it in GitHub Desktop.
/**
* 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