Code example for DataInputStream

Methods: readByte, readInt, readLong

0
        bb.putInt(255);
        bb.put((byte) -3);
        bb.putLong(42L);
        bb.clear();
 
        DataInputStream in = new DataInputStream(ByteBufferUtil.inputStream(bb));
        assert in.readInt() == 255;
        assert in.readByte() == (byte)-3;
        assert in.readLong() == 42L;
    } 
 
    @Test 
    public void testIntBytesConversions() 
    { 
        // positive, negative, 1 and 2 byte cases, including a few edges that would foul things up unless you're careful 
        // about masking away sign extension. 
        int[] ints = new int[]
        { 
            -20, -127, -128, 0, 1, 127, 128, 65534, 65535, -65534, -65535 
        };