public class ByteBufferOutput extends Output
Output that uses a ByteBuffer rather than a byte[].
Note that the byte[] buffer is not used. Code taking an Output and expecting the byte[] to be used may not
work correctly.
| Modifier and Type | Field and Description |
|---|---|
protected java.nio.ByteBuffer |
byteBuffer |
buffer, capacity, maxCapacity, outputStream, position, total, varEncoding| Constructor and Description |
|---|
ByteBufferOutput()
Creates an uninitialized Output,
setBuffer(ByteBuffer) must be called before the Output is used. |
ByteBufferOutput(java.nio.ByteBuffer buffer)
Creates a new Output for writing to a ByteBuffer.
|
ByteBufferOutput(java.nio.ByteBuffer buffer,
int maxBufferSize)
Creates a new Output for writing to a ByteBuffer.
|
ByteBufferOutput(int bufferSize)
Creates a new Output for writing to a direct
ByteBuffer. |
ByteBufferOutput(int bufferSize,
int maxBufferSize)
Creates a new Output for writing to a direct ByteBuffer.
|
ByteBufferOutput(java.io.OutputStream outputStream) |
ByteBufferOutput(java.io.OutputStream outputStream,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Flushes any buffered bytes and closes the underlying OutputStream, if any.
|
void |
flush()
Flushes the buffered bytes.
|
byte[] |
getBuffer()
Deprecated.
|
java.nio.ByteBuffer |
getByteBuffer()
Returns the buffer.
|
java.io.OutputStream |
getOutputStream() |
protected boolean |
require(int required)
Ensures the buffer is large enough to read the specified number of bytes.
|
void |
reset()
Sets the position and total to 0.
|
void |
setBuffer(byte[] buffer)
Deprecated.
|
void |
setBuffer(byte[] buffer,
int maxBufferSize)
Deprecated.
|
void |
setBuffer(byte[] bytes,
int offset,
int count)
Allocates a new direct ByteBuffer with the specified bytes and sets it as the new buffer.
|
void |
setBuffer(java.nio.ByteBuffer buffer)
Sets a new buffer to write to.
|
void |
setBuffer(java.nio.ByteBuffer buffer,
int maxBufferSize)
Sets a new buffer to write to.
|
void |
setPosition(int position)
Sets the current position in the buffer.
|
byte[] |
toBytes()
Allocates and returns a new byte[] containing the bytes currently in the buffer between 0 and
Output.position(). |
void |
write(byte[] bytes)
Writes the bytes.
|
void |
write(byte[] bytes,
int offset,
int length)
Writes the bytes.
|
void |
write(int value)
Writes a byte.
|
void |
writeAscii(java.lang.String value)
Writes a string that is known to contain only ASCII characters.
|
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[] bytes)
Writes the bytes.
|
void |
writeBytes(byte[] bytes,
int offset,
int count)
Writes the bytes.
|
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.
|
void |
writeString(java.lang.String value)
Writes the length and string, or null.
|
int |
writeVarInt(int value,
boolean optimizePositive)
Writes a 1-5 byte int.
|
int |
writeVarIntFlag(boolean flag,
int value,
boolean optimizePositive)
Writes a 1-5 byte int, encoding the boolean value with a bit flag.
|
int |
writeVarLong(long value,
boolean optimizePositive)
Writes a 1-9 byte long.
|
getMaxCapacity, getVariableLengthEncoding, intLength, longLength, position, setOutputStream, setVariableLengthEncoding, total, varIntLength, varLongLength, writeInt, writeInts, writeLong, writeLongs, writeVarDouble, writeVarFloatpublic ByteBufferOutput()
setBuffer(ByteBuffer) must be called before the Output is used.public ByteBufferOutput(int bufferSize)
ByteBuffer.bufferSize - The size of the buffer. An exception is thrown if more bytes than this are written and flush()
does not empty the buffer.public ByteBufferOutput(int bufferSize,
int maxBufferSize)
bufferSize - The initial size of the buffer.maxBufferSize - If 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 ByteBufferOutput(java.nio.ByteBuffer buffer)
public ByteBufferOutput(java.nio.ByteBuffer buffer,
int maxBufferSize)
maxBufferSize - If 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 ByteBufferOutput(java.io.OutputStream outputStream)
Output.Output(OutputStream)public ByteBufferOutput(java.io.OutputStream outputStream,
int bufferSize)
Output.Output(OutputStream, int)public java.io.OutputStream getOutputStream()
getOutputStream in class Outputpublic byte[] getBuffer()
UnsupportedOperationException because this output uses a ByteBuffer, not a byte[].getBuffer in class OutputgetByteBuffer()public void setBuffer(byte[] buffer)
UnsupportedOperationException because this output uses a ByteBuffer, not a byte[].setBuffer in class OutputgetByteBuffer()public void setBuffer(byte[] buffer,
int maxBufferSize)
UnsupportedOperationException because this output uses a ByteBuffer, not a byte[].setBuffer in class OutputmaxBufferSize - If Output.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.getByteBuffer()public void setBuffer(byte[] bytes,
int offset,
int count)
setBuffer(ByteBuffer)public void setBuffer(java.nio.ByteBuffer buffer)
setBuffer(ByteBuffer, int)public void setBuffer(java.nio.ByteBuffer buffer,
int maxBufferSize)
OutputStream is set to null.maxBufferSize - If 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 java.nio.ByteBuffer getByteBuffer()
Output.position() are the data that has been written.public byte[] toBytes()
OutputOutput.position().public void setPosition(int position)
OutputsetPosition in class Outputpublic void reset()
Outputreset in interface Pool.Poolablereset in class Outputprotected boolean require(int required)
throws KryoException
Outputrequire in class OutputKryoExceptionpublic void flush()
throws KryoException
OutputOutputStream, if any, and sets the position to 0. Can be overridden to flush the bytes somewhere else.flush in interface java.io.Flushableflush in class OutputKryoExceptionpublic void close()
throws KryoException
Outputclose in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class OutputKryoExceptionpublic void write(int value)
throws KryoException
Outputwrite in class OutputKryoExceptionpublic void write(byte[] bytes)
throws KryoException
Outputwrite in class OutputKryoExceptionpublic void write(byte[] bytes,
int offset,
int length)
throws KryoException
Outputwrite in class OutputKryoExceptionpublic void writeByte(byte value)
throws KryoException
writeByte in class OutputKryoExceptionpublic void writeByte(int value)
throws KryoException
writeByte in class OutputKryoExceptionpublic void writeBytes(byte[] bytes)
throws KryoException
OutputwriteBytes in class OutputKryoExceptionpublic void writeBytes(byte[] bytes,
int offset,
int count)
throws KryoException
OutputwriteBytes in class OutputKryoExceptionpublic void writeInt(int value)
throws KryoException
OutputwriteInt in class OutputKryoExceptionpublic int writeVarInt(int value,
boolean optimizePositive)
throws KryoException
OutputwriteVarInt in class OutputoptimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (5 bytes).KryoExceptionOutput.varIntLength(int, boolean)public int writeVarIntFlag(boolean flag,
int value,
boolean optimizePositive)
throws KryoException
OutputwriteVarIntFlag in class OutputoptimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (5 bytes).KryoExceptionpublic void writeLong(long value)
throws KryoException
OutputwriteLong in class OutputKryoExceptionpublic int writeVarLong(long value,
boolean optimizePositive)
throws KryoException
OutputwriteVarLong in class OutputoptimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (9 bytes).KryoExceptionOutput.varLongLength(long, boolean)public void writeFloat(float value)
throws KryoException
OutputwriteFloat in class OutputKryoExceptionpublic void writeDouble(double value)
throws KryoException
OutputwriteDouble in class OutputKryoExceptionpublic void writeShort(int value)
throws KryoException
OutputwriteShort in class OutputKryoExceptionpublic void writeChar(char value)
throws KryoException
OutputwriteChar in class OutputKryoExceptionpublic void writeBoolean(boolean value)
throws KryoException
OutputwriteBoolean in class OutputKryoExceptionpublic void writeString(java.lang.String value)
throws KryoException
OutputOutput.writeAscii(String) may be used. The string can be read using
Input.readString() or Input.readStringBuilder().writeString in class Outputvalue - May be null.KryoExceptionpublic void writeAscii(java.lang.String value)
throws KryoException
OutputOutput.writeString(String). The string can be read using Input.readString() or
Input.readStringBuilder().writeAscii in class Outputvalue - May be null.KryoExceptionpublic void writeInts(int[] array,
int offset,
int count)
throws KryoException
OutputwriteInts in class OutputKryoExceptionpublic void writeLongs(long[] array,
int offset,
int count)
throws KryoException
OutputwriteLongs in class OutputKryoExceptionpublic void writeFloats(float[] array,
int offset,
int count)
throws KryoException
OutputwriteFloats in class OutputKryoExceptionpublic void writeDoubles(double[] array,
int offset,
int count)
throws KryoException
OutputwriteDoubles in class OutputKryoExceptionpublic void writeShorts(short[] array,
int offset,
int count)
throws KryoException
OutputwriteShorts in class OutputKryoExceptionpublic void writeChars(char[] array,
int offset,
int count)
throws KryoException
OutputwriteChars in class OutputKryoExceptionpublic void writeBooleans(boolean[] array,
int offset,
int count)
throws KryoException
OutputwriteBooleans in class OutputKryoExceptionCopyright © 2019. All Rights Reserved.