class ConfluentSchemaRegistryWriter implements SchemaAccessWriter {

    @Override
    public void writeHeader(final RecordSchema schema, final OutputStream out) throws IOException {
        final SchemaIdentifier identifier = schema.getIdentifier();
        final Long id = identifier.getIdentifier().getAsLong();

        // This encoding follows the pattern that is provided for serializing data by the Confluent Schema Registry serializer
        // as it is provided at:
        // http://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format
        // The format consists of the first byte always being 0, to indicate a 'magic byte' followed by 4 bytes
        // representing the schema id.
        final ByteBuffer bb = ByteBuffer.allocate(5);
        bb.put((byte) 0);
        bb.putInt(id.intValue());

        out.write(bb.array());
    }

}