com.esotericsoftware.kryo.serialize
Class CollectionSerializer

java.lang.Object
  extended by com.esotericsoftware.kryo.Serializer
      extended by com.esotericsoftware.kryo.serialize.CollectionSerializer

public class CollectionSerializer
extends Serializer

Serializes objects that implement the Collection interface.

With the default constructor, a collection requires a 1-3 byte header and an extra 2-3 bytes is written for each element in the collection. The alternate constructor can be used to improve efficiency to match that of using an array instead of a collection.

Author:
Nathan Sweet

Constructor Summary
CollectionSerializer(Kryo kryo)
           
 
Method Summary
<T> T
readObjectData(java.nio.ByteBuffer buffer, java.lang.Class<T> type)
          Reads an object from the buffer.
 void setElementClass(java.lang.Class elementClass)
           
 void setElementClass(java.lang.Class elementClass, Serializer serializer)
           
 void setElementsCanBeNull(boolean elementsCanBeNull)
           
 void setLength(int length)
          Sets the number of objects in the collection.
 void writeObjectData(java.nio.ByteBuffer buffer, java.lang.Object object)
          Writes the object to the buffer.
 
Methods inherited from class com.esotericsoftware.kryo.Serializer
isFinal, newInstance, readObject, setCanBeNull, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionSerializer

public CollectionSerializer(Kryo kryo)
Method Detail

setElementsCanBeNull

public void setElementsCanBeNull(boolean elementsCanBeNull)
Parameters:
elementsCanBeNull - False if all elements are not null. This saves 1 byte per element if elementClass is set. True if it is not known (default).

setElementClass

public void setElementClass(java.lang.Class elementClass)
Parameters:
elementClass - The concrete class of each element. This saves 1-2 bytes per element. The serializer registered for the specified class will be used. Set to null if the class is not known or varies per element (default).

setLength

public void setLength(int length)
Sets the number of objects in the collection. Saves 1-2 bytes.


setElementClass

public void setElementClass(java.lang.Class elementClass,
                            Serializer serializer)
Parameters:
elementClass - The concrete class of each element. This saves 1-2 bytes per element. Set to null if the class is not known or varies per element (default).
serializer - The serializer to use for each element.

writeObjectData

public void writeObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Object object)
Description copied from class: Serializer
Writes the object to the buffer.

Specified by:
writeObjectData in class Serializer
object - Cannot be null.

readObjectData

public <T> T readObjectData(java.nio.ByteBuffer buffer,
                            java.lang.Class<T> type)
Description copied from class: Serializer
Reads an object from the buffer.

Specified by:
readObjectData in class Serializer
Returns:
The deserialized object, never null.


Copyright © 2011. All Rights Reserved.