Here you can find the source of readUnsignedInt(InputStream is)
Parameter | Description |
---|---|
is | The input stream to read from. |
public static long readUnsignedInt(InputStream is) throws IOException
//package com.java2s; // See LICENSE.txt for license information import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.ReadableByteChannel; public class Main { /**// ww w . j a va2 s .co m * Reads an unsigned integer (32 bit) from specified input stream. * @param is The input stream to read from. * @return The unsigned integer value from the stream. */ public static long readUnsignedInt(InputStream is) throws IOException { return (long) readInt(is) & 0xffffffffL; } /** * Reads an integer (32 bit) from the specified byte channel. * @param channel The {@link ReadableByteChannel} to read from. * @return The integer value from the channel. */ public static int readInt(ReadableByteChannel channel) throws IOException { ByteBuffer bb4 = getByteBuffer(4); bb4.position(0); for (int cnt = 0; cnt < 4;) { int n = channel.read(bb4); if (n < 0) { throw new IOException("End of stream"); } cnt += n; } bb4.position(0); return bb4.getInt(); } /** * Reads an integer (32 bit) from specified input stream. * @param is The input stream to read from. * @return The integer value from the stream. */ public static int readInt(InputStream is) throws IOException { ByteBuffer bb4 = getByteBuffer(4); for (int cnt = 0; cnt < 4;) { int n = is.read(bb4.array(), cnt, bb4.array().length - cnt); if (n < 0) { throw new IOException("End of stream"); } cnt += n; } bb4.position(0); return bb4.getInt(); } /** Returns a fully initialized empty {@link ByteBuffer} in little endian order. */ public static ByteBuffer getByteBuffer(int size) { return ByteBuffer.allocate(Math.max(0, size)).order(ByteOrder.LITTLE_ENDIAN); } /** Returns a {@link ByteBuffer} based on {@code buffer} in little endian order. */ public static ByteBuffer getByteBuffer(byte[] buffer) { if (buffer == null) { buffer = new byte[0]; } return ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN); } }