public void writeFooterFor(ByteBuffer bb) throws IOException {
        if (rawOut.getBytesWritten() != 0)
            throw new IllegalStateException("writeFooterFor can only be called at a footer boundary.");
        ByteBuffer source = bb.duplicate();
        byte[] bytes;
        if (source.hasArray()) {
            bytes = source.array();
        } else {
            bytes = new byte[source.remaining()];
            source.get(bytes);
        }
        rawOut.getChecksum().update(bytes, 0, source.remaining());
        internalWriteFooter(source.remaining());
    }