Code example for ByteBuffer

Methods: markpositionresetequalsput

0
 
    private void checkReadWrite(ByteBuffer bb) throws IOException
    { 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(bos);
        ByteBufferUtil.writeWithLength(bb, out);
        ByteBufferUtil.writeWithShortLength(bb, out);
 
        DataInputStream in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
        assert bb.equals(ByteBufferUtil.readWithLength(in));
        assert bb.equals(ByteBufferUtil.readWithShortLength(in));
    } 
 
    @Test 
    public void testInputStream() throws IOException 
    { 
        ByteBuffer bb = ByteBuffer.allocate(13);
        bb.putInt(255);
        bb.put((byte) -3);
        bb.putLong(42L);
Contextual code suggestions in your IDE  Get Codota for Java