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,java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class UnsafeOutput extends Output
AnOutputthat 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.unsafecan 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(java.io.OutputStream outputStream)Creates a new Output for writing to an OutputStream.UnsafeOutput(java.io.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 voidwrite(int value)Writes a byte.voidwriteBoolean(boolean value)Writes a 1 byte boolean.voidwriteBooleans(boolean[] array, int offset, int count)Writes a boolean array in bulk.voidwriteByte(byte value)voidwriteByte(int value)voidwriteBytes(byte[] array, int offset, int count)Writes the bytes.voidwriteBytes(java.lang.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.voidwriteChar(char value)Writes a 2 byte char.voidwriteChars(char[] array, int offset, int count)Writes a char array in bulk.voidwriteDouble(double value)Writes an 8 byte double.voidwriteDoubles(double[] array, int offset, int count)Writes a double array in bulk.voidwriteFloat(float value)Writes a 4 byte float.voidwriteFloats(float[] array, int offset, int count)Writes a float array in bulk.voidwriteInt(int value)Writes a 4 byte int.voidwriteInts(int[] array, int offset, int count)Writes an int array in bulk.voidwriteLong(long value)Writes an 8 byte long.voidwriteLongs(long[] array, int offset, int count)Writes a long array in bulk.voidwriteShort(int value)Writes a 2 byte short.voidwriteShorts(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
-
-
-
-
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(java.io.OutputStream outputStream)
Creates a new Output for writing to an OutputStream. A buffer size of 4096 is used.
-
UnsafeOutput
public UnsafeOutput(java.io.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 KryoExceptionDescription copied from class:OutputWrites a byte.- Overrides:
writein classOutput- Throws:
KryoException
-
writeByte
public void writeByte(byte value) throws KryoException- Overrides:
writeBytein classOutput- Throws:
KryoException
-
writeByte
public void writeByte(int value) throws KryoException- Overrides:
writeBytein classOutput- Throws:
KryoException
-
writeInt
public void writeInt(int value) throws KryoExceptionDescription copied from class:OutputWrites a 4 byte int.- Overrides:
writeIntin classOutput- Throws:
KryoException
-
writeLong
public void writeLong(long value) throws KryoExceptionDescription copied from class:OutputWrites an 8 byte long.- Overrides:
writeLongin classOutput- Throws:
KryoException
-
writeFloat
public void writeFloat(float value) throws KryoExceptionDescription copied from class:OutputWrites a 4 byte float.- Overrides:
writeFloatin classOutput- Throws:
KryoException
-
writeDouble
public void writeDouble(double value) throws KryoExceptionDescription copied from class:OutputWrites an 8 byte double.- Overrides:
writeDoublein classOutput- Throws:
KryoException
-
writeShort
public void writeShort(int value) throws KryoExceptionDescription copied from class:OutputWrites a 2 byte short.- Overrides:
writeShortin classOutput- Throws:
KryoException
-
writeChar
public void writeChar(char value) throws KryoExceptionDescription copied from class:OutputWrites a 2 byte char.- Overrides:
writeCharin classOutput- Throws:
KryoException
-
writeBoolean
public void writeBoolean(boolean value) throws KryoExceptionDescription copied from class:OutputWrites a 1 byte boolean.- Overrides:
writeBooleanin classOutput- Throws:
KryoException
-
writeInts
public void writeInts(int[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites an int array in bulk. This may be more efficient than writing them individually.- Overrides:
writeIntsin classOutput- Throws:
KryoException
-
writeLongs
public void writeLongs(long[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites a long array in bulk. This may be more efficient than writing them individually.- Overrides:
writeLongsin classOutput- Throws:
KryoException
-
writeFloats
public void writeFloats(float[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites a float array in bulk. This may be more efficient than writing them individually.- Overrides:
writeFloatsin classOutput- Throws:
KryoException
-
writeDoubles
public void writeDoubles(double[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites a double array in bulk. This may be more efficient than writing them individually.- Overrides:
writeDoublesin classOutput- Throws:
KryoException
-
writeShorts
public void writeShorts(short[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites a short array in bulk. This may be more efficient than writing them individually.- Overrides:
writeShortsin classOutput- Throws:
KryoException
-
writeChars
public void writeChars(char[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites a char array in bulk. This may be more efficient than writing them individually.- Overrides:
writeCharsin classOutput- Throws:
KryoException
-
writeBooleans
public void writeBooleans(boolean[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites a boolean array in bulk. This may be more efficient than writing them individually.- Overrides:
writeBooleansin classOutput- Throws:
KryoException
-
writeBytes
public void writeBytes(byte[] array, int offset, int count) throws KryoExceptionDescription copied from class:OutputWrites the bytes. Note the number of bytes is not written.- Overrides:
writeBytesin classOutput- Throws:
KryoException
-
writeBytes
public void writeBytes(java.lang.Object from, long offset, int count) throws KryoExceptionWrite count bytes to the byte buffer, reading from the given offset inside the in-memory representation of the object.- Throws:
KryoException
-
-