Code example for ByteBuffer

Methods: mark, position, put, reset

0
ByteBuffer tmp = ByteBuffer.allocate(l + pos + 3);
            tmp.position(3);
            bb = tmp.slice(); // make bb have a non null arrayOffset
        } 
        bb.position(pos);
        bb.mark();
        bb.put(s.getBytes());
        bb.reset();
        assert bb.position() == pos;
        return bb;
    } 
 
    @Test 
    public void testString() throws Exception 
    { 
        assert s.equals(ByteBufferUtil.string(ByteBufferUtil.bytes(s)));
 
        int pos = 10;
        ByteBuffer bb = fromStringWithPosition(s, 10, false);
        assert s.equals(ByteBufferUtil.string(bb, 10, s.length()));