@Override
    public byte[] readArray(int size) {
        int remaining = buf.remaining();
        if (size > remaining) {
            throw new RuntimeException("Error reading byte array of " + size + " byte(s): only " + remaining +
                    " byte(s) available");
        }
        byte[] arr = new byte[size];
        buf.get(arr);
        return arr;
    }
@Test
    public void testReadArray() {
        ByteBuffer buf = ByteBuffer.allocate(1024);
        ByteBufferAccessor accessor = new ByteBufferAccessor(buf);
        final byte[] testArray = new byte[] {0x4b, 0x61, 0x46};
        accessor.writeByteArray(testArray);
        accessor.writeInt(12345);
        accessor.flip();
        final byte[] testArray2 = accessor.readArray(3);
        assertArrayEquals(testArray, testArray2);
        assertEquals(12345, accessor.readInt());
        assertEquals("Error reading byte array of 3 byte(s): only 0 byte(s) available",
            assertThrows(RuntimeException.class,
                () -> accessor.readArray(3)).getMessage());
    }