Code example for ByteBuffer

Methods: putInt

0
     * @param bb ByteBuffer to put the int into 
     * @param v the long containing the unsigned int 
     * @param offset the offset to insert the unsigned int at 
     */ 
    public static void putUnsignedInt(ByteBuffer bb, long v, int offset) {
        bb.putInt(offset, (int) (v & 0xffffffffL));
    } 
 
    /** 
     * Get an unsigned long from the current position of the ByteBuffer 
     * 
     * @param bb ByteBuffer to get the long from 
     * @return an unsigned long contained in a BigInteger 
     */ 
    public static BigInteger getUnsignedLong(ByteBuffer bb) {
        byte[] v = new byte[8];
        for (int i = 0; i < 8; ++i) {
            v[i] = bb.get(i);
        } 
        return new BigInteger(1, v);
    }