Package com.esotericsoftware.kryo.unsafe
Class UnsafeInput
- java.lang.Object
-
- java.io.InputStream
-
- com.esotericsoftware.kryo.io.Input
-
- com.esotericsoftware.kryo.unsafe.UnsafeInput
-
- All Implemented Interfaces:
Pool.Poolable,java.io.Closeable,java.lang.AutoCloseable
public class UnsafeInput extends Input
AnInputthat reads data from a byte[] using sun.misc.Unsafe. Multi-byte primitive types use native byte order, so the native byte order on different computers which read and write the data must be the same.Not available on all JVMs.
Util.unsafecan be checked before using this class.This class may be much faster when
Input.setVariableLengthEncoding(boolean)is false.- Author:
- Roman Levenstein
, Nathan Sweet
-
-
Field Summary
-
Fields inherited from class com.esotericsoftware.kryo.io.Input
buffer, capacity, chars, inputStream, limit, position, total, varEncoding
-
-
Constructor Summary
Constructors Constructor Description UnsafeInput()Creates an uninitialized Input,Input.setBuffer(byte[])must be called before the Input is used.UnsafeInput(byte[] buffer)Creates a new Input for reading from a byte[] buffer.UnsafeInput(byte[] buffer, int offset, int count)Creates a new Input for reading from a byte[] buffer.UnsafeInput(int bufferSize)Creates a new Input for reading from a byte[] buffer.UnsafeInput(java.io.InputStream inputStream)Creates a new Input for reading from an InputStream with a buffer size of 4096.UnsafeInput(java.io.InputStream inputStream, int bufferSize)Creates a new Input for reading from an InputStream with the specified buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intread()Reads a single byte as an int from 0 to 255, or -1 if there are no more bytes are available.booleanreadBoolean()Reads a 1 byte boolean.boolean[]readBooleans(int length)Reads a boolean array in bulk.bytereadByte()Reads a single byte.voidreadBytes(byte[] bytes, int offset, int count)Reads count bytes and writes them to the specified byte[], starting at offset.voidreadBytes(java.lang.Object to, long offset, int count)Read count bytes and write them to the object at the given offset inside the in-memory representation of the object.intreadByteUnsigned()Reads a byte as an int from 0 to 255.charreadChar()Reads a 2 byte char.char[]readChars(int length)Reads a char array in bulk.doublereadDouble()Reads an 8 byte double.double[]readDoubles(int length)Reads a double array in bulk.floatreadFloat()Reads a 4 byte float.float[]readFloats(int length)Reads a float array in bulk.intreadInt()Reads a 4 byte int.int[]readInts(int length)Reads an int array in bulk.longreadLong()Reads an 8 byte long.long[]readLongs(int length)Reads a long array in bulk.shortreadShort()Reads a 2 byte short.short[]readShorts(int length)Reads a short array in bulk.-
Methods inherited from class com.esotericsoftware.kryo.io.Input
available, canReadInt, canReadLong, canReadVarInt, canReadVarLong, close, end, fill, getBuffer, getInputStream, getVariableLengthEncoding, limit, optional, position, read, read, readBytes, readBytes, readInt, readInts, readLong, readLongs, readShortUnsigned, readString, readStringBuilder, readVarDouble, readVarFloat, readVarInt, readVarIntFlag, readVarIntFlag, readVarLong, require, reset, setBuffer, setBuffer, setInputStream, setLimit, setPosition, setTotal, setVariableLengthEncoding, skip, skip, total
-
-
-
-
Constructor Detail
-
UnsafeInput
public UnsafeInput()
Creates an uninitialized Input,Input.setBuffer(byte[])must be called before the Input is used.
-
UnsafeInput
public UnsafeInput(int bufferSize)
Creates a new Input for reading from a byte[] buffer.- Parameters:
bufferSize- The size of the buffer. An exception is thrown if more bytes than this are read andInput.fill(byte[], int, int)does not supply more bytes.
-
UnsafeInput
public UnsafeInput(byte[] buffer)
Creates a new Input for reading from a byte[] buffer.- Parameters:
buffer- An exception is thrown if more bytes than this are read andInput.fill(byte[], int, int)does not supply more bytes.
-
UnsafeInput
public UnsafeInput(byte[] buffer, int offset, int count)Creates a new Input for reading from a byte[] buffer.- Parameters:
buffer- An exception is thrown if more bytes than this are read andInput.fill(byte[], int, int)does not supply more bytes.
-
UnsafeInput
public UnsafeInput(java.io.InputStream inputStream)
Creates a new Input for reading from an InputStream with a buffer size of 4096.
-
UnsafeInput
public UnsafeInput(java.io.InputStream inputStream, int bufferSize)Creates a new Input for reading from an InputStream with the specified buffer size.
-
-
Method Detail
-
read
public int read() throws KryoExceptionDescription copied from class:InputReads a single byte as an int from 0 to 255, or -1 if there are no more bytes are available.- Overrides:
readin classInput- Throws:
KryoException
-
readByte
public byte readByte() throws KryoExceptionDescription copied from class:InputReads a single byte.- Overrides:
readBytein classInput- Throws:
KryoException
-
readByteUnsigned
public int readByteUnsigned() throws KryoExceptionDescription copied from class:InputReads a byte as an int from 0 to 255.- Overrides:
readByteUnsignedin classInput- Throws:
KryoException
-
readInt
public int readInt() throws KryoExceptionDescription copied from class:InputReads a 4 byte int.- Overrides:
readIntin classInput- Throws:
KryoException
-
readLong
public long readLong() throws KryoExceptionDescription copied from class:InputReads an 8 byte long.- Overrides:
readLongin classInput- Throws:
KryoException
-
readFloat
public float readFloat() throws KryoExceptionDescription copied from class:InputReads a 4 byte float.- Overrides:
readFloatin classInput- Throws:
KryoException
-
readDouble
public double readDouble() throws KryoExceptionDescription copied from class:InputReads an 8 byte double.- Overrides:
readDoublein classInput- Throws:
KryoException
-
readShort
public short readShort() throws KryoExceptionDescription copied from class:InputReads a 2 byte short.- Overrides:
readShortin classInput- Throws:
KryoException
-
readChar
public char readChar() throws KryoExceptionDescription copied from class:InputReads a 2 byte char.- Overrides:
readCharin classInput- Throws:
KryoException
-
readBoolean
public boolean readBoolean() throws KryoExceptionDescription copied from class:InputReads a 1 byte boolean.- Overrides:
readBooleanin classInput- Throws:
KryoException
-
readInts
public int[] readInts(int length) throws KryoExceptionDescription copied from class:InputReads an int array in bulk. This may be more efficient than reading them individually.- Overrides:
readIntsin classInput- Throws:
KryoException
-
readLongs
public long[] readLongs(int length) throws KryoExceptionDescription copied from class:InputReads a long array in bulk. This may be more efficient than reading them individually.- Overrides:
readLongsin classInput- Throws:
KryoException
-
readFloats
public float[] readFloats(int length) throws KryoExceptionDescription copied from class:InputReads a float array in bulk. This may be more efficient than reading them individually.- Overrides:
readFloatsin classInput- Throws:
KryoException
-
readDoubles
public double[] readDoubles(int length) throws KryoExceptionDescription copied from class:InputReads a double array in bulk. This may be more efficient than reading them individually.- Overrides:
readDoublesin classInput- Throws:
KryoException
-
readShorts
public short[] readShorts(int length) throws KryoExceptionDescription copied from class:InputReads a short array in bulk. This may be more efficient than reading them individually.- Overrides:
readShortsin classInput- Throws:
KryoException
-
readChars
public char[] readChars(int length) throws KryoExceptionDescription copied from class:InputReads a char array in bulk. This may be more efficient than reading them individually.- Overrides:
readCharsin classInput- Throws:
KryoException
-
readBooleans
public boolean[] readBooleans(int length) throws KryoExceptionDescription copied from class:InputReads a boolean array in bulk. This may be more efficient than reading them individually.- Overrides:
readBooleansin classInput- Throws:
KryoException
-
readBytes
public void readBytes(byte[] bytes, int offset, int count) throws KryoExceptionDescription copied from class:InputReads count bytes and writes them to the specified byte[], starting at offset.- Overrides:
readBytesin classInput- Throws:
KryoException
-
readBytes
public void readBytes(java.lang.Object to, long offset, int count) throws KryoExceptionRead count bytes and write them to the object at the given offset inside the in-memory representation of the object.- Throws:
KryoException
-
-