Code example for ByteBuffer

Methods: capacity, get, position

0
    } 
 
    /* ------------------------------------------------------------ */ 
    public int capacity() 
    { 
        return _buf.capacity();
    } 
 
    /* ------------------------------------------------------------ */ 
    public byte peek(int position)
    { 
        return _buf.get(position);
    } 
 
    public int peek(int index, byte[] b, int offset, int length)
    { 
        int l = length;
        if (index+l > capacity())
        { 
            l=capacity()-index;
            if (l==0)
                return -1; 
        } 
         
        if (l < 0) 
            return -1; 
        try 
        { 
            _buf.position(index);
            _buf.get(b,offset,l);
        } 
        finally 
        { 
            _buf.position(0);
        } 
         
        return l;
    }