final class LEDataInputStream
extends java.io.InputStream
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The byte array containing the bytes to read.
|
(package private) java.io.InputStream |
in |
protected int |
pos
The current position within the byte array
buf. |
(package private) int |
position |
| Constructor and Description |
|---|
LEDataInputStream(java.io.InputStream input) |
LEDataInputStream(java.io.InputStream input,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
int |
available()
Answers how many bytes are available for reading without blocking
|
void |
close() |
int |
getPosition()
Answer how many bytes were read.
|
int |
read()
Answer the next byte of the input stream.
|
int |
read(byte[] b,
int off,
int len)
Don't imitate the JDK behaviour of reading a random number
of bytes when you can actually read them all.
|
private int |
readData(byte[] buffer,
int offset,
int length)
Reads at most
length bytes from this LEDataInputStream and
stores them in byte array buffer starting at offset. |
int |
readInt()
Answer an integer comprised of the next
four bytes of the input stream.
|
short |
readShort()
Answer a short comprised of the next
two bytes of the input stream.
|
void |
unread(byte[] b)
Push back the entire content of the given buffer
b. |
int position
java.io.InputStream in
protected byte[] buf
protected int pos
buf. A value
equal to buf.length indicates no bytes available. A value of
0 indicates the buffer is full.public LEDataInputStream(java.io.InputStream input)
public LEDataInputStream(java.io.InputStream input,
int bufferSize)
public void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic int getPosition()
public int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionprivate int readData(byte[] buffer,
int offset,
int length)
throws java.io.IOException
length bytes from this LEDataInputStream and
stores them in byte array buffer starting at offset.
Answer the number of bytes actually read or -1 if no bytes were read and
end of stream was encountered. This implementation reads bytes from
the pushback buffer first, then the target stream if more bytes are required
to satisfy count.
buffer - the byte array in which to store the read bytes.offset - the offset in buffer to store the read bytes.length - the maximum number of bytes to store in buffer.java.io.IOException - if an IOException occurs.public int readInt()
throws java.io.IOException
java.io.IOExceptionpublic short readShort()
throws java.io.IOException
java.io.IOExceptionpublic void unread(byte[] b)
throws java.io.IOException
b.
The bytes are pushed so that they would be read back b[0], b[1], etc.
If the push back buffer cannot handle the bytes copied from b,
an IOException will be thrown and no byte will be pushed back.
b - the byte array containing bytes to push back into the streamjava.io.IOException - if the pushback buffer is too small