Java ByteBuffer to Long readUInt32(ByteBuffer buf, int length)

Here you can find the source of readUInt32(ByteBuffer buf, int length)

Description

read U Int

License

Open Source License

Declaration

public static long readUInt32(ByteBuffer buf, int length) 

Method Source Code

//package com.java2s;
/**//  w  w w  . j  a v  a 2  s . com
 * Project: ${puma-common.aid}
 * <p/>
 * File Created at 2012-6-6 $Id$
 * <p/>
 * Copyright 2010 dianping.com. All rights reserved.
 * <p/>
 * This software is the confidential and proprietary information of Dianping
 * Company. ("Confidential Information"). You shall not disclose such
 * Confidential Information and shall use it only in accordance with the terms
 * of the license agreement you entered into with dianping.com.
 */

import java.nio.ByteBuffer;

public class Main {
    public static long readUInt32(ByteBuffer buf, int length) {
        if ((buf.position() + length) <= buf.limit() && length <= 4) {
            long r = 0;
            for (int i = 0; i < length; i++) {
                r |= (((long) (buf.get() & 0xff)) << (i << 3));
            }
            return r;
        }
        return 0;
    }
}

Related

  1. readUB1(ByteBuffer buffer)
  2. readUB4(ByteBuffer buffer)
  3. readUBEInt16(ByteBuffer b)
  4. readUInt16(ByteBuffer bb)
  5. readUInt16BE(ByteBuffer bb)
  6. readUInt64(ByteBuffer bb)
  7. readUInt64(ByteBuffer byteBuffer)
  8. readUInt8(ByteBuffer bb)
  9. readVarLong(ByteBuffer buff)