|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
maspack.util.BinaryInputStream
public class BinaryInputStream
A data input stream class that can be set to convert its input from little-endian to big-endian. Characters can also be specified to be either word or byte length. The code is a mash-up of Elliotte Rusty Harold's LittleEndianInputStream, Java source code, and Antonio Sanchez's BinaryStreamReader.
Field Summary | |
---|---|
static int |
BIG_ENDIAN
|
static int |
BYTE_CHAR
|
static int |
LITTLE_ENDIAN
|
Constructor Summary | |
---|---|
BinaryInputStream(java.io.InputStream in)
Creates a new BinaryInputStream from an input stream. |
|
BinaryInputStream(java.io.InputStream in,
int flags)
Creates a new BinaryInputStream from an input stream and prescribed set of flag values. |
Method Summary | |
---|---|
int |
getByteCount()
Returns the total number of bytes that have been read by this stream. |
int |
getFlags()
Gets the flags for this stream. |
boolean |
isLittleEndian()
Returns true if this stream converts its input from
little-endian where appropriate. |
boolean |
readBoolean()
Reads a boolean value from this stream. |
byte |
readByte()
Reads a byte value from this stream. |
char |
readChar()
Reads a character value from this stream. |
double |
readDouble()
Reads a double value from this stream. |
float |
readFloat()
Reads a float value from this stream. |
void |
readFully(byte[] b)
Reads an array of bytes from this stream. |
void |
readFully(byte[] b,
int off,
int len)
Reads len bytes from an input stream and stores them in
buf starting at off . |
int |
readInt()
Reads an integer value from this stream. |
long |
readLong()
Reads a long value from this stream. |
short |
readShort()
Reads a short value from this stream. |
int |
readUnsignedByte()
Reads an unsigned byte value from this stream. |
int |
readUnsignedShort()
Reads an unsigned short value from this stream. |
java.lang.String |
readUTF()
Reads a UTF-8 string from this stream. |
void |
setByteChar(boolean bytechar)
Sets whether or not this stream uses byte-length characters as opposed to 2-byte word characters. |
void |
setFlags(int flags)
Sets the flags for this stream. |
void |
setLittleEndian(boolean little)
Sets whether or not this stream converts its input from little-endian. |
int |
skipBytes(int n)
Skips over n bytes from this stream. |
boolean |
usesByteChar()
Returns true if this stream uses byte-length characters as
opposed to 2-byte word characters. |
Methods inherited from class java.io.FilterInputStream |
---|
available, close, mark, markSupported, read, read, read, reset, skip |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BIG_ENDIAN
public static final int LITTLE_ENDIAN
public static final int BYTE_CHAR
Constructor Detail |
---|
public BinaryInputStream(java.io.InputStream in)
in
- underlying input streampublic BinaryInputStream(java.io.InputStream in, int flags)
in
- underlying input streamflags
- flag valuesMethod Detail |
---|
public void setFlags(int flags)
flags
- new flag valuespublic int getFlags()
public boolean isLittleEndian()
true
if this stream converts its input from
little-endian where appropriate.
true
if this stream converts from little-endianpublic void setLittleEndian(boolean little)
little
- if true
, enables little-endian conversion.public boolean usesByteChar()
true
if this stream uses byte-length characters as
opposed to 2-byte word characters.
true
if this stream uses byte-length characterspublic void setByteChar(boolean bytechar)
bytechar
- if true
, enables byte-length characters.public final void readFully(byte[] b) throws java.io.IOException
b
- array in which to store the bytes
java.io.IOException
public final void readFully(byte[] b, int off, int len) throws java.io.IOException
len
bytes from an input stream and stores them in
buf
starting at off
.
b
- array in which to store the bytesoff
- starting offset for storing byteslen
- number of bytes to read
java.io.IOException
public final int skipBytes(int n) throws java.io.IOException
n
bytes from this stream.
n
- number of bytes to skip
java.io.IOException
public final boolean readBoolean() throws java.io.IOException
java.io.IOException
public final byte readByte() throws java.io.IOException
java.io.IOException
public final int readUnsignedByte() throws java.io.IOException
java.io.IOException
public final short readShort() throws java.io.IOException
isLittleEndian()
returns
true
, then the byte order is switched from
little-endian to big-endian.
java.io.IOException
public final int readUnsignedShort() throws java.io.IOException
isLittleEndian()
returns true
, then the byte order is switched from
little-endian to big-endian.
java.io.IOException
public final char readChar() throws java.io.IOException
usesByteChar()
returns
true
or false
. In the latter case, if isLittleEndian()
returns true
, then the byte order is
switched from little-endian to big-endian.
java.io.IOException
public final int readInt() throws java.io.IOException
isLittleEndian()
returns true
, then the byte order is switched from
little-endian to big-endian.
java.io.IOException
public final long readLong() throws java.io.IOException
isLittleEndian()
returns true
, then the byte order is switched from
little-endian to big-endian.
java.io.IOException
public final float readFloat() throws java.io.IOException
isLittleEndian()
returns true
, then the byte order is switched from
little-endian to big-endian.
java.io.IOException
public final double readDouble() throws java.io.IOException
isLittleEndian()
returns true
, then the byte order is switched from
little-endian to big-endian.
java.io.IOException
public final java.lang.String readUTF() throws java.io.IOException
java.io.IOException
public int getByteCount()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |