src/main/java/org/nustaq/serialization/simpleapi/DefaultCoder.java
public int toByteArray( Object obj, byte result[], int resultOffset, int avaiableSize ) {
        output.resetForReUse();
        try {
            output.writeObject(obj);
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        int written = output.getWritten();
        if ( written > avaiableSize ) {
            throw FSTBufferTooSmallException.Instance;
        }
        System.arraycopy(output.getBuffer(),0,result,resultOffset, written);
        return written;
    }
public int toByteArray( Object obj, byte result[], int resultOffset, int avaiableSize ) {
        output.resetForReUse();
        try {
            output.writeObject(obj);
        } catch (IOException e) {
            FSTUtil.<RuntimeException>rethrow(e);
        }
        int written = output.getWritten();
        if ( written > avaiableSize ) {
            throw FSTBufferTooSmallException.Instance;
        }
        System.arraycopy(output.getBuffer(),0,result,resultOffset, written);
        return written;
    }
will throw an FSTBufferTooSmallException if buffer is too small.