Here you can find the source of readUnsignedInt24(InputStream is)
Parameter | Description |
---|---|
is | The input stream to read from. |
public static int readUnsignedInt24(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; public class Main { /**/* w ww.jav a 2 s. c om*/ * Reads an unsigned 24 bit integer from specified input stream. * @param is The input stream to read from. * @return The unsigned 24 bit integer value from the stream. */ public static int readUnsignedInt24(InputStream is) throws IOException { ByteBuffer bb4 = getByteBuffer(4); for (int cnt = 0; cnt < 3;) { int n = is.read(bb4.array(), cnt, bb4.array().length - cnt - 1); if (n < 0) { throw new IOException("End of stream"); } cnt += n; } bb4.position(0); return bb4.getInt() & 0xffffff; } /** 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); } }