Class MsgPackTokenWriter
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,RecordWriter,TokenWriter
TokenWriter surface for the MessagePack format.
MessagePack containers are length-prefixed (no indefinite-length encoding); the writer therefore
buffers each open container's body bytes until endObject() / endArray()
is called, then writes the length-prefix header followed by the buffered bytes. Memory cost
is O(largest open container).
Notes:
- This class is not thread safe.
byte[]values dispatch to native MsgPackbin, not to a base64 string fallback.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCursor-level settings honored byMsgPackTokenWriter. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor with default settings.MsgPackTokenWriter(OutputStream out, MsgPackTokenWriter.Settings settings) Constructor with explicit settings. -
Method Summary
Modifier and TypeMethodDescriptionbinary(byte[] value) Emits aTokenType.VALUE_BINARYevent.bool(boolean value) Emits aTokenType.VALUE_BOOLEANevent.voidclose()Closes the writer, flushing any buffered output first.endArray()Emits aTokenType.END_ARRAYevent.Emits aTokenType.END_OBJECTevent.Emits aTokenType.FIELD_NAMEevent for the next field of the enclosing object.voidflush()Flushes any buffered output to the underlying stream.booleanStructural token cursors are always O(1)-memory streamers.nil()Emits aTokenType.VALUE_NULLevent.number(double value) Emits aTokenType.VALUE_NUMBERevent for adouble.number(long value) Emits aTokenType.VALUE_NUMBERevent for along.Emits aTokenType.VALUE_NUMBERevent for an arbitraryNumber.number(BigDecimal value) Emits aTokenType.VALUE_NUMBERevent for aBigDecimal.number(BigInteger value) Emits aTokenType.VALUE_NUMBERevent for aBigInteger.Emits an arbitrary POJO through the format's structural events.Emits aTokenType.START_ARRAYevent.Emits aTokenType.START_OBJECTevent.Emits aTokenType.VALUE_STRINGevent.writeExt(int type, byte[] payload) Emits a typed-binary value (signed type byte + binary payload).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.marshall.stream.TokenWriter
write, writeSimple, writeTag
-
Constructor Details
-
MsgPackTokenWriter
Constructor with default settings.- Parameters:
out- TheOutputStreamto emit MsgPack to. Must not benull .
-
MsgPackTokenWriter
Constructor with explicit settings.- Parameters:
out- TheOutputStreamto emit MsgPack to. Must not benull .settings- The settings. Must not benull .
-
-
Method Details
-
startObject
Description copied from interface:TokenWriterEmits aTokenType.START_OBJECTevent.- Specified by:
startObjectin interfaceTokenWriter- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
endObject
Description copied from interface:TokenWriterEmits aTokenType.END_OBJECTevent.- Specified by:
endObjectin interfaceTokenWriter- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
startArray
Description copied from interface:TokenWriterEmits aTokenType.START_ARRAYevent.- Specified by:
startArrayin interfaceTokenWriter- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
endArray
Description copied from interface:TokenWriterEmits aTokenType.END_ARRAYevent.- Specified by:
endArrayin interfaceTokenWriter- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
fieldName
Description copied from interface:TokenWriterEmits aTokenType.FIELD_NAMEevent for the next field of the enclosing object.- Specified by:
fieldNamein interfaceTokenWriter- Parameters:
name- The field name. Must not benull .- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
string
Description copied from interface:TokenWriterEmits aTokenType.VALUE_STRINGevent.- Specified by:
stringin interfaceTokenWriter- Parameters:
value- The value. May benull , in which case aTokenType.VALUE_NULLevent is emitted instead.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
number
Description copied from interface:TokenWriterEmits aTokenType.VALUE_NUMBERevent for an arbitraryNumber.- Specified by:
numberin interfaceTokenWriter- Parameters:
value- The value. May benull , in which case aTokenType.VALUE_NULLevent is emitted instead.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
number
Description copied from interface:TokenWriterEmits aTokenType.VALUE_NUMBERevent for along.- Specified by:
numberin interfaceTokenWriter- Parameters:
value- The value.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
number
Description copied from interface:TokenWriterEmits aTokenType.VALUE_NUMBERevent for adouble.- Specified by:
numberin interfaceTokenWriter- Parameters:
value- The value.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
number
Description copied from interface:TokenWriterEmits aTokenType.VALUE_NUMBERevent for aBigDecimal.- Specified by:
numberin interfaceTokenWriter- Parameters:
value- The value. May benull , in which case aTokenType.VALUE_NULLevent is emitted instead.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
number
Description copied from interface:TokenWriterEmits aTokenType.VALUE_NUMBERevent for aBigInteger.- Specified by:
numberin interfaceTokenWriter- Parameters:
value- The value. May benull , in which case aTokenType.VALUE_NULLevent is emitted instead.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
bool
Description copied from interface:TokenWriterEmits aTokenType.VALUE_BOOLEANevent.- Specified by:
boolin interfaceTokenWriter- Parameters:
value- The value.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
nil
Description copied from interface:TokenWriterEmits aTokenType.VALUE_NULLevent.- Specified by:
nilin interfaceTokenWriter- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
binary
Description copied from interface:TokenWriterEmits aTokenType.VALUE_BINARYevent.Text formats normally encode the value as base64-encoded
TokenType.VALUE_STRING; the exact encoding is format-defined.- Specified by:
binaryin interfaceTokenWriter- Parameters:
value- The value. May benull , in which case aTokenType.VALUE_NULLevent is emitted instead.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
writeExt
Description copied from interface:TokenWriterEmits a typed-binary value (signed type byte + binary payload). The corresponding read-side token isTokenType.VALUE_BINARYwithTokenReader.getExtType()andTokenReader.getBinary().- Specified by:
writeExtin interfaceTokenWriter- Parameters:
type- The signed type byte (range-128..127).payload- The payload bytes. Must not benull.- Returns:
- This object.
- Throws:
IOException- If a problem occurred writing to the underlying stream.
-
object
Description copied from interface:TokenWriterEmits an arbitrary POJO through the format's structural events.The value is walked via
PojoWalker: nulls / scalars / collections / arrays / maps / beans are introspected and re-emitted through this writer'sTokenWriter.startObject(),TokenWriter.fieldName(String),TokenWriter.string(String),TokenWriter.number(long),TokenWriter.bool(boolean),TokenWriter.nil(), andTokenWriter.binary(byte[])methods. Per-format encoding (quoting, indentation, newlines, etc.) is whatever this writer is configured for.Cursor positioning: the writer must be in a state where a value emit is legal — at root, after a
TokenWriter.fieldName(String)call, or inside an array. Callingobject(...)from inside an object body without a preceding field name throwsIllegalStateException, same as callingTokenWriter.string(String)would.Default behavior: the default implementation throws
UnsupportedOperationException. Format-specific token writers override this by delegating toPojoWalker.walk(TokenWriter, Object).Swaps and
@Schema: this method is purely structural. Object swaps and schema annotations are NOT applied at the token layer — use the POJO databind path onSerializer.write(Object)for those.- Specified by:
objectin interfaceTokenWriter- Parameters:
value- The value to emit. May benull .- Returns:
- This object.
- Throws:
IOException- If the underlying stream fails.
-
isStreaming
Description copied from interface:TokenWriterStructural token cursors are always O(1)-memory streamers.- Specified by:
isStreamingin interfaceRecordWriter- Specified by:
isStreamingin interfaceTokenWriter- Returns:
- Always
true .
-
flush
Description copied from interface:TokenWriterFlushes any buffered output to the underlying stream.- Specified by:
flushin interfaceFlushable- Specified by:
flushin interfaceRecordWriter- Specified by:
flushin interfaceTokenWriter- Throws:
IOException- If a problem occurred flushing the underlying stream.
-
close
Description copied from interface:TokenWriterCloses the writer, flushing any buffered output first.Implementations should be idempotent — closing a closed writer is a no-op.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceRecordWriter- Specified by:
closein interfaceTokenWriter- Throws:
IOException
-