Java ByteBuffer to Int getUnsignedInt(ByteBuffer buffer)

Here you can find the source of getUnsignedInt(ByteBuffer buffer)

Description

Read an unsigned integer from the current position in the buffer, incrementing the position by 4 bytes

License

Open Source License

Return

The integer read, as a long to avoid signedness

Declaration

public static long getUnsignedInt(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

import java.util.*;

public class Main {
    /**/*from   w w w.j a v  a2  s.  c  om*/
     * Read an unsigned integer from the current position in the buffer,
     * incrementing the position by 4 bytes
     *
     * @return The integer read, as a long to avoid signedness
     */
    public static long getUnsignedInt(ByteBuffer buffer) {
        return buffer.getInt() & 0xffffffffL;
    }

    /**
     * Read an unsigned integer from the given position without modifying
     * the buffers position
     *
     * @param index the index from which to read the integer
     * @return The integer read, as a long to avoid signedness
     */
    public static long getUnsignedInt(ByteBuffer buffer, int index) {
        return buffer.getInt(index) & 0xffffffffL;
    }

    public static int getInt(Properties props, String name) {
        if (props.containsKey(name)) {
            return getInt(props, name, -1);
        }
        throw new IllegalArgumentException("Missing required property '" + name + "'");
    }

    public static int getInt(Properties props, String name, int defaultValue) {
        return getIntInRange(props, name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE);
    }

    public static int getIntInRange(Properties props, String name, int defaultValue, int min, int max) {
        int v = defaultValue;
        if (props.containsKey(name)) {
            v = Integer.valueOf(props.getProperty(name));
        }
        if (v >= min && v <= max) {
            return v;
        }
        throw new IllegalArgumentException(name + " has value " + v + " which is not in the range");
    }
}

Related

  1. getUnsignedByte(ByteBuffer bb)
  2. getUnsignedByte(ByteBuffer buffer)
  3. getUnsignedInt(ByteBuffer bb)
  4. getUnsignedInt(ByteBuffer buffer)
  5. getUnsignedInt(ByteBuffer buffer)
  6. getUnsignedInt16LSBMSB(ByteBuffer byteBuffer)
  7. getUnsignedLong(ByteBuffer buf)
  8. getUnsignedLong(final ByteBuffer src)