public class Output extends OutputStream
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buffer |
protected int |
capacity |
protected int |
maxCapacity |
protected OutputStream |
outputStream |
protected int |
position |
protected long |
total |
| Constructor and Description |
|---|
Output()
Creates an uninitialized Output.
|
Output(byte[] buffer)
Creates a new Output for writing to a byte array.
|
Output(byte[] buffer,
int maxBufferSize)
Creates a new Output for writing to a byte array.
|
Output(int bufferSize)
Creates a new Output for writing to a byte array.
|
Output(int bufferSize,
int maxBufferSize)
Creates a new Output for writing to a byte array.
|
Output(OutputStream outputStream)
Creates a new Output for writing to an OutputStream.
|
Output(OutputStream outputStream,
int bufferSize)
Creates a new Output for writing to an OutputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Sets the position and total to zero.
|
void |
close()
Flushes any buffered bytes and closes the underlying OutputStream, if any.
|
void |
flush()
Writes the buffered bytes to the underlying OutputStream, if any.
|
byte[] |
getBuffer()
Returns the buffer.
|
OutputStream |
getOutputStream() |
static int |
intLength(int value,
boolean optimizePositive)
Returns the number of bytes that would be written with
writeInt(int, boolean). |
static int |
longLength(long value,
boolean optimizePositive)
Returns the number of bytes that would be written with
writeLong(long, boolean). |
int |
position()
Returns the current position in the buffer.
|
protected boolean |
require(int required) |
void |
setBuffer(byte[] buffer)
Sets the buffer that will be written to.
|
void |
setBuffer(byte[] buffer,
int maxBufferSize)
Sets the buffer that will be written to.
|
void |
setOutputStream(OutputStream outputStream)
Sets a new OutputStream.
|
void |
setPosition(int position)
Sets the current position in the buffer.
|
byte[] |
toBytes()
Returns a new byte array containing the bytes currently in the buffer between zero and
position(). |
long |
total()
Returns the total number of bytes written.
|
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(String value)
Writes a string that is known to contain only ASCII characters.
|
void |
writeBoolean(boolean value)
Writes a 1 byte boolean.
|
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[] object)
Bulk output of a char array.
|
void |
writeDouble(double value)
Writes an 8 byte double.
|
int |
writeDouble(double value,
double precision,
boolean optimizePositive)
Writes a 1-9 byte double with reduced precision.
|
void |
writeDoubles(double[] object)
Bulk output of a double array.
|
void |
writeFloat(float value)
Writes a 4 byte float.
|
int |
writeFloat(float value,
float precision,
boolean optimizePositive)
Writes a 1-5 byte float with reduced precision.
|
void |
writeFloats(float[] object)
Bulk output of a float array.
|
void |
writeInt(int value)
Writes a 4 byte int.
|
int |
writeInt(int value,
boolean optimizePositive)
Writes a 1-5 byte int.
|
void |
writeInts(int[] object)
Bulk output of an int array.
|
void |
writeInts(int[] object,
boolean optimizePositive)
Bulk output of an int array.
|
void |
writeLong(long value)
Writes an 8 byte long.
|
int |
writeLong(long value,
boolean optimizePositive)
Writes a 1-9 byte long.
|
void |
writeLongs(long[] object)
Bulk output of an long array.
|
void |
writeLongs(long[] object,
boolean optimizePositive)
Bulk output of an long array.
|
void |
writeShort(int value)
Writes a 2 byte short.
|
void |
writeShorts(short[] object)
Bulk output of a short array.
|
void |
writeString(CharSequence value)
Writes the length and CharSequence as UTF8, or null.
|
void |
writeString(String value)
Writes the length and string, or null.
|
int |
writeVarInt(int value,
boolean optimizePositive)
Writes a 1-5 byte int.
|
int |
writeVarLong(long value,
boolean optimizePositive)
Writes a 1-9 byte long.
|
protected int maxCapacity
protected long total
protected int position
protected int capacity
protected byte[] buffer
protected OutputStream outputStream
public Output()
setBuffer(byte[], int) must be called before the Output is used.public Output(int bufferSize)
bufferSize - The initial and maximum size of the buffer. An exception is thrown if this size is exceeded.public Output(int bufferSize,
int maxBufferSize)
bufferSize - The initial size of the buffer.maxBufferSize - The buffer is doubled as needed until it exceeds maxBufferSize and an exception is thrown. Can be -1
for no maximum.public Output(byte[] buffer)
setBuffer(byte[])public Output(byte[] buffer,
int maxBufferSize)
setBuffer(byte[], int)public Output(OutputStream outputStream)
public Output(OutputStream outputStream, int bufferSize)
public OutputStream getOutputStream()
public void setOutputStream(OutputStream outputStream)
outputStream - May be null.public void setBuffer(byte[] buffer)
setBuffer(byte[], int) is called with the specified buffer's length as
the maxBufferSize.public void setBuffer(byte[] buffer,
int maxBufferSize)
OutputStream is set to null.maxBufferSize - The buffer is doubled as needed until it exceeds maxBufferSize and an exception is thrown.public byte[] getBuffer()
position() are the data that has been written.public byte[] toBytes()
position().public int position()
public void setPosition(int position)
public long total()
public void clear()
protected boolean require(int required)
throws KryoException
KryoExceptionpublic void flush()
throws KryoException
flush in interface Flushableflush in class OutputStreamKryoExceptionpublic void close()
throws KryoException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamKryoExceptionpublic void write(int value)
throws KryoException
write in class OutputStreamKryoExceptionpublic void write(byte[] bytes)
throws KryoException
write in class OutputStreamKryoExceptionpublic void write(byte[] bytes,
int offset,
int length)
throws KryoException
write in class OutputStreamKryoExceptionpublic void writeByte(byte value)
throws KryoException
KryoExceptionpublic void writeByte(int value)
throws KryoException
KryoExceptionpublic void writeBytes(byte[] bytes)
throws KryoException
KryoExceptionpublic void writeBytes(byte[] bytes,
int offset,
int count)
throws KryoException
KryoExceptionpublic void writeInt(int value)
throws KryoException
KryoExceptionpublic int writeInt(int value,
boolean optimizePositive)
throws KryoException
optimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (5 bytes).KryoExceptionpublic int writeVarInt(int value,
boolean optimizePositive)
throws KryoException
optimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (5 bytes).KryoExceptionpublic void writeString(String value) throws KryoException
writeAscii(String) may be used. The string can be read using
Input.readString() or Input.readStringBuilder().value - May be null.KryoExceptionpublic void writeString(CharSequence value) throws KryoException
Input.readString() or
Input.readStringBuilder().value - May be null.KryoExceptionpublic void writeAscii(String value) throws KryoException
writeString(String). The string can be read using Input.readString() or
Input.readStringBuilder().value - May be null.KryoExceptionpublic void writeFloat(float value)
throws KryoException
KryoExceptionpublic int writeFloat(float value,
float precision,
boolean optimizePositive)
throws KryoException
optimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (5 bytes).KryoExceptionpublic void writeShort(int value)
throws KryoException
KryoExceptionpublic void writeLong(long value)
throws KryoException
KryoExceptionpublic int writeLong(long value,
boolean optimizePositive)
throws KryoException
optimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (9 bytes).KryoExceptionpublic int writeVarLong(long value,
boolean optimizePositive)
throws KryoException
optimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (9 bytes).KryoExceptionpublic void writeBoolean(boolean value)
throws KryoException
KryoExceptionpublic void writeChar(char value)
throws KryoException
KryoExceptionpublic void writeDouble(double value)
throws KryoException
KryoExceptionpublic int writeDouble(double value,
double precision,
boolean optimizePositive)
throws KryoException
optimizePositive - If true, small positive numbers will be more efficient (1 byte) and small negative numbers will be
inefficient (9 bytes).KryoExceptionpublic static int intLength(int value,
boolean optimizePositive)
writeInt(int, boolean).public static int longLength(long value,
boolean optimizePositive)
writeLong(long, boolean).public void writeInts(int[] object,
boolean optimizePositive)
throws KryoException
KryoExceptionpublic void writeLongs(long[] object,
boolean optimizePositive)
throws KryoException
KryoExceptionpublic void writeInts(int[] object)
throws KryoException
KryoExceptionpublic void writeLongs(long[] object)
throws KryoException
KryoExceptionpublic void writeFloats(float[] object)
throws KryoException
KryoExceptionpublic void writeShorts(short[] object)
throws KryoException
KryoExceptionpublic void writeChars(char[] object)
throws KryoException
KryoExceptionpublic void writeDoubles(double[] object)
throws KryoException
KryoExceptionCopyright © 2023. All rights reserved.