public interface ExtractorInput
Extractor
.Modifier and Type | Method and Description |
---|---|
void |
advancePeekPosition(int length)
Advances the peek position by
length bytes. |
boolean |
advancePeekPosition(int length,
boolean allowEndOfInput)
Advances the peek position by
length bytes. |
long |
getLength()
Returns the length of the source stream, or
C.LENGTH_UNBOUNDED if it is unknown. |
long |
getPeekPosition()
Returns the current peek position (byte offset) in the stream.
|
long |
getPosition()
Returns the current read position (byte offset) in the stream.
|
void |
peekFully(byte[] target,
int offset,
int length)
Peeks
length bytes from the peek position, writing them into target at index
offset . |
boolean |
peekFully(byte[] target,
int offset,
int length,
boolean allowEndOfInput)
Peeks
length bytes from the peek position, writing them into target at index
offset . |
int |
read(byte[] target,
int offset,
int length)
Reads up to
length bytes from the input and resets the peek position. |
void |
readFully(byte[] target,
int offset,
int length)
Equivalent to
readFully(target, offset, length, false) . |
boolean |
readFully(byte[] target,
int offset,
int length,
boolean allowEndOfInput)
Like
read(byte[], int, int) , but reads the requested length in full. |
void |
resetPeekPosition()
Resets the peek position to equal the current read position.
|
int |
skip(int length)
Like
read(byte[], int, int) , except the data is skipped instead of read. |
void |
skipFully(int length)
Like
readFully(byte[], int, int) , except the data is skipped instead of read. |
boolean |
skipFully(int length,
boolean allowEndOfInput)
Like
readFully(byte[], int, int, boolean) , except the data is skipped instead of read. |
int read(byte[] target, int offset, int length) throws IOException, InterruptedException
length
bytes from the input and resets the peek position.
This method blocks until at least one byte of data can be read, the end of the input is detected, or an exception is thrown.
target
- A target array into which data should be written.offset
- The offset into the target array at which to write.length
- The maximum number of bytes to read from the input.C.RESULT_END_OF_INPUT
if the input has ended.IOException
- If an error occurs reading from the input.InterruptedException
- If the thread has been interrupted.boolean readFully(byte[] target, int offset, int length, boolean allowEndOfInput) throws IOException, InterruptedException
read(byte[], int, int)
, but reads the requested length
in full.
If the end of the input is found having read no data, then behavior is dependent on
allowEndOfInput
. If allowEndOfInput == true
then false
is returned.
Otherwise an EOFException
is thrown.
Encountering the end of input having partially satisfied the read is always considered an
error, and will result in an EOFException
being thrown.
target
- A target array into which data should be written.offset
- The offset into the target array at which to write.length
- The number of bytes to read from the input.allowEndOfInput
- True if encountering the end of the input having read no data is
allowed, and should result in false
being returned. False if it should be
considered an error, causing an EOFException
to be thrown.EOFException
- If the end of input was encountered having partially satisfied the read
(i.e. having read at least one byte, but fewer than length
), or if no bytes were
read and allowEndOfInput
is false.IOException
- If an error occurs reading from the input.InterruptedException
- If the thread has been interrupted.void readFully(byte[] target, int offset, int length) throws IOException, InterruptedException
readFully(target, offset, length, false)
.target
- A target array into which data should be written.offset
- The offset into the target array at which to write.length
- The number of bytes to read from the input.EOFException
- If the end of input was encountered.IOException
- If an error occurs reading from the input.InterruptedException
- If the thread is interrupted.int skip(int length) throws IOException, InterruptedException
read(byte[], int, int)
, except the data is skipped instead of read.length
- The maximum number of bytes to skip from the input.C.RESULT_END_OF_INPUT
if the input has ended.IOException
- If an error occurs reading from the input.InterruptedException
- If the thread has been interrupted.boolean skipFully(int length, boolean allowEndOfInput) throws IOException, InterruptedException
readFully(byte[], int, int, boolean)
, except the data is skipped instead of read.length
- The number of bytes to skip from the input.allowEndOfInput
- True if encountering the end of the input having skipped no data is
allowed, and should result in false
being returned. False if it should be
considered an error, causing an EOFException
to be thrown.EOFException
- If the end of input was encountered having partially satisfied the skip
(i.e. having skipped at least one byte, but fewer than length
), or if no bytes were
skipped and allowEndOfInput
is false.IOException
- If an error occurs reading from the input.InterruptedException
- If the thread has been interrupted.void skipFully(int length) throws IOException, InterruptedException
readFully(byte[], int, int)
, except the data is skipped instead of read.
Encountering the end of input is always considered an error, and will result in an
EOFException
being thrown.
length
- The number of bytes to skip from the input.EOFException
- If the end of input was encountered.IOException
- If an error occurs reading from the input.InterruptedException
- If the thread is interrupted.boolean peekFully(byte[] target, int offset, int length, boolean allowEndOfInput) throws IOException, InterruptedException
length
bytes from the peek position, writing them into target
at index
offset
. The current read position is left unchanged.
If the end of the input is found having peeked no data, then behavior is dependent on
allowEndOfInput
. If allowEndOfInput == true
then false
is returned.
Otherwise an EOFException
is thrown.
Calling resetPeekPosition()
resets the peek position to equal the current read
position, so the caller can peek the same data again. Reading and skipping also reset the peek
position.
target
- A target array into which data should be written.offset
- The offset into the target array at which to write.length
- The number of bytes to peek from the input.allowEndOfInput
- True if encountering the end of the input having peeked no data is
allowed, and should result in false
being returned. False if it should be
considered an error, causing an EOFException
to be thrown.EOFException
- If the end of input was encountered having partially satisfied the peek
(i.e. having peeked at least one byte, but fewer than length
), or if no bytes were
peeked and allowEndOfInput
is false.IOException
- If an error occurs peeking from the input.InterruptedException
- If the thread is interrupted.void peekFully(byte[] target, int offset, int length) throws IOException, InterruptedException
length
bytes from the peek position, writing them into target
at index
offset
. The current read position is left unchanged.
Calling resetPeekPosition()
resets the peek position to equal the current read
position, so the caller can peek the same data again. Reading or skipping also resets the peek
position.
target
- A target array into which data should be written.offset
- The offset into the target array at which to write.length
- The number of bytes to peek from the input.EOFException
- If the end of input was encountered.IOException
- If an error occurs peeking from the input.InterruptedException
- If the thread is interrupted.boolean advancePeekPosition(int length, boolean allowEndOfInput) throws IOException, InterruptedException
length
bytes.
If the end of the input is encountered before advancing the peek position, then behavior is
dependent on allowEndOfInput
. If allowEndOfInput == true
then false
is
returned. Otherwise an EOFException
is thrown.
length
- The number of bytes by which to advance the peek position.allowEndOfInput
- True if encountering the end of the input before advancing is allowed,
and should result in false
being returned. False if it should be considered an
error, causing an EOFException
to be thrown.EOFException
- If the end of input was encountered having partially advanced (i.e. having
advanced by at least one byte, but fewer than length
), or if the end of input was
encountered before advancing and allowEndOfInput
is false.IOException
- If an error occurs advancing the peek position.InterruptedException
- If the thread is interrupted.void advancePeekPosition(int length) throws IOException, InterruptedException
length
bytes.length
- The number of bytes to peek from the input.EOFException
- If the end of input was encountered.IOException
- If an error occurs peeking from the input.InterruptedException
- If the thread is interrupted.void resetPeekPosition()
long getPeekPosition()
long getPosition()
long getLength()
C.LENGTH_UNBOUNDED
if it is unknown.C.LENGTH_UNBOUNDED
.