Java ByteBuffer to Int readUnsignedInt(ByteBuffer buf)

Here you can find the source of readUnsignedInt(ByteBuffer buf)

Description

Unmarshall the next four bytes which hold an unsigned int into a long.

License

Open Source License

Declaration

public static long readUnsignedInt(ByteBuffer buf) 

Method Source Code


//package com.java2s;
/*-//w  w  w .ja  v a2 s  .c o m
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2010 Oracle.  All rights reserved.
 *
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Unmarshall the next four bytes which hold an unsigned int into a long.
     */
    public static long readUnsignedInt(ByteBuffer buf) {
        long ret = (buf.get() & 0xFFL) << 0;
        ret += (buf.get() & 0xFFL) << 8;
        ret += (buf.get() & 0xFFL) << 16;
        ret += (buf.get() & 0xFFL) << 24;
        return ret;
    }
}

Related

  1. readIntoBuffer(SocketChannel channel, ByteBuffer buf, int sleepMsecs)
  2. readInts(final ByteBuffer bb, final int length)
  3. readInts4(final ByteBuffer buffer, final int[] array, final int count)
  4. readUnsigned(ByteBuffer in, int size)
  5. readUnsignedByte(ByteBuffer buffer)
  6. readUnsignedInt(ByteBuffer buffer)
  7. readUnsignedInt(ByteBuffer buffer, int index)
  8. readUnsignedInt(ByteBuffer byteBuf)
  9. readUnsignedMedium(ByteBuffer buf)