Package io.permazen.util
Class ByteData.Reader
java.lang.Object
java.io.InputStream
java.io.ByteArrayInputStream
io.permazen.util.ByteData.Reader
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing class:
- ByteData
Reads out the data from an underlying
ByteData
instance.
Instances are thread safe and fully support InputStream.available()
and mark/reset.
-
Field Summary
Fields inherited from class java.io.ByteArrayInputStream
buf, count, mark, pos
-
Method Summary
Modifier and TypeMethodDescriptionObtain aByteData
instance containing all of the data read not yet read from this instance.Obtain aByteData
instance containing all of the data read from this instance so far.Obtain the originalByteData
instance from which this reader was created.int
Get the current offset into the underlying data.int
peek()
Peek at the next byte.int
read
(byte[] b) int
readByte()
Read the next byte as an unsigned value.readBytes
(int len) Read out the specified number of bytes.byte[]
readNBytes
(int len) Read out all remaining bytes.int
remain()
Get the number of bytes remaining.void
skipNBytes
(long n) void
unread()
Unread the previously read byte.void
unread
(int len) Unread the specified number of previously read bytes.Methods inherited from class java.io.ByteArrayInputStream
available, close, mark, markSupported, read, read, readAllBytes, readNBytes, reset, skip, transferTo
Methods inherited from class java.io.InputStream
nullInputStream
-
Method Details
-
read
public int read(byte[] b) - Overrides:
read
in classInputStream
-
readNBytes
public byte[] readNBytes(int len) - Overrides:
readNBytes
in classInputStream
-
skipNBytes
public void skipNBytes(long n) - Overrides:
skipNBytes
in classInputStream
-
peek
public int peek()Peek at the next byte.This does not change the current read offset.
- Returns:
- next byte (0-255)
- Throws:
IndexOutOfBoundsException
- if there are no more bytes
-
readByte
public int readByte()Read the next byte as an unsigned value.- Returns:
- next byte (0-255)
- Throws:
IndexOutOfBoundsException
- if there are no more bytes
-
unread
public void unread()Unread the previously read byte.Equivalent to
unread(1)
.- Throws:
IndexOutOfBoundsException
- if zero bytes have been read
-
unread
public void unread(int len) Unread the specified number of previously read bytes.Upon return this instance's current offset will be decremented by
len
bytes.- Parameters:
len
- the number of bytes to unread- Throws:
IndexOutOfBoundsException
- iflen
is negative or greater than the number of bytes that have been read
-
remain
public int remain()Get the number of bytes remaining.- Returns:
- bytes remaining
-
getOffset
public int getOffset()Get the current offset into the underlying data.- Returns:
- current offset
-
readBytes
Read out the specified number of bytes.- Parameters:
len
- number of bytes to read- Returns:
- the next
len
bytes - Throws:
IndexOutOfBoundsException
- iflen
is negative or greater than the number of bytes remaining
-
dataReadSoFar
Obtain aByteData
instance containing all of the data read from this instance so far.This does not change the current read offset.
- Returns:
- all data read so far
-
dataNotYetRead
Obtain aByteData
instance containing all of the data read not yet read from this instance.This does not change the current read offset.
- Returns:
- all unread data
-
readRemaining
Read out all remaining bytes.Upon return this instance's current offset will be positioned at the end of the data.
- Returns:
- bytes read
-
getByteData
Obtain the originalByteData
instance from which this reader was created.This does not change the current read offset.
- Returns:
- the entire underlying data
-