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.
byteBuffer
buffer, 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, writeVarLong
getMaxCapacity, getVariableLengthEncoding, intLength, longLength, position, setOutputStream, setVariableLengthEncoding, total, varIntLength, varLongLength, writeInt, writeInts, writeLong, writeLongs, writeVarDouble, writeVarFloat
public 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)
ByteBufferOutput
OutputStream
is set to null.setBuffer
in class ByteBufferOutput
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.protected boolean require(int required) throws KryoException
Output
require
in class ByteBufferOutput
KryoException
public void dispose()
public void write(int value) throws KryoException
Output
write
in class ByteBufferOutput
KryoException
public void writeByte(byte value) throws KryoException
writeByte
in class ByteBufferOutput
KryoException
public void writeByte(int value) throws KryoException
writeByte
in class ByteBufferOutput
KryoException
public void writeInt(int value) throws KryoException
Output
writeInt
in class ByteBufferOutput
KryoException
public void writeLong(long value) throws KryoException
Output
writeLong
in class ByteBufferOutput
KryoException
public void writeFloat(float value) throws KryoException
Output
writeFloat
in class ByteBufferOutput
KryoException
public void writeDouble(double value) throws KryoException
Output
writeDouble
in class ByteBufferOutput
KryoException
public void writeShort(int value) throws KryoException
Output
writeShort
in class ByteBufferOutput
KryoException
public void writeChar(char value) throws KryoException
Output
writeChar
in class ByteBufferOutput
KryoException
public void writeBoolean(boolean value) throws KryoException
Output
writeBoolean
in class ByteBufferOutput
KryoException
public void writeInts(int[] array, int offset, int count) throws KryoException
Output
writeInts
in class ByteBufferOutput
KryoException
public void writeLongs(long[] array, int offset, int count) throws KryoException
Output
writeLongs
in class ByteBufferOutput
KryoException
public void writeFloats(float[] array, int offset, int count) throws KryoException
Output
writeFloats
in class ByteBufferOutput
KryoException
public void writeDoubles(double[] array, int offset, int count) throws KryoException
Output
writeDoubles
in class ByteBufferOutput
KryoException
public void writeShorts(short[] array, int offset, int count) throws KryoException
Output
writeShorts
in class ByteBufferOutput
KryoException
public void writeChars(char[] array, int offset, int count) throws KryoException
Output
writeChars
in class ByteBufferOutput
KryoException
public void writeBooleans(boolean[] array, int offset, int count) throws KryoException
Output
writeBooleans
in class ByteBufferOutput
KryoException
public void writeBytes(byte[] array, int offset, int count) throws KryoException
Output
writeBytes
in class ByteBufferOutput
KryoException
public void writeBytes(java.lang.Object from, long offset, int count) throws KryoException
KryoException
Copyright © 2019. All Rights Reserved.