public class UnsafeByteBufferOutput extends ByteBufferOutput
ByteBufferOutput that writes data to a direct ByteBuffer (off-heap memory) 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.
byteBufferbuffer, capacity, maxCapacity, outputStream, position, total, varEncoding| Constructor and Description |
|---|
UnsafeByteBufferOutput()
Creates an uninitialized Output,
ByteBufferOutput.setBuffer(ByteBuffer) must be called before the Output is used. |
UnsafeByteBufferOutput(int bufferSize)
Creates a new Output for writing to a direct
ByteBuffer. |
UnsafeByteBufferOutput(int bufferSize,
int maxBufferSize)
Creates a new Output for writing to a direct ByteBuffer.
|
UnsafeByteBufferOutput(long address,
int size)
Creates a new Output for writing to a ByteBuffer representing the memory region at the specified address and size.
|
UnsafeByteBufferOutput(java.io.OutputStream outputStream)
Creates a new Output for writing to an OutputStream.
|
UnsafeByteBufferOutput(java.io.OutputStream outputStream,
int bufferSize)
Creates a new Output for writing to an OutputStream with the specified buffer size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dispose()
Releases the byte buffer immediately, rather than waiting for GC.
|
protected boolean |
require(int required)
Ensures the buffer is large enough to read the specified number of bytes.
|
void |
setBuffer(java.nio.ByteBuffer buffer,
int maxBufferSize)
Sets a new buffer to write to.
|
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(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.
|
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.
|
close, flush, getBuffer, getByteBuffer, getOutputStream, reset, setBuffer, setBuffer, setBuffer, setBuffer, setPosition, toBytes, write, write, writeAscii, writeBytes, writeString, writeVarInt, writeVarIntFlag, writeVarLonggetMaxCapacity, getVariableLengthEncoding, intLength, longLength, position, setOutputStream, setVariableLengthEncoding, total, varIntLength, varLongLength, writeInt, writeInts, writeLong, writeLongs, writeVarDouble, writeVarFloatpublic UnsafeByteBufferOutput()
ByteBufferOutput.setBuffer(ByteBuffer) must be called before the Output is used.public UnsafeByteBufferOutput(int bufferSize)
ByteBuffer.bufferSize - The size of the buffer. An exception is thrown if more bytes than this are written and ByteBufferOutput.flush()
does not empty the buffer.public UnsafeByteBufferOutput(int bufferSize,
int maxBufferSize)
bufferSize - The initial size of the buffer.maxBufferSize - If ByteBufferOutput.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.public UnsafeByteBufferOutput(java.io.OutputStream outputStream)
public UnsafeByteBufferOutput(java.io.OutputStream outputStream,
int bufferSize)
public UnsafeByteBufferOutput(long address,
int size)
public void setBuffer(java.nio.ByteBuffer buffer,
int maxBufferSize)
ByteBufferOutputOutputStream is set to null.setBuffer in class ByteBufferOutputmaxBufferSize - If ByteBufferOutput.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.protected boolean require(int required)
throws KryoException
Outputrequire in class ByteBufferOutputKryoExceptionpublic void dispose()
public void write(int value)
throws KryoException
Outputwrite in class ByteBufferOutputKryoExceptionpublic void writeByte(byte value)
throws KryoException
writeByte in class ByteBufferOutputKryoExceptionpublic void writeByte(int value)
throws KryoException
writeByte in class ByteBufferOutputKryoExceptionpublic void writeInt(int value)
throws KryoException
OutputwriteInt in class ByteBufferOutputKryoExceptionpublic void writeLong(long value)
throws KryoException
OutputwriteLong in class ByteBufferOutputKryoExceptionpublic void writeFloat(float value)
throws KryoException
OutputwriteFloat in class ByteBufferOutputKryoExceptionpublic void writeDouble(double value)
throws KryoException
OutputwriteDouble in class ByteBufferOutputKryoExceptionpublic void writeShort(int value)
throws KryoException
OutputwriteShort in class ByteBufferOutputKryoExceptionpublic void writeChar(char value)
throws KryoException
OutputwriteChar in class ByteBufferOutputKryoExceptionpublic void writeBoolean(boolean value)
throws KryoException
OutputwriteBoolean in class ByteBufferOutputKryoExceptionpublic void writeInts(int[] array,
int offset,
int count)
throws KryoException
OutputwriteInts in class ByteBufferOutputKryoExceptionpublic void writeLongs(long[] array,
int offset,
int count)
throws KryoException
OutputwriteLongs in class ByteBufferOutputKryoExceptionpublic void writeFloats(float[] array,
int offset,
int count)
throws KryoException
OutputwriteFloats in class ByteBufferOutputKryoExceptionpublic void writeDoubles(double[] array,
int offset,
int count)
throws KryoException
OutputwriteDoubles in class ByteBufferOutputKryoExceptionpublic void writeShorts(short[] array,
int offset,
int count)
throws KryoException
OutputwriteShorts in class ByteBufferOutputKryoExceptionpublic void writeChars(char[] array,
int offset,
int count)
throws KryoException
OutputwriteChars in class ByteBufferOutputKryoExceptionpublic void writeBooleans(boolean[] array,
int offset,
int count)
throws KryoException
OutputwriteBooleans in class ByteBufferOutputKryoExceptionpublic void writeBytes(byte[] array,
int offset,
int count)
throws KryoException
OutputwriteBytes in class ByteBufferOutputKryoExceptionpublic void writeBytes(java.lang.Object from,
long offset,
int count)
throws KryoException
KryoExceptionCopyright © 2019. All Rights Reserved.