@Override
    public void put2PrefixedBytes(final byte[] bytes) {
        if (bytes == null) {
            checkExpand(BytesUtils.SHORT_BYTE_LENGTH);
            super.putShort((short)NULL);
        } else {
            if (bytes.length > Short.MAX_VALUE) {
                throw new IndexOutOfBoundsException("too large bytes length:" + bytes.length);
            }
            checkExpand(bytes.length + BytesUtils.SHORT_BYTE_LENGTH);
            super.putShort((short)bytes.length);
            super.putBytes(bytes);
        }
    }
Buffer that can be expanded automatically
@author emeroad
commons-buffer/src/main/java/com/navercorp/pinpoint/common/buffer/AutomaticBuffer.java