public class JodaBeanBinWriter extends Object
This class contains mutable state and cannot be used from multiple threads. A new instance must be created for each message.
The binary format is based on MessagePack v2.0. Each bean is output as a map using the property name.
Most simple types, defined by Joda-Convert, are output as MessagePack strings. However, MessagePack nil, boolean, float, integral and bin types are also used for null, byte[] and the Java numeric primitive types (excluding char).
Beans are output using MessagePack maps where the key is the property name. Collections are output using MessagePack maps or arrays. Multisets are output as a map of value to count.
If a collection contains a collection then addition meta-type information is written to aid with deserialization. At this level, the data read back may not be identical to that written.
Where necessary, the Java type is sent using an 'ext' entity. Three 'ext' types are used, one each for beans, meta-type and simple. The class name is passed as the 'ext' data. The 'ext' value is sent as an additional key-value pair for beans, with the 'ext' as the key and 'nil' as the value. Where the additional type information is not about a bean, a tuple is written using a size 1 map where the key is the 'ext' data and the value is the data being annotated.
Type names are shortened by the package of the root type if possible. Certain basic types are also handled, such as String, Integer, File and URI.
| Constructor and Description |
|---|
JodaBeanBinWriter(JodaBeanSer settings)
Creates an instance.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
write(Bean bean)
Writes the bean to an array of bytes.
|
byte[] |
write(Bean bean,
boolean rootType)
Writes the bean to an array of bytes.
|
void |
write(Bean bean,
boolean rootType,
OutputStream output)
Writes the bean to the
OutputStream. |
void |
write(Bean bean,
OutputStream output)
Writes the bean to the
OutputStream. |
public JodaBeanBinWriter(JodaBeanSer settings)
settings - the settings to use, not nullpublic byte[] write(Bean bean)
The type of the bean will be set in the message.
bean - the bean to output, not nullpublic byte[] write(Bean bean, boolean rootType)
bean - the bean to output, not nullrootType - true to output the root typepublic void write(Bean bean, OutputStream output) throws IOException
OutputStream.
The type of the bean will be set in the message.
bean - the bean to output, not nulloutput - the output stream, not nullIOException - if an error occurspublic void write(Bean bean, boolean rootType, OutputStream output) throws IOException
OutputStream.bean - the bean to output, not nullrootType - true to output the root typeoutput - the output stream, not nullIOException - if an error occursCopyright © 2007–2017 Joda.org. All rights reserved.