public class Input extends java.io.InputStream implements java.lang.AutoCloseable, Pool.Poolable
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buffer |
protected int |
capacity |
protected char[] |
chars |
protected java.io.InputStream |
inputStream |
protected int |
limit |
protected int |
position |
protected long |
total |
protected boolean |
varEncoding |
Constructor and Description |
---|
Input()
Creates an uninitialized Input,
setBuffer(byte[]) must be called before the Input is used. |
Input(byte[] buffer)
Creates a new Input for reading from a byte[] buffer.
|
Input(byte[] buffer,
int offset,
int count)
Creates a new Input for reading from a byte[] buffer.
|
Input(java.io.InputStream inputStream)
Creates a new Input for reading from an InputStream with a buffer size of 4096.
|
Input(java.io.InputStream inputStream,
int bufferSize)
Creates a new Input for reading from an InputStream with the specified buffer size.
|
Input(int bufferSize)
Creates a new Input for reading from a byte[] buffer.
|
Modifier and Type | Method and Description |
---|---|
int |
available() |
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) . |
boolean |
canReadVarInt()
Returns true if enough bytes are available to read an int with
readVarInt(boolean) . |
boolean |
canReadVarLong()
Returns true if enough bytes are available to read a long with
readVarLong(boolean) . |
void |
close()
Closes the underlying InputStream, if any.
|
boolean |
end()
Returns true if the
limit() has been reached and fill(byte[], int, int) is unable to provide more
bytes. |
protected int |
fill(byte[] buffer,
int offset,
int count)
Fills the buffer with more bytes.
|
byte[] |
getBuffer()
Returns the buffer.
|
java.io.InputStream |
getInputStream() |
boolean |
getVariableLengthEncoding() |
int |
limit()
Returns the limit for the buffer.
|
protected int |
optional(int optional)
Fills the buffer with at least the number of bytes specified, if possible.
|
int |
position()
Returns the current position in the buffer.
|
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)
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)
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 |
readInt(boolean optimizePositive)
Reads an int using fixed or variable length encoding, depending on
setVariableLengthEncoding(boolean) . |
int[] |
readInts(int length)
Reads an int array in bulk.
|
int[] |
readInts(int length,
boolean optimizePositive)
Reads an int array in bulk using fixed or variable length encoding, depending on
setVariableLengthEncoding(boolean) . |
long |
readLong()
Reads an 8 byte long.
|
long |
readLong(boolean optimizePositive)
Reads a long using fixed or variable length encoding, depending on
setVariableLengthEncoding(boolean) . |
long[] |
readLongs(int length)
Reads a long array in bulk.
|
long[] |
readLongs(int length,
boolean optimizePositive)
Reads an int array in bulk using fixed or variable length encoding, depending on
setVariableLengthEncoding(boolean) . |
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.
|
double |
readVarDouble(double precision,
boolean optimizePositive)
Reads a 1-9 byte double with reduced precision.
|
float |
readVarFloat(float precision,
boolean optimizePositive)
Reads a 1-5 byte float with reduced precision.
|
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)
Sets a new buffer.
|
void |
setBuffer(byte[] bytes,
int offset,
int count)
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 |
setTotal(long total)
Sets the total number of bytes read.
|
void |
setVariableLengthEncoding(boolean varEncoding)
If false,
readInt(boolean) , readLong(boolean) , readInts(int, boolean) , and
readLongs(int, boolean) will use fixed length encoding, which may be faster for some data. |
void |
skip(int count)
Discards the specified number of bytes.
|
long |
skip(long count)
Discards the specified number of bytes.
|
long |
total()
Returns the total number of bytes read.
|
protected byte[] buffer
protected int position
protected int capacity
protected int limit
protected long total
protected char[] chars
protected java.io.InputStream inputStream
protected boolean varEncoding
public Input()
setBuffer(byte[])
must be called before the Input is used.public Input(int bufferSize)
bufferSize
- The size of the buffer. An exception is thrown if more bytes than this are read and
fill(byte[], int, int)
does not supply more bytes.public Input(byte[] buffer)
buffer
- An exception is thrown if more bytes than this are read and fill(byte[], int, int)
does not supply
more bytes.public Input(byte[] buffer, int offset, int count)
buffer
- An exception is thrown if more bytes than this are read and fill(byte[], int, int)
does not supply
more bytes.public Input(java.io.InputStream inputStream)
public Input(java.io.InputStream inputStream, int bufferSize)
public void setBuffer(byte[] bytes)
setBuffer(byte[], int, int)
public void setBuffer(byte[] bytes, int offset, int count)
InputStream
is set to null.public byte[] getBuffer()
position()
are the data that can be read.public java.io.InputStream getInputStream()
public void setInputStream(java.io.InputStream inputStream)
inputStream
- May be null.public boolean getVariableLengthEncoding()
public void setVariableLengthEncoding(boolean varEncoding)
readInt(boolean)
, readLong(boolean)
, readInts(int, boolean)
, and
readLongs(int, boolean)
will use fixed length encoding, which may be faster for some data. Default is true.public long total()
public void setTotal(long total)
public int position()
public void setPosition(int position)
public int limit()
public void setLimit(int limit)
public void reset()
reset
in interface Pool.Poolable
reset
in class java.io.InputStream
public void skip(int count) throws KryoException
KryoException
protected int fill(byte[] 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
required
- Must be > 0.required
bytes.KryoException
- if fill(byte[], int, int)
is unable to provide more bytes (buffer underflow).protected int optional(int optional) throws KryoException
optional
- Must be > 0.fill(byte[], int, int)
is unable to
provide more bytes.KryoException
public boolean end()
limit()
has been reached and fill(byte[], int, int)
is unable to provide more
bytes.public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public int read() throws KryoException
read
in class java.io.InputStream
KryoException
public int read(byte[] bytes) throws KryoException
read
in class java.io.InputStream
KryoException
public int read(byte[] bytes, int offset, int count) throws KryoException
read
in class java.io.InputStream
KryoException
public long skip(long count) throws KryoException
skip
in class java.io.InputStream
KryoException
public void close() throws KryoException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
KryoException
public byte readByte() throws KryoException
KryoException
public int readByteUnsigned() throws KryoException
KryoException
public byte[] readBytes(int length) throws KryoException
KryoException
public void readBytes(byte[] bytes) throws KryoException
KryoException
public void readBytes(byte[] bytes, int offset, int count) throws KryoException
KryoException
public int readInt() throws KryoException
KryoException
public int readInt(boolean optimizePositive) throws KryoException
setVariableLengthEncoding(boolean)
. Use
readVarInt(boolean)
explicitly when reading values that should always use variable length encoding (eg values that
appear many times).KryoException
canReadInt()
public boolean canReadInt() throws KryoException
readInt(boolean)
.KryoException
public int readVarInt(boolean optimizePositive) throws KryoException
KryoException
canReadVarInt()
public boolean canReadVarInt() throws KryoException
readVarInt(boolean)
.KryoException
public boolean readVarIntFlag()
readVarIntFlag(boolean)
should be used to
advance the position.public int readVarIntFlag(boolean optimizePositive)
readVarIntFlag()
.public long readLong() throws KryoException
KryoException
public long readLong(boolean optimizePositive) throws KryoException
setVariableLengthEncoding(boolean)
. Use
readVarLong(boolean)
explicitly when reading values that should always use variable length encoding (eg values that
appear many times).KryoException
canReadLong()
public long readVarLong(boolean optimizePositive) throws KryoException
KryoException
canReadLong()
public boolean canReadLong() throws KryoException
readLong(boolean)
.KryoException
public boolean canReadVarLong() throws KryoException
readVarLong(boolean)
.KryoException
public float readFloat() throws KryoException
KryoException
public float readVarFloat(float precision, boolean optimizePositive) throws KryoException
KryoException
public double readDouble() throws KryoException
KryoException
public double readVarDouble(double precision, boolean optimizePositive) throws KryoException
KryoException
public short readShort() throws KryoException
KryoException
public int readShortUnsigned() throws KryoException
KryoException
public char readChar() throws KryoException
KryoException
public boolean readBoolean() throws KryoException
KryoException
public java.lang.String readString()
Output.writeString(String)
and Output.writeAscii(String)
.public java.lang.StringBuilder readStringBuilder()
Output.writeString(String)
and
Output.writeAscii(String)
.public int[] readInts(int length) throws KryoException
KryoException
public int[] readInts(int length, boolean optimizePositive) throws KryoException
setVariableLengthEncoding(boolean)
. This may be more efficient than reading them individually.KryoException
public long[] readLongs(int length) throws KryoException
KryoException
public long[] readLongs(int length, boolean optimizePositive) throws KryoException
setVariableLengthEncoding(boolean)
. This may be more efficient than reading them individually.KryoException
public float[] readFloats(int length) throws KryoException
KryoException
public double[] readDoubles(int length) throws KryoException
KryoException
public short[] readShorts(int length) throws KryoException
KryoException
public char[] readChars(int length) throws KryoException
KryoException
public boolean[] readBooleans(int length) throws KryoException
KryoException
Copyright © 2019. All Rights Reserved.