src/main/java/org/nustaq/serialization/FSTConfiguration.java
public byte[] asSharedByteArray( Object object, int length[] ) {
        FSTObjectOutput objectOutput = getObjectOutput();
        try {
            objectOutput.writeObject(object);
            length[0] = objectOutput.getWritten();
            return objectOutput.getBuffer();
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        return null;
    }
public byte[] asSharedByteArray( Object object, int length[] ) {
        FSTObjectOutput objectOutput = getObjectOutput();
        try {
            objectOutput.writeObject(object);
            length[0] = objectOutput.getWritten();
            return objectOutput.getBuffer();
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        return null;
    }
Warning: avoids allocation + copying.
The returned byteArray is a direct pointer to underlying buffer.
the int length[] is expected to have at least on element.
The buffer can be larger than written data, therefore length[0] will contain written length.

The buffer content must be used (e.g. sent to network, copied to offheap) before doing another
asByteArray on the current Thread.