public static byte[] readBytes(ByteBuffer buffer) {
        return readBytes(buffer, 0, buffer.remaining());
    }
@Test
    public void readBytesFromNonArrayBackedByteBuffer() {
        final byte[] bytes = "FOOBAR".getBytes(StandardCharsets.US_ASCII);
        final ByteBuffer buffer1 = ByteBuffer.allocateDirect(1024);
        buffer1.put(bytes).flip();
        final ByteBuffer buffer2 = ByteBuffer.allocateDirect(1024);
        buffer2.put(bytes).flip();

        final byte[] readBytesComplete = ByteBufferUtils.readBytes(buffer1);
        final byte[] readBytesPartial = ByteBufferUtils.readBytes(buffer2, 0, 3);

        assertThat(readBytesComplete).isEqualTo(bytes);
        assertThat(readBytesPartial).isEqualTo(Arrays.copyOf(bytes, 3));
    }