public class MessageBufferPacker extends MessagePacker
This class allocates a new buffer instead of resizing the buffer when data doesn't fit in the initial capacity. This is faster than ByteArrayOutputStream especially when size of written bytes is large because resizing a buffer usually needs to copy contents of the buffer.
out
Modifier | Constructor and Description |
---|---|
protected |
MessageBufferPacker(ArrayBufferOutput out,
MessagePack.PackerConfig config) |
protected |
MessageBufferPacker(MessagePack.PackerConfig config) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the written data.
|
MessageBufferOutput |
reset(MessageBufferOutput out)
Replaces underlying output.
|
java.util.List<MessageBuffer> |
toBufferList()
Returns the written data as a list of MessageBuffer.
|
byte[] |
toByteArray()
Gets copy of the written data as a byte array.
|
MessageBuffer |
toMessageBuffer()
Gets the written data as a MessageBuffer.
|
addPayload, addPayload, close, flush, getTotalWrittenBytes, packArrayHeader, packBigInteger, packBinaryHeader, packBoolean, packByte, packDouble, packExtensionTypeHeader, packFloat, packInt, packLong, packMapHeader, packNil, packRawStringHeader, packShort, packString, packValue, writePayload, writePayload
protected MessageBufferPacker(MessagePack.PackerConfig config)
protected MessageBufferPacker(ArrayBufferOutput out, MessagePack.PackerConfig config)
public MessageBufferOutput reset(MessageBufferOutput out) throws java.io.IOException
MessagePacker
This method flushes current internal buffer to the output, swaps it with the new given output, then returns the old output.
This method doesn't close the old output.
reset
in class MessagePacker
out
- new outputjava.io.IOException
- when underlying output throws IOExceptionpublic void clear()
public byte[] toByteArray()
If your application needs better performance and smaller memory consumption, you may prefer
toMessageBuffer()
or toBufferList()
to avoid copying.
public MessageBuffer toMessageBuffer()
Unlike toByteArray()
, this method omits copy of the contents if size of the written data is smaller
than a single buffer capacity.
public java.util.List<MessageBuffer> toBufferList()
Unlike toByteArray()
or toMessageBuffer()
, this is the fastest method that doesn't
copy contents in any cases.