public byte[] data()
    {
        if (buf.hasArray()) {
            byte[] array = buf.array();
            int offset = buf.arrayOffset();

            if (offset == 0 && array.length == size) {
                // If the backing array is exactly what we need, return it without copy.
                return array;
            }
            else {
                // Else use it to make an efficient copy.
                return Arrays.copyOfRange(array, offset, offset + size);
            }
        }
        else {
            // No backing array -> use ByteBuffer#get().
            byte[] array = new byte[size];
            ByteBuffer dup = buf.duplicate();
            dup.position(0);
            dup.get(array);
            return array;
        }
    }
@Test
    public void testDataNonZeroOffset()
    {
        byte[] data = new byte[]{10, 11, 12};

        ByteBuffer buffer = ByteBuffer.wrap(data, 1, 2).slice();
        Msg msg = new Msg(buffer);

        assertThat(msg.data(), is(new byte[]{11, 12}));
    }