public class Output
extends java.io.OutputStream
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(java.io.OutputStream outputStream)
Creates a new Output for writing to an OutputStream.
|
Output(java.io.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.
|
java.io.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.
|
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(java.io.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() . |
int |
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(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 |
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 |
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 |
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 |
writeInt(int value)
Writes a 4 byte int.
|
int |
writeInt(int value,
boolean optimizePositive)
Writes a 1-5 byte int.
|
void |
writeLong(long value)
Writes an 8 byte long.
|
int |
writeLong(long value,
boolean optimizePositive)
Writes a 1-9 byte long.
|
void |
writeShort(int value)
Writes a 2 byte short.
|
void |
writeString(java.lang.CharSequence value)
Writes the length and CharSequence as UTF8, or null.
|
void |
writeString(java.lang.String value)
Writes the length and string, or null.
|
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(java.io.OutputStream outputStream)
public Output(java.io.OutputStream outputStream, int bufferSize)
public java.io.OutputStream getOutputStream()
public void setOutputStream(java.io.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 int total()
public void clear()
public void flush() throws KryoException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
KryoException
public void close() throws KryoException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
KryoException
public void write(int value) throws KryoException
write
in class java.io.OutputStream
KryoException
public void write(byte[] bytes) throws KryoException
write
in class java.io.OutputStream
KryoException
public void write(byte[] bytes, int offset, int length) throws KryoException
write
in class java.io.OutputStream
KryoException
public void writeByte(byte value) throws KryoException
KryoException
public void writeByte(int value) throws KryoException
KryoException
public void writeBytes(byte[] bytes) throws KryoException
KryoException
public void writeBytes(byte[] bytes, int offset, int count) throws KryoException
KryoException
public void writeInt(int value) throws KryoException
KryoException
public 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).KryoException
public void writeString(java.lang.String value) throws KryoException
writeAscii(String)
may be used. The string can be read using
Input.readString()
or Input.readStringBuilder()
.value
- May be null.KryoException
public void writeString(java.lang.CharSequence value) throws KryoException
Input.readString()
or
Input.readStringBuilder()
.value
- May be null.KryoException
public void writeAscii(java.lang.String value) throws KryoException
writeString(String)
. The string can be read using Input.readString()
or
Input.readStringBuilder()
.value
- May be null.KryoException
public void writeFloat(float value) throws KryoException
KryoException
public 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).KryoException
public void writeShort(int value) throws KryoException
KryoException
public void writeLong(long value) throws KryoException
KryoException
public 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).KryoException
public void writeBoolean(boolean value) throws KryoException
KryoException
public void writeChar(char value) throws KryoException
KryoException
public void writeDouble(double value) throws KryoException
KryoException
public 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).KryoException
public static int intLength(int value, boolean optimizePositive)
writeInt(int, boolean)
.public static int longLength(long value, boolean optimizePositive)
writeLong(long, boolean)
.