public class ByteBufferInput extends Input
Input that uses a ByteBuffer rather than a byte[].
Note that the byte[] buffer is not used. Code taking an Input and expecting the byte[] to be used may not
work correctly.
| Modifier and Type | Field and Description |
|---|---|
protected java.nio.ByteBuffer |
byteBuffer |
buffer, capacity, chars, inputStream, limit, position, total, varEncoding| Constructor and Description |
|---|
ByteBufferInput()
Creates an uninitialized Input,
setBuffer(ByteBuffer) must be called before the Input is used. |
ByteBufferInput(byte[] bytes)
Creates a new Input for reading from a
ByteBuffer which is filled with the specified bytes. |
ByteBufferInput(byte[] bytes,
int offset,
int count)
Creates a new Input for reading from a
ByteBuffer which is filled with the specified bytes. |
ByteBufferInput(java.nio.ByteBuffer buffer)
Creates a new Input for reading from a ByteBuffer.
|
ByteBufferInput(java.io.InputStream inputStream) |
ByteBufferInput(java.io.InputStream inputStream,
int bufferSize) |
ByteBufferInput(int bufferSize)
Creates a new Input for reading from a direct
ByteBuffer. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canReadVarInt()
Returns true if enough bytes are available to read an int with
Input.readVarInt(boolean). |
boolean |
canReadVarLong()
Returns true if enough bytes are available to read a long with
Input.readVarLong(boolean). |
void |
close()
Closes the underlying InputStream, if any.
|
protected int |
fill(java.nio.ByteBuffer buffer,
int offset,
int count)
Fills the buffer with more bytes.
|
byte[] |
getBuffer()
Deprecated.
|
java.nio.ByteBuffer |
getByteBuffer() |
protected int |
optional(int optional)
Fills the buffer with at least the number of bytes specified, if possible.
|
int |
read()
Reads a single byte as an int from 0 to 255, or -1 if there are no more bytes are available.
|
int |
read(byte[] bytes)
Reads bytes.length bytes or less and writes them to the specified byte[], starting at 0, and returns the number of bytes
read.
|
int |
read(byte[] bytes,
int offset,
int count)
Reads count bytes or less and writes them to the specified byte[], starting at offset, and returns the number of bytes read
or -1 if no more bytes are available.
|
boolean |
readBoolean()
Reads a 1 byte boolean.
|
boolean[] |
readBooleans(int length)
Reads a boolean array in bulk.
|
byte |
readByte()
Reads a single byte.
|
void |
readBytes(byte[] bytes,
int offset,
int count)
Reads count bytes and writes them to the specified byte[], starting at offset.
|
byte[] |
readBytes(int length)
Reads the specified number of bytes into a new byte[].
|
int |
readByteUnsigned()
Reads a byte as an int from 0 to 255.
|
char |
readChar()
Reads a 2 byte char.
|
char[] |
readChars(int length)
Reads a char array in bulk.
|
double |
readDouble()
Reads an 8 byte double.
|
double[] |
readDoubles(int length)
Reads a double array in bulk.
|
float |
readFloat()
Reads a 4 byte float.
|
float[] |
readFloats(int length)
Reads a float array in bulk.
|
int |
readInt()
Reads a 4 byte int.
|
int[] |
readInts(int length)
Reads an int array in bulk.
|
long |
readLong()
Reads an 8 byte long.
|
long[] |
readLongs(int length)
Reads a long array in bulk.
|
short |
readShort()
Reads a 2 byte short.
|
short[] |
readShorts(int length)
Reads a short array in bulk.
|
int |
readShortUnsigned()
Reads a 2 byte short as an int from 0 to 65535.
|
java.lang.String |
readString()
Reads the length and string of UTF8 characters, or null.
|
java.lang.StringBuilder |
readStringBuilder()
Reads the length and string of UTF8 characters, or null.
|
int |
readVarInt(boolean optimizePositive)
Reads a 1-5 byte int.
|
boolean |
readVarIntFlag()
Reads the boolean part of a varint flag.
|
int |
readVarIntFlag(boolean optimizePositive)
Reads the 1-5 byte int part of a varint flag.
|
long |
readVarLong(boolean optimizePositive)
Reads a 1-9 byte long.
|
protected int |
require(int required)
Fills the buffer with at least the number of bytes specified.
|
void |
reset()
Sets the position and total to zero.
|
void |
setBuffer(byte[] bytes)
Deprecated.
|
void |
setBuffer(byte[] bytes,
int offset,
int count)
Deprecated.
|
void |
setBuffer(java.nio.ByteBuffer buffer)
Sets a new buffer to read from.
|
void |
setInputStream(java.io.InputStream inputStream)
Sets an InputStream to read from when data in the buffer is exhausted.
|
void |
setLimit(int limit)
Sets the limit in the buffer which marks the end of the data that can be read.
|
void |
setPosition(int position)
Sets the current position in the buffer where the next byte will be read.
|
void |
skip(int count)
Discards the specified number of bytes.
|
long |
skip(long count)
Discards the specified number of bytes.
|
available, canReadInt, canReadLong, end, fill, getInputStream, getVariableLengthEncoding, limit, position, readBytes, readInt, readInts, readLong, readLongs, readVarDouble, readVarFloat, setTotal, setVariableLengthEncoding, totalpublic ByteBufferInput()
setBuffer(ByteBuffer) must be called before the Input is used.public ByteBufferInput(int bufferSize)
ByteBuffer.bufferSize - The size of the buffer. An exception is thrown if more bytes than this are read and
fill(ByteBuffer, int, int) does not supply more bytes.public ByteBufferInput(byte[] bytes)
ByteBuffer which is filled with the specified bytes.public ByteBufferInput(byte[] bytes,
int offset,
int count)
ByteBuffer which is filled with the specified bytes.setBuffer(byte[], int, int)public ByteBufferInput(java.nio.ByteBuffer buffer)
public ByteBufferInput(java.io.InputStream inputStream)
Input.Input(InputStream)public ByteBufferInput(java.io.InputStream inputStream,
int bufferSize)
Input.Input(InputStream, int)public byte[] getBuffer()
UnsupportedOperationException because this input uses a ByteBuffer, not a byte[].getBuffer in class InputgetByteBuffer()public void setBuffer(byte[] bytes)
UnsupportedOperationException because this input uses a ByteBuffer, not a byte[].setBuffer in class InputsetBuffer(ByteBuffer)public void setBuffer(byte[] bytes,
int offset,
int count)
UnsupportedOperationException because this input uses a ByteBuffer, not a byte[].setBuffer in class InputsetBuffer(ByteBuffer)public void setBuffer(java.nio.ByteBuffer buffer)
InputStream is set to null.public java.nio.ByteBuffer getByteBuffer()
public void setInputStream(java.io.InputStream inputStream)
InputsetInputStream in class InputinputStream - May be null.public void reset()
Inputreset in interface Pool.Poolablereset in class Inputprotected int fill(java.nio.ByteBuffer buffer,
int offset,
int count)
throws KryoException
InputStream, if set. Can be overridden to fill the bytes from another source.KryoExceptionprotected int require(int required)
throws KryoException
Inputrequire in class Inputrequired - Must be > 0.required bytes.KryoException - if Input.fill(byte[], int, int) is unable to provide more bytes (buffer underflow).protected int optional(int optional)
throws KryoException
optional in class Inputoptional - Must be > 0.fill(ByteBuffer, int, int) is unable to
provide more bytes.KryoExceptionpublic int read()
throws KryoException
Inputread in class InputKryoExceptionpublic int read(byte[] bytes)
throws KryoException
Inputread in class InputKryoExceptionpublic int read(byte[] bytes,
int offset,
int count)
throws KryoException
Inputread in class InputKryoExceptionpublic void setPosition(int position)
InputsetPosition in class Inputpublic void setLimit(int limit)
Inputpublic void skip(int count)
throws KryoException
Inputskip in class InputKryoExceptionpublic long skip(long count)
throws KryoException
Inputskip in class InputKryoExceptionpublic void close()
throws KryoException
Inputclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class InputKryoExceptionpublic byte readByte()
throws KryoException
InputreadByte in class InputKryoExceptionpublic int readByteUnsigned()
throws KryoException
InputreadByteUnsigned in class InputKryoExceptionpublic byte[] readBytes(int length)
throws KryoException
InputreadBytes in class InputKryoExceptionpublic void readBytes(byte[] bytes,
int offset,
int count)
throws KryoException
InputreadBytes in class InputKryoExceptionpublic int readInt()
throws KryoException
InputreadInt in class InputKryoExceptionpublic int readVarInt(boolean optimizePositive)
throws KryoException
InputreadVarInt in class InputKryoExceptionInput.canReadVarInt()public boolean canReadVarInt()
throws KryoException
InputInput.readVarInt(boolean).canReadVarInt in class InputKryoExceptionpublic boolean readVarIntFlag()
readVarIntFlag(boolean) should be used to
advance the position.readVarIntFlag in class Inputpublic int readVarIntFlag(boolean optimizePositive)
readVarIntFlag().readVarIntFlag in class Inputpublic long readLong()
throws KryoException
InputreadLong in class InputKryoExceptionpublic long readVarLong(boolean optimizePositive)
throws KryoException
InputreadVarLong in class InputKryoExceptionInput.canReadLong()public boolean canReadVarLong()
throws KryoException
InputInput.readVarLong(boolean).canReadVarLong in class InputKryoExceptionpublic float readFloat()
throws KryoException
InputreadFloat in class InputKryoExceptionpublic double readDouble()
throws KryoException
InputreadDouble in class InputKryoExceptionpublic boolean readBoolean()
throws KryoException
InputreadBoolean in class InputKryoExceptionpublic short readShort()
throws KryoException
InputreadShort in class InputKryoExceptionpublic int readShortUnsigned()
throws KryoException
InputreadShortUnsigned in class InputKryoExceptionpublic char readChar()
throws KryoException
InputreadChar in class InputKryoExceptionpublic java.lang.String readString()
InputOutput.writeString(String) and Output.writeAscii(String).readString in class Inputpublic java.lang.StringBuilder readStringBuilder()
InputOutput.writeString(String) and
Output.writeAscii(String).readStringBuilder in class Inputpublic int[] readInts(int length)
throws KryoException
InputreadInts in class InputKryoExceptionpublic long[] readLongs(int length)
throws KryoException
InputreadLongs in class InputKryoExceptionpublic float[] readFloats(int length)
throws KryoException
InputreadFloats in class InputKryoExceptionpublic double[] readDoubles(int length)
throws KryoException
InputreadDoubles in class InputKryoExceptionpublic short[] readShorts(int length)
throws KryoException
InputreadShorts in class InputKryoExceptionpublic char[] readChars(int length)
throws KryoException
InputreadChars in class InputKryoExceptionpublic boolean[] readBooleans(int length)
throws KryoException
InputreadBooleans in class InputKryoExceptionCopyright © 2019. All Rights Reserved.