public class Input extends 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 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(InputStream inputStream)
Creates a new Input for reading from an InputStream with a buffer size of 4096.
|
Input(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() |
InputStream |
getInputStream() |
int |
limit()
Returns the limit for the buffer.
|
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.
|
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.
|
int[] |
readInts(int length,
boolean optimizePositive)
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.
|
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.
|
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.
|
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(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.
|
mark, markSupported, reset
protected byte[] buffer
protected int position
protected int capacity
protected int limit
protected long total
protected char[] chars
protected 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(InputStream inputStream)
public Input(InputStream inputStream, int bufferSize)
public void setBuffer(byte[] bytes)
public void setBuffer(byte[] bytes, int offset, int count)
public byte[] getBuffer()
public InputStream getInputStream()
public void setInputStream(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
KryoException
protected int fill(byte[] buffer, int offset, int count) throws KryoException
KryoException
protected 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).public boolean eof()
public int available() throws IOException
available
in class InputStream
IOException
public int read() throws KryoException
read
in class InputStream
KryoException
public int read(byte[] bytes) throws KryoException
read
in class InputStream
KryoException
public int read(byte[] bytes, int offset, int count) throws KryoException
read
in class InputStream
KryoException
public long skip(long count) throws KryoException
skip
in class InputStream
KryoException
public void close() throws KryoException
close
in interface Closeable
close
in interface AutoCloseable
close
in class 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
KryoException
public int readVarInt(boolean optimizePositive) throws KryoException
KryoException
public boolean canReadInt() throws KryoException
readInt(boolean)
.KryoException
public boolean canReadLong() throws KryoException
readLong(boolean)
.KryoException
public String readString()
Output.writeString(String)
, Output.writeString(CharSequence)
, and Output.writeAscii(String)
.public StringBuilder readStringBuilder()
Output.writeString(String)
, Output.writeString(CharSequence)
, and Output.writeAscii(String)
.public float readFloat() throws KryoException
KryoException
public float readFloat(float precision, boolean optimizePositive) throws KryoException
KryoException
public short readShort() throws KryoException
KryoException
public int readShortUnsigned() throws KryoException
KryoException
public long readLong() throws KryoException
KryoException
public long readLong(boolean optimizePositive) throws KryoException
KryoException
public long readVarLong(boolean optimizePositive) throws KryoException
KryoException
public boolean readBoolean() throws KryoException
KryoException
public char readChar() throws KryoException
KryoException
public double readDouble() throws KryoException
KryoException
public double readDouble(double precision, boolean optimizePositive) throws KryoException
KryoException
public int[] readInts(int length, boolean optimizePositive) throws KryoException
KryoException
public long[] readLongs(int length, boolean optimizePositive) throws KryoException
KryoException
public int[] readInts(int length) throws KryoException
KryoException
public long[] readLongs(int length) throws KryoException
KryoException
public float[] readFloats(int length) throws KryoException
KryoException
public short[] readShorts(int length) throws KryoException
KryoException
public char[] readChars(int length) throws KryoException
KryoException
public double[] readDoubles(int length) throws KryoException
KryoException
Copyright © 2018. All rights reserved.