@Override
    public byte[] write(final Object o, final Class<?> clazz, final String entryName) throws Exception  {
        final Buffer buffer = bufferFactory.create(allocator.buffer());
        try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
            writer.write(o, buffer);
            buffer.readerIndex(0);
            buffer.readBytes(stream, buffer.readableBytes());

            final byte[] bytes = stream.toByteArray();

            // write out files for debugging purposes
            final File f = new File(testCaseDataPath + File.separator + entryName + "-" + getCompatibility() + ".gbin");
            if (f.exists()) f.delete();
            try (FileOutputStream fileOuputStream = new FileOutputStream(f)) {
                fileOuputStream.write(bytes);
            }

            return bytes;
        }
    }
@author Stephen Mallette (http://stephen.genoprime.com)
gremlin-util/src/test/java/org/apache/tinkerpop/gremlin/structure/io/graphbinary/GraphBinaryCompatibilityTest.java