Package com.esotericsoftware.kryo.unsafe
Class UnsafeOutput
- java.lang.Object
-
- java.io.OutputStream
-
- com.esotericsoftware.kryo.io.Output
-
- com.esotericsoftware.kryo.unsafe.UnsafeOutput
-
- All Implemented Interfaces:
Pool.Poolable
,Closeable
,Flushable
,AutoCloseable
public class UnsafeOutput extends Output
AnOutput
that reads data 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.unsafe
can be checked before using this class.This class may be much faster when
Output.setVariableLengthEncoding(boolean)
is false.- Author:
- Roman Levenstein
, Nathan Sweet
-
-
Field Summary
-
Fields inherited from class com.esotericsoftware.kryo.io.Output
buffer, capacity, maxCapacity, outputStream, position, total, varEncoding
-
-
Constructor Summary
Constructors Constructor Description UnsafeOutput()
Creates an uninitialized Output,Output.setBuffer(byte[], int)
must be called before the Output is used.UnsafeOutput(byte[] buffer)
Creates a new Output for writing to a byte[].UnsafeOutput(byte[] buffer, int maxBufferSize)
Creates a new Output for writing to a byte[].UnsafeOutput(int bufferSize)
Creates a new Output for writing to a byte[].UnsafeOutput(int bufferSize, int maxBufferSize)
Creates a new Output for writing to a byte[].UnsafeOutput(OutputStream outputStream)
Creates a new Output for writing to an OutputStream.UnsafeOutput(OutputStream outputStream, int bufferSize)
Creates a new Output for writing to an OutputStream with the specified buffer size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
write(int value)
Writes a byte.void
writeBoolean(boolean value)
Writes a 1 byte boolean.void
writeBooleans(boolean[] array, int offset, int count)
Writes a boolean array in bulk.void
writeByte(byte value)
void
writeByte(int value)
void
writeBytes(byte[] array, int offset, int count)
Writes the bytes.void
writeBytes(Object from, long offset, int count)
Write count bytes to the byte buffer, reading from the given offset inside the in-memory representation of the object.void
writeChar(char value)
Writes a 2 byte char.void
writeChars(char[] array, int offset, int count)
Writes a char array in bulk.void
writeDouble(double value)
Writes an 8 byte double.void
writeDoubles(double[] array, int offset, int count)
Writes a double array in bulk.void
writeFloat(float value)
Writes a 4 byte float.void
writeFloats(float[] array, int offset, int count)
Writes a float array in bulk.void
writeInt(int value)
Writes a 4 byte int.void
writeInts(int[] array, int offset, int count)
Writes an int array in bulk.void
writeLong(long value)
Writes an 8 byte long.void
writeLongs(long[] array, int offset, int count)
Writes a long array in bulk.void
writeShort(int value)
Writes a 2 byte short.void
writeShorts(short[] array, int offset, int count)
Writes a short array in bulk.-
Methods inherited from class com.esotericsoftware.kryo.io.Output
close, flush, getBuffer, getMaxCapacity, getOutputStream, getVariableLengthEncoding, intLength, longLength, position, require, reset, setBuffer, setBuffer, setOutputStream, setPosition, setVariableLengthEncoding, toBytes, total, varIntLength, varLongLength, write, write, writeAscii, writeBytes, writeInt, writeInts, writeLong, writeLongs, writeString, writeVarDouble, writeVarFloat, writeVarInt, writeVarIntFlag, writeVarLong
-
Methods inherited from class java.io.OutputStream
nullOutputStream
-
-
-
-
Constructor Detail
-
UnsafeOutput
public UnsafeOutput()
Creates an uninitialized Output,Output.setBuffer(byte[], int)
must be called before the Output is used.
-
UnsafeOutput
public UnsafeOutput(int bufferSize)
Creates a new Output for writing to a byte[].- Parameters:
bufferSize
- The size of the buffer. An exception is thrown if more bytes than this are written andOutput.flush()
does not empty the buffer.
-
UnsafeOutput
public UnsafeOutput(int bufferSize, int maxBufferSize)
Creates a new Output for writing to a byte[].- Parameters:
bufferSize
- The initial size of the buffer.maxBufferSize
- IfOutput.flush()
does not empty the buffer, the buffer is doubled as needed until it exceeds maxBufferSize and an exception is thrown. Can be -1 for no maximum.
-
UnsafeOutput
public UnsafeOutput(byte[] buffer)
Creates a new Output for writing to a byte[].- See Also:
Output.setBuffer(byte[])
-
UnsafeOutput
public UnsafeOutput(byte[] buffer, int maxBufferSize)
Creates a new Output for writing to a byte[].- See Also:
Output.setBuffer(byte[], int)
-
UnsafeOutput
public UnsafeOutput(OutputStream outputStream)
Creates a new Output for writing to an OutputStream. A buffer size of 4096 is used.
-
UnsafeOutput
public UnsafeOutput(OutputStream outputStream, int bufferSize)
Creates a new Output for writing to an OutputStream with the specified buffer size.
-
-
Method Detail
-
write
public void write(int value) throws KryoException
Description copied from class:Output
Writes a byte.- Overrides:
write
in classOutput
- Throws:
KryoException
-
writeByte
public void writeByte(byte value) throws KryoException
- Overrides:
writeByte
in classOutput
- Throws:
KryoException
-
writeByte
public void writeByte(int value) throws KryoException
- Overrides:
writeByte
in classOutput
- Throws:
KryoException
-
writeInt
public void writeInt(int value) throws KryoException
Description copied from class:Output
Writes a 4 byte int.- Overrides:
writeInt
in classOutput
- Throws:
KryoException
-
writeLong
public void writeLong(long value) throws KryoException
Description copied from class:Output
Writes an 8 byte long.- Overrides:
writeLong
in classOutput
- Throws:
KryoException
-
writeFloat
public void writeFloat(float value) throws KryoException
Description copied from class:Output
Writes a 4 byte float.- Overrides:
writeFloat
in classOutput
- Throws:
KryoException
-
writeDouble
public void writeDouble(double value) throws KryoException
Description copied from class:Output
Writes an 8 byte double.- Overrides:
writeDouble
in classOutput
- Throws:
KryoException
-
writeShort
public void writeShort(int value) throws KryoException
Description copied from class:Output
Writes a 2 byte short.- Overrides:
writeShort
in classOutput
- Throws:
KryoException
-
writeChar
public void writeChar(char value) throws KryoException
Description copied from class:Output
Writes a 2 byte char.- Overrides:
writeChar
in classOutput
- Throws:
KryoException
-
writeBoolean
public void writeBoolean(boolean value) throws KryoException
Description copied from class:Output
Writes a 1 byte boolean.- Overrides:
writeBoolean
in classOutput
- Throws:
KryoException
-
writeInts
public void writeInts(int[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes an int array in bulk. This may be more efficient than writing them individually.- Overrides:
writeInts
in classOutput
- Throws:
KryoException
-
writeLongs
public void writeLongs(long[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes a long array in bulk. This may be more efficient than writing them individually.- Overrides:
writeLongs
in classOutput
- Throws:
KryoException
-
writeFloats
public void writeFloats(float[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes a float array in bulk. This may be more efficient than writing them individually.- Overrides:
writeFloats
in classOutput
- Throws:
KryoException
-
writeDoubles
public void writeDoubles(double[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes a double array in bulk. This may be more efficient than writing them individually.- Overrides:
writeDoubles
in classOutput
- Throws:
KryoException
-
writeShorts
public void writeShorts(short[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes a short array in bulk. This may be more efficient than writing them individually.- Overrides:
writeShorts
in classOutput
- Throws:
KryoException
-
writeChars
public void writeChars(char[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes a char array in bulk. This may be more efficient than writing them individually.- Overrides:
writeChars
in classOutput
- Throws:
KryoException
-
writeBooleans
public void writeBooleans(boolean[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes a boolean array in bulk. This may be more efficient than writing them individually.- Overrides:
writeBooleans
in classOutput
- Throws:
KryoException
-
writeBytes
public void writeBytes(byte[] array, int offset, int count) throws KryoException
Description copied from class:Output
Writes the bytes. Note the number of bytes is not written.- Overrides:
writeBytes
in classOutput
- Throws:
KryoException
-
writeBytes
public void writeBytes(Object from, long offset, int count) throws KryoException
Write count bytes to the byte buffer, reading from the given offset inside the in-memory representation of the object.- Throws:
KryoException
-
-