public static void put(ByteBuffer dst, ByteBuffer src) {
        if (src.remaining() <= dst.remaining()) {
            // there is enough space in the dst buffer to copy the src
            dst.put(src);
        } else {
            // there is not enough space in the dst buffer, so we need to
            // copy as much as we can.
            int srcOldLimit = src.limit();
            src.limit(src.position() + dst.remaining());
            dst.put(src);
            src.limit(srcOldLimit);
        }
    }
@Test
    public void test_put_notEnoughSpace() {
        ByteBuffer src = ByteBuffer.allocate(8);
        src.putInt(1);
        src.putInt(2);
        src.flip();
        int srcPos = src.position();
        int srcLimit = src.limit();

        ByteBuffer dst = ByteBuffer.allocate(4);
        BufferUtil.put(dst, src);
        dst.flip();
        assertEquals(4, dst.remaining());
        assertEquals(1, dst.getInt());

        assertEquals(srcPos + 4, src.position());
        assertEquals(srcLimit, src.limit());
    }