|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
com.kirkwarez.kirkpack.io.EndianInputStream
This stream behaves about exactly as DataInputStream
, it reads
primitive and some non-primitive data types from the underlying stream. The reason it
doesn't extend DataInputStream
is because all methods in that class are
declared final. This class does implement DataInput
.
The big difference is that this class takes a byte order on construction, and guarantees that the primitives will be constructed from bytes read using that byte order.
The non-primitive methods from this class are delegated to a
DataInputStream
, however the readLine
method shouldn't be
used, because the DataInputStream
method is deprecated, even though it's
implementing an interface... As of yet there is no replacement for this method, but
you shouldn't be using it anyways since lines are pretty rare in byte streams...
Field Summary | |
static int |
BIG_ENDIAN
The Big Endian byte order. |
protected int |
byteorder
The byte order used by this stream. |
protected DataInputStream |
cache
The InputStream that FilterInputStream parent class
delegates to, only uncast. |
static int |
LITTLE_ENDIAN
The Little Endian byte order. |
Fields inherited from class java.io.FilterInputStream |
in |
Fields inherited from class java.io.InputStream |
|
Constructor Summary | |
EndianInputStream(InputStream input,
int byteorder)
Constucts a new stream that delivers primitives read using the given byte order. |
Method Summary | |
int |
getByteorder()
Returns the byte order. |
boolean |
readBoolean()
See the general contract of DataInput . |
byte |
readByte()
See the general contract of DataInput . |
char |
readChar()
See the general contract of DataInput . |
double |
readDouble()
See the general contract of DataInput . |
float |
readFloat()
See the general contract of DataInput . |
void |
readFully(byte[] buffer)
See the general contract of DataInput . |
void |
readFully(byte[] buffer,
int offset,
int length)
See the general contract of DataInput . |
byte[] |
readFully(int length)
Creates a byte array wih the given length, fills it in with bytes from the stream completely and returns it. |
int |
readInt()
See the general contract of DataInput . |
String |
readLine()
Deprecated. DataInputStream uses a deprecated way. However, using a
BufferedReader internally isn't going to work, since it'll mess up
the stream (it buffers), and will require two objects each method call, since you
can't close it. Nobody should actually use this method, because it simply doesn't
make sense. A line in a byte stream?* A null terminated string I can understand...
but a line? I mean, strings are usually just stored as either null-terminted
strings or with some length attribute. Just read that out and bother with the
lines later. |
long |
readLong()
See the general contract of DataInput . |
short |
readShort()
See the general contract of DataInput . |
int |
readUnsignedByte()
See the general contract of DataInput . |
long |
readUnsignedInt()
Reads 4 bytes and turns them into an unsigned int. |
int |
readUnsignedShort()
See the general contract of DataInput . |
String |
readUTF()
See the general contract of DataInput . |
protected void |
setByteorder(int byteorder)
Sets the byte order. |
int |
skipBytes(int amount)
See the general contract of DataInput . |
Methods inherited from class java.io.FilterInputStream |
available, close, mark, markSupported, read, read, read, reset, skip |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected DataInputStream cache
InputStream
that FilterInputStream
parent class
delegates to, only uncast.
protected int byteorder
public static final int BIG_ENDIAN
public static final int LITTLE_ENDIAN
Constructor Detail |
public EndianInputStream(InputStream input, int byteorder)
input
- The stream to read from.byteorder
- The byte order. This is either BIG_ENDIAN or LITTLE_ENDIAN.Method Detail |
public byte[] readFully(int length) throws IOException
length
- The size of the buffer where the data is to be read into.
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.public void readFully(byte[] buffer) throws IOException
DataInput
.
readFully
in interface DataInput
buffer
- The buffer where the data is read into.
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readFully(byte[])
public void readFully(byte[] buffer, int offset, int length) throws IOException
DataInput
.
readFully
in interface DataInput
buffer
- The buffer where the data is read into.offset
- The starting offset of the data in the array.length
- The number of bytes read.
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readFully(byte[], int, int)
public int skipBytes(int amount) throws IOException
DataInput
.
skipBytes
in interface DataInput
amount
- The number of bytes to be skipped.
IOException
- When I/O errors happen.DataInput.skipBytes(int)
public boolean readBoolean() throws IOException
DataInput
.
readBoolean
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readBoolean()
public byte readByte() throws IOException
DataInput
.
readByte
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readByte()
public int readUnsignedByte() throws IOException
DataInput
.
readUnsignedByte
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readUnsignedByte()
public short readShort() throws IOException
DataInput
.
readShort
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readShort()
public int readUnsignedShort() throws IOException
DataInput
.
readUnsignedShort
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readUnsignedShort()
public char readChar() throws IOException
DataInput
.
readChar
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readChar()
public int readInt() throws IOException
DataInput
.
readInt
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readInt()
public long readUnsignedInt() throws IOException
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.public long readLong() throws IOException
DataInput
.
readLong
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readLong()
public float readFloat() throws IOException
DataInput
.
readFloat
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readFloat()
,
Float.intBitsToFloat(int)
public double readDouble() throws IOException
DataInput
.
readDouble
in interface DataInput
EOFException
- When the end of the steam is encountered.
IOException
- When I/O errors happen.DataInput.readDouble()
,
Double.longBitsToDouble(long)
public String readLine() throws IOException
DataInputStream
uses a deprecated way. However, using a
BufferedReader
internally isn't going to work, since it'll mess up
the stream (it buffers), and will require two objects each method call, since you
can't close it. Nobody should actually use this method, because it simply doesn't
make sense. A line in a byte stream?* A null terminated string I can understand...
but a line? I mean, strings are usually just stored as either null-terminted
strings or with some length attribute. Just read that out and bother with the
lines later.
DataInput
.
readLine
in interface DataInput
IOException
- When I/O errors occur.BufferedReader.readLine()
,
DataInputStream.readLine()
,
DataInput.readLine()
public String readUTF() throws IOException
DataInput
.
readUTF
in interface DataInput
EOFException
- When the end of the stream is encountered.
IOException
- When IO errors happen.
UTFDataFormatException
- When the bytes do not represent a valid UTF-8
encoding of a string.DataInput.readUTF()
public int getByteorder()
protected void setByteorder(int byteorder)
byteorder
- The byte order used by this stream.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |