final class InputStreamSource extends java.lang.Object implements SequentialSource
Modifier and Type | Field and Description |
---|---|
private java.io.PushbackInputStream |
input |
private int |
position |
Constructor and Description |
---|
InputStreamSource(java.io.InputStream input)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
long |
getPosition()
Returns offset of next byte to be returned by a read method.
|
boolean |
isEOF()
Returns true if the end of the data source has been reached.
|
int |
peek()
This will peek at the next byte.
|
int |
read()
Read a single byte of data.
|
int |
read(byte[] b)
Read a buffer of data.
|
int |
read(byte[] b,
int offset,
int length)
Read a buffer of data.
|
byte[] |
readFully(int length)
Reads a given number of bytes in its entirety.
|
void |
unread(byte[] bytes)
Unreads an array of bytes.
|
void |
unread(byte[] bytes,
int start,
int len)
Unreads a portion of an array of bytes.
|
void |
unread(int b)
Unreads a single byte.
|
InputStreamSource(java.io.InputStream input)
input
- The input stream to wrap.public int read() throws java.io.IOException
SequentialSource
read
in interface SequentialSource
java.io.IOException
- If there is an error while reading the data.public int read(byte[] b) throws java.io.IOException
SequentialSource
read
in interface SequentialSource
b
- The buffer to write the data to.java.io.IOException
- If there was an error while reading the data.public int read(byte[] b, int offset, int length) throws java.io.IOException
SequentialSource
read
in interface SequentialSource
b
- The buffer to write the data to.offset
- Offset into the buffer to start writing.length
- The amount of data to attempt to read.java.io.IOException
- If there was an error while reading the data.public long getPosition() throws java.io.IOException
SequentialSource
getPosition
in interface SequentialSource
SequentialSource.read()
(if no more
bytes are left it returns a value >= length of source).java.io.IOException
- If there was an error while reading the data.public int peek() throws java.io.IOException
SequentialSource
peek
in interface SequentialSource
java.io.IOException
- If there is an error reading the next byte.public void unread(int b) throws java.io.IOException
SequentialSource
unread
in interface SequentialSource
b
- byte array to push backjava.io.IOException
- if there is an error while unreadingpublic void unread(byte[] bytes) throws java.io.IOException
SequentialSource
unread
in interface SequentialSource
bytes
- byte array to be unreadjava.io.IOException
- if there is an error while unreadingpublic void unread(byte[] bytes, int start, int len) throws java.io.IOException
SequentialSource
unread
in interface SequentialSource
bytes
- byte array to be unreadstart
- start indexlen
- number of bytes to be unreadjava.io.IOException
- if there is an error while unreadingpublic byte[] readFully(int length) throws java.io.IOException
SequentialSource
readFully
in interface SequentialSource
length
- the number of bytes to be readjava.io.IOException
- if an I/O error occurs while reading datapublic boolean isEOF() throws java.io.IOException
SequentialSource
isEOF
in interface SequentialSource
java.io.IOException
- If there is an error reading the next byte.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException