org.joda.beans.ser.bin
Class JodaBeanBinWriter

java.lang.Object
  extended by org.joda.beans.ser.bin.JodaBeanBinWriter

public class JodaBeanBinWriter
extends Object

Provides the ability for a Joda-Bean to be written to a binary format.

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 Summary
JodaBeanBinWriter(JodaBeanSer settings)
          Creates an instance.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JodaBeanBinWriter

public JodaBeanBinWriter(JodaBeanSer settings)
Creates an instance.

Parameters:
settings - the settings to use, not null
Method Detail

write

public byte[] write(Bean bean)
Writes the bean to an array of bytes.

The type of the bean will be set in the message.

Parameters:
bean - the bean to output, not null
Returns:
the binary data, not null

write

public byte[] write(Bean bean,
                    boolean rootType)
Writes the bean to an array of bytes.

Parameters:
bean - the bean to output, not null
rootType - true to output the root type
Returns:
the binary data, not null

write

public void write(Bean bean,
                  OutputStream output)
           throws IOException
Writes the bean to the OutputStream.

The type of the bean will be set in the message.

Parameters:
bean - the bean to output, not null
output - the output stream, not null
Throws:
IOException

write

public void write(Bean bean,
                  boolean rootType,
                  OutputStream output)
           throws IOException
Writes the bean to the OutputStream.

Parameters:
bean - the bean to output, not null
rootType - true to output the root type
output - the output stream, not null
Throws:
IOException


Copyright © 2007–2015 Joda.org. All rights reserved.