public class BitInput
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected ByteInput |
input
The underlying byte input.
|
Constructor and Description |
---|
BitInput(ByteInput input)
Creates a new instance built on top of the specified byte input.
|
Modifier and Type | Method and Description |
---|---|
int |
align(int length)
Aligns to given number of bytes.
|
long |
getCount()
Returns the number of bytes read from the underlying byte input so far.
|
protected boolean |
isNotNull()
Reads a boolean flag for nullability of the subsequent object.
|
protected boolean |
isNull()
Reads a boolean flag for nullability of the subsequent object.
|
static BitInput |
newInstance(java.nio.ByteBuffer source)
Creates a new instance consuming bytes from specified byte source.
|
static BitInput |
newInstance(java.io.InputStream source)
Creates a new instance consuming bytes from given byte source.
|
boolean |
readBoolean()
Reads a 1-bit boolean value.
|
protected void |
readBytes(int range,
byte[] value,
int offset,
int length)
Reads a sequence of bytes.
|
byte[] |
readBytes(int scale,
int range)
Reads an array of bytes.
|
int |
readBytes(int scale,
int range,
byte[] value,
int offset)
Reads a sequence of bytes.
|
double |
readDouble()
Reads a double value.
|
float |
readFloat()
Reads a float value.
|
int |
readInt(int length)
Reads a signed int value.
|
long |
readLong(int length)
Reads a signed long value.
|
java.lang.String |
readString(java.lang.String charsetName)
Reads a string.
|
protected int |
readUnsignedByte(int length)
Reads an unsigned byte value.
|
int |
readUnsignedInt(int length)
Reads an unsigned int value.
|
long |
readUnsignedLong(int length)
Reads an unsigned long value.
|
protected int |
readUnsignedShort(int length)
Reads an unsigned short value.
|
java.lang.String |
readUsAsciiString()
Reads a
US-ASCII encoded string. |
protected final ByteInput input
public BitInput(ByteInput input)
input
- the byte input on which this bit input is built.java.lang.NullPointerException
- if the specified input
is
null
.public static BitInput newInstance(java.io.InputStream source)
source
- the byte sourcejava.lang.NullPointerException
- if source
is null
.public static BitInput newInstance(java.nio.ByteBuffer source)
source
- the byte source.protected int readUnsignedByte(int length) throws java.io.IOException
length
- the number of bits for the value; between 0
(exclusive) and 8
(inclusive).java.lang.IllegalArgumentException
- if length
is not valid.java.io.IOException
- if an I/O error occurs.public boolean readBoolean() throws java.io.IOException
true
for 0b1
and
false
for 0b0
.java.io.IOException
- if an I/O error occurs.protected boolean isNull() throws java.io.IOException
true
if the subsequent object is null
or
false
if the subsequent object is not null
.java.io.IOException
- if an I/O error occurs.isNotNull()
protected boolean isNotNull() throws java.io.IOException
true
if the subsequent object is not null
or
false
if the subsequent object is null
.java.io.IOException
- if an I/O error occurs.isNull()
protected int readUnsignedShort(int length) throws java.io.IOException
length
- the number of bits for the value; between 0 (exclusive) and
16 (inclusive).java.lang.IllegalArgumentException
- if length
is not valid.java.io.IOException
- if an I/O error occurs.public int readUnsignedInt(int length) throws java.io.IOException
length
- the number of bits for the value; between 1 (inclusive) and
32 (exclusive).java.lang.IllegalArgumentException
- if length
is not valid.java.io.IOException
- if an I/O error occurspublic int readInt(int length) throws java.io.IOException
length
- the number of bits for the value; between 1 (exclusive) and
32 (inclusive).java.lang.IllegalArgumentException
- if length
is not valid.java.io.IOException
- if an I/O error occurs.public float readFloat() throws java.io.IOException
java.io.IOException
- if an I/O error occursFloat.intBitsToFloat(int)
public long readUnsignedLong(int length) throws java.io.IOException
length
- the number of bits for the value; between 1 (inclusive) and
64 (exclusive).java.lang.IllegalArgumentException
- if length
is not validjava.io.IOException
- if an I/O error occurspublic long readLong(int length) throws java.io.IOException
length
- the number of bits for the value; between 1 (exclusive) and
64 (inclusive).java.lang.IllegalArgumentException
- if length
is not validjava.io.IOException
- if an I/O error occurs.public final double readDouble() throws java.io.IOException
java.io.IOException
- if an I/O error occurs.Double.longBitsToDouble(long)
protected void readBytes(int range, byte[] value, int offset, int length) throws java.io.IOException
range
- the number of valid bits in each byte; between 0 (exclusive)
and 8 (inclusive).value
- the array to which each byte are stored.offset
- starting offset in the array.length
- the number of bytes to readjava.io.IOException
- if an I/O error occurs.public int readBytes(int scale, int range, byte[] value, int offset) throws java.io.IOException
scale
- the number of bits required for calculating the number of
bytes to read; between 0 (exclusive) and 16 (inclusive).range
- the number of valid bits in each byte; between 0 (exclusive)
and 8 (inclusive).value
- the array to which each byte are storedoffset
- starting offset in the arrayreadUnsignedShort(scale)
java.io.IOException
- if an I/O error occurs.readBytes(int, byte[], int, int)
public byte[] readBytes(int scale, int range) throws java.io.IOException
scale
- the number of bits for calculating the number of bytes to
read; between 0 (exclusive) and 16 (inclusive).range
- the number of valid bits in each byte; between 0 (exclusive)
and 8 (inclusive).java.io.IOException
- if an I/O error occurs.readBytes(int, byte[], int, int)
public java.lang.String readString(java.lang.String charsetName) throws java.io.IOException
readBytes(int, int)
with scale
of 16
and
range
of 8
and returns the output string created by
String.String(byte[], java.lang.String)
with the byte array and
given charsetName
.charsetName
- the character set name to encode output string.java.lang.NullPointerException
- if charsetName
is null
.java.io.IOException
- if an I/O error occurs.readBytes(int, int)
,
String.String(byte[], java.lang.String)
public java.lang.String readUsAsciiString() throws java.io.IOException
US-ASCII
encoded string. This method reads a byte array
via readBytes(int, int)
with scale
of 16
and
range
of 7
and returns the output string created by
String.String(byte[], java.lang.String)
with the byte array and
US-ASCII
.US-ASCII
encoded string.java.io.IOException
- if an I/O error occurs.readBytes(int, int)
,
String.String(byte[], java.lang.String)
public int align(int length) throws java.io.IOException
length
- the number of bytes to align; between 0 (exclusive) and
32767 (inclusive).java.lang.IllegalArgumentException
- if length
is not valid.java.io.IOException
- if an I/O error occurs.public long getCount()
Copyright © 2011-2014. All Rights Reserved.