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, total
public 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 Input
getByteBuffer()
public void setBuffer(byte[] bytes)
UnsupportedOperationException
because this input uses a ByteBuffer, not a byte[].setBuffer
in class Input
setBuffer(ByteBuffer)
public void setBuffer(byte[] bytes, int offset, int count)
UnsupportedOperationException
because this input uses a ByteBuffer, not a byte[].setBuffer
in class Input
setBuffer(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)
Input
setInputStream
in class Input
inputStream
- May be null.public void reset()
Input
reset
in interface Pool.Poolable
reset
in class Input
protected 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.KryoException
protected int require(int required) throws KryoException
Input
require
in class Input
required
- 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 Input
optional
- Must be > 0.fill(ByteBuffer, int, int)
is unable to
provide more bytes.KryoException
public int read() throws KryoException
Input
read
in class Input
KryoException
public int read(byte[] bytes) throws KryoException
Input
read
in class Input
KryoException
public int read(byte[] bytes, int offset, int count) throws KryoException
Input
read
in class Input
KryoException
public void setPosition(int position)
Input
setPosition
in class Input
public void setLimit(int limit)
Input
public void skip(int count) throws KryoException
Input
skip
in class Input
KryoException
public long skip(long count) throws KryoException
Input
skip
in class Input
KryoException
public void close() throws KryoException
Input
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class Input
KryoException
public byte readByte() throws KryoException
Input
readByte
in class Input
KryoException
public int readByteUnsigned() throws KryoException
Input
readByteUnsigned
in class Input
KryoException
public byte[] readBytes(int length) throws KryoException
Input
readBytes
in class Input
KryoException
public void readBytes(byte[] bytes, int offset, int count) throws KryoException
Input
readBytes
in class Input
KryoException
public int readInt() throws KryoException
Input
readInt
in class Input
KryoException
public int readVarInt(boolean optimizePositive) throws KryoException
Input
readVarInt
in class Input
KryoException
Input.canReadVarInt()
public boolean canReadVarInt() throws KryoException
Input
Input.readVarInt(boolean)
.canReadVarInt
in class Input
KryoException
public boolean readVarIntFlag()
readVarIntFlag(boolean)
should be used to
advance the position.readVarIntFlag
in class Input
public int readVarIntFlag(boolean optimizePositive)
readVarIntFlag()
.readVarIntFlag
in class Input
public long readLong() throws KryoException
Input
readLong
in class Input
KryoException
public long readVarLong(boolean optimizePositive) throws KryoException
Input
readVarLong
in class Input
KryoException
Input.canReadLong()
public boolean canReadVarLong() throws KryoException
Input
Input.readVarLong(boolean)
.canReadVarLong
in class Input
KryoException
public float readFloat() throws KryoException
Input
readFloat
in class Input
KryoException
public double readDouble() throws KryoException
Input
readDouble
in class Input
KryoException
public boolean readBoolean() throws KryoException
Input
readBoolean
in class Input
KryoException
public short readShort() throws KryoException
Input
readShort
in class Input
KryoException
public int readShortUnsigned() throws KryoException
Input
readShortUnsigned
in class Input
KryoException
public char readChar() throws KryoException
Input
readChar
in class Input
KryoException
public java.lang.String readString()
Input
Output.writeString(String)
and Output.writeAscii(String)
.readString
in class Input
public java.lang.StringBuilder readStringBuilder()
Input
Output.writeString(String)
and
Output.writeAscii(String)
.readStringBuilder
in class Input
public int[] readInts(int length) throws KryoException
Input
readInts
in class Input
KryoException
public long[] readLongs(int length) throws KryoException
Input
readLongs
in class Input
KryoException
public float[] readFloats(int length) throws KryoException
Input
readFloats
in class Input
KryoException
public double[] readDoubles(int length) throws KryoException
Input
readDoubles
in class Input
KryoException
public short[] readShorts(int length) throws KryoException
Input
readShorts
in class Input
KryoException
public char[] readChars(int length) throws KryoException
Input
readChars
in class Input
KryoException
public boolean[] readBooleans(int length) throws KryoException
Input
readBooleans
in class Input
KryoException
Copyright © 2019. All Rights Reserved.