public final class BufferedInputPart extends BufferedInput
BufferedInput
for parsing of size-tagged packets.
The totalPosition
of the BufferedInputPart
is the same as the totalPosition
of the
underlying BufferedInput
, but the number of bytes available
in the BufferedInputPart
is limited by the length
specified in its constructor
or
in setInput
method.
Reading from this BufferedInputPart
does not
automatically advance position in the underlying input, but it does not stay fixed either. The position of
the underlying BufferedInput
is advanced at unspecified times.
Use syncInputPosition
method to advance it to the current position of
this BufferedInputPart
when needed.
buffer, EMPTY_BYTE_ARRAY, limit, markPosition, position, totalPositionBase
Constructor and Description |
---|
BufferedInputPart()
Creates
BufferedInputPart object that needs to be bound to a particular underlying input
by setInput method before use. |
BufferedInputPart(BufferedInput in,
long length)
Creates
BufferedInputPart object that is bound the part of the specified input and
is limited by the particular length. |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes that can be read without blocking.
|
protected void |
checkEncapsulatedLength(long length,
long min,
long max)
Validate encapsulated content length according to
specified bounds and stream limits.
|
void |
close()
Unbinds this
BufferedInputPart object from the underlying input with resetInput method. |
boolean |
hasAvailable()
Checks if more bytes can be read from this input.
|
boolean |
hasAvailable(int bytes)
Checks if the specified number of bytes can be read from this input.
|
int |
read(byte[] b,
int off,
int len) |
protected int |
readData()
This method is invoked when input methods need more bytes to read data.
|
void |
resetInput()
Unbinds this
BufferedInputPart object from the underlying input. |
void |
rewind(long n)
Rewinds specified number of bytes.
|
void |
setInput(BufferedInput in,
long length)
Binds this
BufferedInputPart object to the part of the specified input with
a limit by the particular length. |
long |
skip(long n) |
void |
syncInputPosition()
Updates underlying
BufferedInput position so that it corresponds to the position that this
BufferedInputPart was read to. |
checkEOB, checkRewind, mark, mark, mark, markSupported, needData, read, read, readBoolean, readByte, readByteArray, readChar, readCompactInt, readCompactLong, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readMarshalled, readMarshalled, readObject, readObject, readObject, readShort, readToByteBuffer, readToDataOutput, readToOutputStream, readUnsignedByte, readUnsignedShort, readUTF, readUTFBody, readUTFChar, readUTFString, reset, seek, skipBytes, throwEOFException, totalPosition, unmark
public BufferedInputPart()
BufferedInputPart
object that needs to be bound to a particular underlying input
by setInput
method before use.public BufferedInputPart(BufferedInput in, long length)
BufferedInputPart
object that is bound the part of the specified input and
is limited by the particular length. See setInput
method
for all preconditions.in
- the underlying input.length
- the length limit.NullPointerException
- if in
is null.IllegalStateException
- if the underlying input is not marked properly.public void setInput(BufferedInput in, long length)
BufferedInputPart
object to the part of the specified input with
a limit by the particular length. This method can be called multiple times
to reuse this instance by binding it differently. The underlying BufferedInput
this method was previously bound to is ignored by this method for a predictable
reuse behavior regardless of how the previous use of this instance has terminated.
The state of this BufferedInputPart
is completely reset as if it was created from scratch.
The underlying BufferedInput
has to be marked
before invocation of this method.
The behavior of this BufferedInputPart
is undefined if the underlying BufferedInput
is changed in any way directly by reading from it or otherwise changing its position or mark before
this BufferedInputPart
is disposed of or unbound
.
in
- the underlying input.length
- the length limit.NullPointerException
- if in
is null.IllegalStateException
- if the underlying input is not marked.public void syncInputPosition()
BufferedInput
position so that it corresponds to the position that this
BufferedInputPart
was read to. Unlike resetInput
method,
this BufferedInputPart
continues to be bound.NullPointerException
- if this BufferedInputPart
is not bound.public void resetInput()
BufferedInputPart
object from the underlying input. This method
does nothing if this instance is not currently bound. This method does not
synchronize the underlying BufferedInput
position with
syncInputPosition
method.public void close()
BufferedInputPart
object from the underlying input with resetInput
method.
The underlying BufferedInput
is not closed.close
in interface Closeable
close
in interface ObjectInput
close
in interface AutoCloseable
close
in class InputStream
public boolean hasAvailable() throws IOException
false
when this object is not bound.hasAvailable
in class BufferedInput
true
if more bytes can be read from this input.IOException
- if an I/O error occurs.public boolean hasAvailable(int bytes) throws IOException
available
() >= bytes
check.
This method returns bytes <= 0
when this object is not bound.hasAvailable
in class BufferedInput
bytes
- the number of bytes.true
if the specified number of bytes can be read from this input.NullPointerException
- if this object is not bound with setInput
.IOException
- if an I/O error occurs.public int available() throws IOException
length
specified when binding this object
with setInput
method.
This method returns 0
when this object is not bound.available
in interface ObjectInput
available
in class BufferedInput
IOException
- If an I/O error has occurred.public int read(byte[] b, int off, int len) throws IOException
read
in interface ObjectInput
read
in class BufferedInput
IOException
public long skip(long n) throws IOException
skip
in interface ObjectInput
skip
in class BufferedInput
IOException
public void rewind(long n)
rewind
in class BufferedInput
n
- the number of bytes to rewindprotected int readData() throws IOException
-1
if no bytes can be read because the end of the stream has been reached.
This method may block if needed.
This method is allowed to update buffer, position, limit and totalPositionBase fields as needed.
This method shall never throw an EOFException
.
readData
in class BufferedInput
-1
if there is no more data because the end of the stream has been reachedIOException
- if an I/O error occursprotected void checkEncapsulatedLength(long length, long min, long max) throws IOException
Data retrieval methods getting variable amount of data can invoke this method to check an upper bound of available data for validation.
checkEncapsulatedLength
in class BufferedInput
length
- encapsulated length value to be checkedmin
- minimal theoretically valid length valuemax
- maximal theoretically valid length valueIOException
- if length < min || length > max
or length
bytes definitely cannot
be retrievedCopyright © 2002–2025 Devexperts LLC. All rights reserved.