public class ByteArrayInput extends BufferedInput
BufferedInput
using single byte array buffer.buffer, EMPTY_BYTE_ARRAY, limit, markPosition, position, totalPositionBase
Constructor and Description |
---|
ByteArrayInput()
Creates a new byte array input without pre-allocated buffer.
|
ByteArrayInput(byte[] buf)
Creates a new byte array input with specified buffer as its input.
|
ByteArrayInput(byte[] buf,
int offset,
int length)
Creates a new byte array input with specified buffer and range as its input.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears this byte array input.
|
void |
ensureCapacity(int requiredCapacity)
Ensures that the byte array used for buffering has at least the specified capacity.
|
byte[] |
getBuffer()
Returns byte array used for buffering.
|
int |
getLimit()
Returns limit.
|
int |
getPosition()
Returns position.
|
protected int |
readData()
This method is invoked when input methods need more bytes to read data.
|
protected int |
readData(int length)
Deprecated.
This method is provided for backwards compatibility, because
it is extended in some legacy classes. It is always invoked with a length of 1.
Override
readData() instead. |
void |
rewind(long n)
Rewinds specified number of bytes.
|
void |
setBuffer(byte[] newBuffer)
Sets specified byte array to be used for buffering.
|
void |
setInput(byte[] buf,
int offset,
int length)
Sets specified buffer and range as an input.
|
void |
setLimit(int newLimit)
Sets limit as specified.
|
void |
setPosition(int newPosition)
Sets position as specified.
|
void |
setTotalPosition(long totalPosition)
Sets total position as specified.
|
available, checkEncapsulatedLength, checkEOB, checkRewind, hasAvailable, hasAvailable, mark, mark, mark, markSupported, needData, read, 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, skip, skipBytes, throwEOFException, totalPosition, unmark
close
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
close
public ByteArrayInput()
public ByteArrayInput(byte[] buf)
buf
- the input bufferpublic ByteArrayInput(byte[] buf, int offset, int length)
offset
, the limit is set to offset+length
.buf
- the input bufferoffset
- the offset in the buffer of the first byte to readlength
- the maximum number of bytes to read from the bufferIllegalArgumentException
- if buf, offset and length do not constitute a valid rangeprotected int readData(int length) throws IOException
readData()
instead.readData()
.
This implementation checks internal invariant that
and returns position
== limit
-1
.
IOException
protected 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
.
This implementation invokes
for backwards compatibility.readData
(1)
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 occurspublic void setInput(byte[] buf, int offset, int length)
offset
,
the limit is set to offset+length
, the mark is invalidated.buf
- the input bufferoffset
- the offset in the buffer of the first byte to readlength
- the maximum number of bytes to read from the bufferIllegalArgumentException
- if buf, offset and length do not constitute a valid rangepublic byte[] getBuffer()
public void setBuffer(byte[] newBuffer)
public int getPosition()
public void setPosition(int newPosition)
IllegalArgumentException
- if the new position is negative or is larger than the limitpublic int getLimit()
public void setLimit(int newLimit)
IllegalArgumentException
- if the new limit is negative or is larger than the capacitypublic void setTotalPosition(long totalPosition)
IllegalArgumentException
- if the new total position is negativepublic void clear()
totalPosition
is set to zero,
the position
is set to zero,
the limit
is set to the capacity,
the mark is invalidated.public void ensureCapacity(int requiredCapacity)
public void rewind(long n)
BufferedInput
rewind
in class BufferedInput
n
- the number of bytes to rewindCopyright © 2002–2025 Devexperts LLC. All rights reserved.