Code example for ByteBuffer

Methods: get, getInt, hasRemaining, position

0
 
    private static final int  DEFAULT_SIZE     = 33;
    private static final long serialVersionUID = 1L;
 
    public static NodeIdSet readWireForm(ByteBuffer bytes, int idx, int len) {
        assert bytes.hasRemaining() : "Empty byte buffer";
        bytes.position(idx);
        byte[] storage = new byte[bytes.getInt()];
        bytes.get(storage);
        return new NodeIdSet(storage);
    } 
 
    /** 
     * use a byte array to hold the bits for messaging efficency. 
     */ 
    private byte[] storage;
 
    /** 
     * create a bitset with a default size 
     */ 
    public NodeIdSet() {