-
- All Implemented Interfaces:
-
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class MessageBufferPacker extends MessagePacker
MessagePacker that is useful to produce byte array output.
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.
-
-
Method Summary
Modifier and Type Method Description MessageBufferOutputreset(MessageBufferOutput out)Replaces underlying output. voidclear()Clears the written data. Array<byte>toByteArray()Gets copy of the written data as a byte array. MessageBuffertoMessageBuffer()Gets the written data as a MessageBuffer. List<MessageBuffer>toBufferList()Returns the written data as a list of MessageBuffer. intgetBufferSize()-
Methods inherited from class com.batch.android.msgpack.core.MessagePacker
addPayload, addPayload, close, flush, getTotalWrittenBytes, packArrayHeader, packBigInteger, packBinaryHeader, packBoolean, packByte, packDouble, packExtensionTypeHeader, packFloat, packInt, packLong, packMapHeader, packNil, packRawStringHeader, packShort, packString, packValue, writePayload, writePayload -
Methods inherited from class java.io.Closeable
close -
Methods inherited from class java.io.Flushable
flush -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
reset
MessageBufferOutput reset(MessageBufferOutput out)
Replaces underlying output.
This method flushes current internal buffer to the output, swaps it with the new given output, then returnsthe old output.
This method doesn't close the old output.
- Parameters:
out- new output
-
clear
void clear()
Clears the written data.
-
toByteArray
Array<byte> toByteArray()
Gets copy of the written data as a byte array.
If your application needs better performance and smaller memory consumption, you may prefer toMessageBuffer or toBufferList to avoid copying.
-
toMessageBuffer
MessageBuffer toMessageBuffer()
Gets the written data as a MessageBuffer.
Unlike toByteArray, this method omits copy of the contents if size of the written data is smallerthan a single buffer capacity.
-
toBufferList
List<MessageBuffer> toBufferList()
Returns the written data as a list of MessageBuffer.
Unlike toByteArray or toMessageBuffer, this is the fastest method that doesn'tcopy contents in any cases.
-
getBufferSize
int getBufferSize()
-
-
-
-