public class Input
extends java.io.InputStream
The byte[] buffer may be modified and then returned to its original state during some read operations, so the same byte[] should not be used concurrently in separate threads.
| 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 |
| Constructor and Description |
|---|
Input()
Creates an uninitialized Input.
|
Input(byte[] buffer)
Creates a new Input for reading from a byte array.
|
Input(byte[] buffer,
int offset,
int count)
Creates a new Input for reading from a byte array.
|
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.
|
Input(int bufferSize)
Creates a new Input for reading from a byte array.
|
| 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). |
void |
close()
Closes the underlying InputStream, if any.
|
boolean |
eof() |
protected int |
fill(byte[] buffer,
int offset,
int count)
Fills the buffer with more bytes.
|
byte[] |
getBuffer() |
java.io.InputStream |
getInputStream() |
int |
limit()
Returns the limit for the buffer.
|
private int |
optional(int optional) |
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.
|
private java.lang.String |
readAscii_slow() |
private java.lang.String |
readAscii() |
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.
|
private int |
readInt_slow(boolean optimizePositive) |
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.
|
int[] |
readInts(int length,
boolean optimizePositive)
Bulk input of an int array.
|
private long |
readLong_slow(boolean optimizePositive) |
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.
|
long[] |
readLongs(int length,
boolean optimizePositive)
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.
|
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.
|
private void |
readUtf8_slow(int charCount,
int charIndex) |
private void |
readUtf8(int charCount) |
private int |
readUtf8Length_slow(int b) |
private int |
readUtf8Length(int b) |
int |
readVarInt(boolean optimizePositive)
Reads a 1-5 byte int.
|
long |
readVarLong(boolean optimizePositive)
Reads a 1-9 byte long.
|
protected int |
require(int required) |
void |
rewind()
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.
|
void |
setInputStream(java.io.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 |
setTotal(long total)
Sets the number of bytes read.
|
void |
skip(int count)
Discards the specified number of bytes.
|
long |
skip(long count)
Discards the specified number of bytes.
|
long |
total()
Returns the 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
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.public Input(byte[] buffer)
buffer - An exception is thrown if more bytes than this are read.public Input(byte[] buffer,
int offset,
int count)
buffer - An exception is thrown if more bytes than this are read.public Input(java.io.InputStream inputStream)
public Input(java.io.InputStream inputStream,
int bufferSize)
public void setBuffer(byte[] bytes)
public void setBuffer(byte[] bytes,
int offset,
int count)
public byte[] getBuffer()
public java.io.InputStream getInputStream()
public void setInputStream(java.io.InputStream inputStream)
inputStream - May be null.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 rewind()
public void skip(int count)
throws KryoException
KryoExceptionprotected int fill(byte[] buffer,
int offset,
int count)
throws KryoException
KryoExceptionprotected int require(int required)
throws KryoException
required - 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).private int optional(int optional)
throws KryoException
optional - Try to fill the buffer with this many bytes.KryoExceptionpublic boolean eof()
public int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic int read()
throws KryoException
read in class java.io.InputStreamKryoExceptionpublic int read(byte[] bytes)
throws KryoException
read in class java.io.InputStreamKryoExceptionpublic int read(byte[] bytes,
int offset,
int count)
throws KryoException
read in class java.io.InputStreamKryoExceptionpublic long skip(long count)
throws KryoException
skip in class java.io.InputStreamKryoExceptionpublic void close()
throws KryoException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamKryoExceptionpublic byte readByte()
throws KryoException
KryoExceptionpublic int readByteUnsigned()
throws KryoException
KryoExceptionpublic byte[] readBytes(int length)
throws KryoException
KryoExceptionpublic void readBytes(byte[] bytes)
throws KryoException
KryoExceptionpublic void readBytes(byte[] bytes,
int offset,
int count)
throws KryoException
KryoExceptionpublic int readInt()
throws KryoException
KryoExceptionpublic int readInt(boolean optimizePositive)
throws KryoException
KryoExceptionpublic int readVarInt(boolean optimizePositive)
throws KryoException
KryoExceptionprivate int readInt_slow(boolean optimizePositive)
public boolean canReadInt()
throws KryoException
readInt(boolean).KryoExceptionpublic boolean canReadLong()
throws KryoException
readLong(boolean).KryoExceptionpublic java.lang.String readString()
Output.writeString(String)
, Output.writeString(CharSequence), and Output.writeAscii(String).private int readUtf8Length(int b)
private int readUtf8Length_slow(int b)
private void readUtf8(int charCount)
private void readUtf8_slow(int charCount,
int charIndex)
private java.lang.String readAscii()
private java.lang.String readAscii_slow()
public java.lang.StringBuilder readStringBuilder()
Output.writeString(String)
, Output.writeString(CharSequence), and Output.writeAscii(String).public float readFloat()
throws KryoException
KryoExceptionpublic float readFloat(float precision,
boolean optimizePositive)
throws KryoException
KryoExceptionpublic short readShort()
throws KryoException
KryoExceptionpublic int readShortUnsigned()
throws KryoException
KryoExceptionpublic long readLong()
throws KryoException
KryoExceptionpublic long readLong(boolean optimizePositive)
throws KryoException
KryoExceptionpublic long readVarLong(boolean optimizePositive)
throws KryoException
KryoExceptionprivate long readLong_slow(boolean optimizePositive)
public boolean readBoolean()
throws KryoException
KryoExceptionpublic char readChar()
throws KryoException
KryoExceptionpublic double readDouble()
throws KryoException
KryoExceptionpublic double readDouble(double precision,
boolean optimizePositive)
throws KryoException
KryoExceptionpublic int[] readInts(int length,
boolean optimizePositive)
throws KryoException
KryoExceptionpublic long[] readLongs(int length,
boolean optimizePositive)
throws KryoException
KryoExceptionpublic int[] readInts(int length)
throws KryoException
KryoExceptionpublic long[] readLongs(int length)
throws KryoException
KryoExceptionpublic float[] readFloats(int length)
throws KryoException
KryoExceptionpublic short[] readShorts(int length)
throws KryoException
KryoExceptionpublic char[] readChars(int length)
throws KryoException
KryoExceptionpublic double[] readDoubles(int length)
throws KryoException
KryoException