class FilterRecord {

    public int writeFullyTo(FileChannel channel) throws IOException {
        final long startPos = channel.position();
        // write body first then we can know how large the body is
        channel.position(startPos + HEADER_OVERHEAD);

        // we don't need to close this stream. it'll be effectively closed when the underlying channel closed
        final ChecksumedBufferedOutputStream stream = new ChecksumedBufferedOutputStream(
                Channels.newOutputStream(channel),
                Configuration.channelBufferSizeForFilterPersistence());
        writeBody(stream);
        stream.flush();

        // write header
        int bodyLen = (int) (channel.position() - startPos - HEADER_OVERHEAD);
        channel.position(startPos);

        final ByteBuffer headerBuffer = ByteBuffer.allocate(HEADER_OVERHEAD);
        headerBuffer.putInt(BODY_LENGTH_OFFSET, bodyLen);
        headerBuffer.put(MAGIC_OFFSET, DEFAULT_MAGIC);
        headerBuffer.putInt(CRC_OFFSET, (int) stream.checksum());
        writeBufferTo(channel, headerBuffer);

        // move position forward to the end of this record
        channel.position(startPos + HEADER_OVERHEAD + bodyLen);
        return HEADER_OVERHEAD + bodyLen;
    }

    public  FilterRecord(String name, F filter);

}