public class ByteBufferInput extends Input
| Modifier and Type | Field and Description |
|---|---|
protected static ByteOrder |
nativeOrder |
protected ByteBuffer |
niobuffer |
protected boolean |
varIntsEnabled |
| Constructor and Description |
|---|
ByteBufferInput()
Creates an uninitialized Input.
|
ByteBufferInput(byte[] buffer) |
ByteBufferInput(ByteBuffer buffer)
Creates a new Input for reading from a ByteBuffer.
|
ByteBufferInput(InputStream inputStream)
Creates a new Input for reading from an InputStream with a buffer size of 4096.
|
ByteBufferInput(InputStream inputStream,
int bufferSize)
Creates a new Input for reading from an InputStream.
|
ByteBufferInput(int bufferSize)
Creates a new Input for reading from a byte array.
|
ByteBufferInput(long address,
int size)
This constructor allows for creation of a direct ByteBuffer of a given size at a given address.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canReadInt()
Returns true if enough bytes are available to read an int with
readInt(boolean). |
boolean |
canReadLong()
Returns true if enough bytes are available to read a long with
readLong(boolean). |
void |
close()
Closes the underlying InputStream, if any.
|
protected int |
fill(ByteBuffer buffer,
int offset,
int count)
Fills the buffer with more bytes.
|
ByteBuffer |
getByteBuffer() |
InputStream |
getInputStream() |
boolean |
getVarIntsEnabled()
Return current setting for variable length encoding of integers
|
ByteOrder |
order() |
void |
order(ByteOrder byteOrder) |
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.
|
byte |
readByte()
Reads a single byte.
|
void |
readBytes(byte[] bytes)
Reads bytes.length bytes and writes them to the specified byte[], starting at index 0.
|
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)
Bulk input of a char array.
|
double |
readDouble()
Reads an 8 bytes double.
|
double |
readDouble(double precision,
boolean optimizePositive)
Reads a 1-9 byte double with reduced precision.
|
double[] |
readDoubles(int length)
Bulk input of a double array.
|
float |
readFloat()
Reads a 4 byte float.
|
float |
readFloat(float precision,
boolean optimizePositive)
Reads a 1-5 byte float with reduced precision.
|
float[] |
readFloats(int length)
Bulk input of a float array.
|
int |
readInt()
Reads a 4 byte int.
|
int |
readInt(boolean optimizePositive)
Reads a 1-5 byte int.
|
int[] |
readInts(int length)
Bulk input of an int array.
|
long |
readLong()
Reads an 8 byte long.
|
long |
readLong(boolean optimizePositive)
Reads a 1-9 byte long.
|
long[] |
readLongs(int length)
Bulk input of a long array.
|
short |
readShort()
Reads a 2 byte short.
|
short[] |
readShorts(int length)
Bulk input of a short array.
|
int |
readShortUnsigned()
Reads a 2 byte short as an int from 0 to 65535.
|
String |
readString()
Reads the length and string of UTF8 characters, or null.
|
StringBuilder |
readStringBuilder()
Reads the length and string of UTF8 characters, or null.
|
int |
readVarInt(boolean optimizePositive)
Reads a 1-5 byte int.
|
long |
readVarLong(boolean optimizePositive)
Reads a 1-9 byte long.
|
void |
release()
Releases a direct buffer.
|
protected int |
require(int required) |
void |
rewind()
Sets the position and total to zero.
|
void |
setBuffer(byte[] bytes)
Sets a new buffer, discarding any previous buffer.
|
void |
setBuffer(ByteBuffer buffer)
Sets a new buffer, discarding any previous buffer.
|
void |
setInputStream(InputStream inputStream)
Sets a new InputStream.
|
void |
setLimit(int limit)
Sets the limit in the buffer.
|
void |
setPosition(int position)
Sets the current position in the buffer.
|
void |
setVarIntsEnabled(boolean varIntsEnabled)
Controls if a variable length encoding for integer types should be used when serializers suggest it.
|
void |
skip(int count)
Discards the specified number of bytes.
|
long |
skip(long count)
Discards the specified number of bytes.
|
available, eof, fill, getBuffer, limit, position, readInts, readLongs, setBuffer, setTotal, totalmark, markSupported, resetprotected ByteBuffer niobuffer
protected boolean varIntsEnabled
protected static final ByteOrder nativeOrder
public ByteBufferInput()
setBuffer(ByteBuffer)public ByteBufferInput(int bufferSize)
bufferSize - The size of the buffer. An exception is thrown if more bytes than this are read.public ByteBufferInput(byte[] buffer)
public ByteBufferInput(ByteBuffer buffer)
public ByteBufferInput(InputStream inputStream)
public ByteBufferInput(InputStream inputStream, int bufferSize)
public ByteBufferInput(long address,
int size)
Typical usage could look like this snippet:
// Explicitly allocate memory long bufAddress = UnsafeUtil.unsafe().allocateMemory(4096); // Create a ByteBufferInput using the allocated memory region ByteBufferInput buffer = new ByteBufferInput(bufAddress, 4096); // Do some operations on this buffer here // Say that ByteBuffer won't be used anymore buffer.release(); // Release the allocated region UnsafeUtil.unsafe().freeMemory(bufAddress);
address - starting address of a memory region pre-allocated using Unsafe.allocateMemory()public ByteOrder order()
public void order(ByteOrder byteOrder)
public void setBuffer(byte[] bytes)
public void setBuffer(ByteBuffer buffer)
InputStream is set to null.public void release()
setBuffer(ByteBuffer) must be called before any write operations can be performed.public ByteBuffer getByteBuffer()
public InputStream getInputStream()
getInputStream in class Inputpublic void setInputStream(InputStream inputStream)
setInputStream in class InputinputStream - May be null.public void rewind()
Inputprotected int fill(ByteBuffer buffer, int offset, int count) throws KryoException
KryoExceptionprotected final int require(int required)
throws KryoException
require in class Inputrequired - Must be > 0. The buffer is filled until it has at least this many bytes.KryoException - if EOS is reached before required bytes are read (buffer underflow).public int read()
throws KryoException
read in class InputKryoExceptionpublic int read(byte[] bytes)
throws KryoException
read in class InputKryoExceptionpublic int read(byte[] bytes,
int offset,
int count)
throws KryoException
read in class InputKryoExceptionpublic void setPosition(int position)
InputsetPosition in class Inputpublic void setLimit(int limit)
public void skip(int count)
throws KryoException
Inputskip in class InputKryoExceptionpublic long skip(long count)
throws KryoException
skip in class InputKryoExceptionpublic void close()
throws KryoException
close in interface Closeableclose in interface AutoCloseableclose in class InputKryoExceptionpublic byte readByte()
throws KryoException
readByte in class InputKryoExceptionpublic int readByteUnsigned()
throws KryoException
readByteUnsigned in class InputKryoExceptionpublic byte[] readBytes(int length)
throws KryoException
readBytes in class InputKryoExceptionpublic void readBytes(byte[] bytes)
throws KryoException
readBytes in class InputKryoExceptionpublic void readBytes(byte[] bytes,
int offset,
int count)
throws KryoException
readBytes in class InputKryoExceptionpublic int readInt()
throws KryoException
InputreadInt in class InputKryoExceptionpublic int readInt(boolean optimizePositive)
throws KryoException
InputreadInt in class InputKryoExceptionpublic int readVarInt(boolean optimizePositive)
throws KryoException
InputreadVarInt in class InputKryoExceptionpublic boolean canReadInt()
throws KryoException
readInt(boolean).canReadInt in class InputKryoExceptionpublic boolean canReadLong()
throws KryoException
readLong(boolean).canReadLong in class InputKryoExceptionpublic String readString()
Output.writeString(String) , Output.writeString(CharSequence), and Output.writeAscii(String).readString in class Inputpublic StringBuilder readStringBuilder()
Output.writeString(String) , Output.writeString(CharSequence), and Output.writeAscii(String).readStringBuilder in class Inputpublic float readFloat()
throws KryoException
readFloat in class InputKryoExceptionpublic float readFloat(float precision,
boolean optimizePositive)
throws KryoException
readFloat in class InputKryoExceptionpublic short readShort()
throws KryoException
readShort in class InputKryoExceptionpublic int readShortUnsigned()
throws KryoException
readShortUnsigned in class InputKryoExceptionpublic long readLong()
throws KryoException
readLong in class InputKryoExceptionpublic long readLong(boolean optimizePositive)
throws KryoException
readLong in class InputKryoExceptionpublic long readVarLong(boolean optimizePositive)
throws KryoException
readVarLong in class InputKryoExceptionpublic boolean readBoolean()
throws KryoException
readBoolean in class InputKryoExceptionpublic char readChar()
throws KryoException
readChar in class InputKryoExceptionpublic double readDouble()
throws KryoException
readDouble in class InputKryoExceptionpublic double readDouble(double precision,
boolean optimizePositive)
throws KryoException
readDouble in class InputKryoExceptionpublic int[] readInts(int length)
throws KryoException
readInts in class InputKryoExceptionpublic long[] readLongs(int length)
throws KryoException
readLongs in class InputKryoExceptionpublic float[] readFloats(int length)
throws KryoException
readFloats in class InputKryoExceptionpublic short[] readShorts(int length)
throws KryoException
readShorts in class InputKryoExceptionpublic char[] readChars(int length)
throws KryoException
readChars in class InputKryoExceptionpublic double[] readDoubles(int length)
throws KryoException
readDoubles in class InputKryoExceptionpublic boolean getVarIntsEnabled()
public void setVarIntsEnabled(boolean varIntsEnabled)
varIntsEnabled - Copyright © 2023. All rights reserved.