public class ByteArrayInput extends BufferedInput
BufferedInput
using single byte array buffer.buffer, EMPTY_BYTE_ARRAY, limit, markLimit, 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.
|
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, checkEOB, checkRewind, mark, mark, markSupported, needData, read, read, read, readBoolean, readByte, readByteArray, readChar, readCompactInt, readCompactLong, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readObject, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTFChar, readUTFString, reset, seek, skip, skipBytes, throwEOFException, totalPosition
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() throws IOException
BufferedInput
-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 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()
public void ensureCapacity(int requiredCapacity)
public void rewind(long n)
BufferedInput
rewind
in class BufferedInput
n
- the number of bytes to rewindCopyright © 2014 Devexperts. All Rights Reserved.