|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.esotericsoftware.kryo.Kryo
public class Kryo
Maps classes to serializers so object graphs can be serialized automatically.
| Nested Class Summary | |
|---|---|
static interface |
Kryo.Listener
Provides notification of Kryo events. |
static class |
Kryo.RegisteredClass
Holds the registration information for a class. |
| Field Summary | |
|---|---|
static java.lang.String |
version
|
| Constructor Summary | |
|---|---|
Kryo()
|
|
| Method Summary | ||
|---|---|---|
void |
addListener(Kryo.Listener listener)
|
|
java.lang.ClassLoader |
getClassLoader()
|
|
static Context |
getContext()
Returns the thread local context for serialization and deserialization. |
|
Kryo.RegisteredClass |
getRegisteredClass(java.lang.Class type)
Returns the registration information for the specified class. |
|
Kryo.RegisteredClass |
getRegisteredClass(int classID)
|
|
Serializer |
getSerializer(java.lang.Class type)
|
|
protected void |
handleUnregisteredClass(java.lang.Class type)
If optional registration is true, this method is called the first time an
unregistered class is encountered. |
|
static boolean |
isFinal(java.lang.Class type)
Returns true if the specified type is final, or if it is an array of a final type. |
|
protected Serializer |
newDefaultSerializer(java.lang.Class type)
Called by newSerializer(Class) when a serializer could not otherwise be determined. |
|
|
newInstance(java.lang.Class<T> type)
Returns an instance of the specified class. |
|
Serializer |
newSerializer(java.lang.Class type)
Returns a serializer for the specified type, determined according to this table: |
|
Kryo.RegisteredClass |
readClass(java.nio.ByteBuffer buffer)
Reads the class from the buffer. |
|
java.lang.Object |
readClassAndObject(java.nio.ByteBuffer buffer)
Reads a class from the buffer and uses the serializer registered for that class to read an object from the buffer. |
|
|
readObject(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
Uses the serializer registered for the specified class to read an object from the buffer. |
|
|
readObjectData(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
Uses the serializer registered for the specified class to read an object from the buffer. |
|
Kryo.RegisteredClass |
register(java.lang.Class type)
Registers a class with an ordinal, automatically determining the serializer to use. |
|
void |
register(java.lang.Class type,
Kryo.RegisteredClass registeredClass)
Registers a class with the ordinal of the specified registered class. |
|
Kryo.RegisteredClass |
register(java.lang.Class type,
Serializer serializer)
Registers a class with an ordinal. |
|
Kryo.RegisteredClass |
register(java.lang.Class type,
Serializer serializer,
boolean useClassNameString)
Registers a class for serialization. |
|
void |
removeListener(Kryo.Listener listener)
|
|
void |
removeRemoteEntity(int remoteEntityID)
Notifies all listeners that the remote entity with the specified ID will no longer be available. |
|
void |
setClassLoader(java.lang.ClassLoader classLoader)
Sets the class loader used to resolve class names when class name Strings are encountered in the serialized bytes. |
|
void |
setRegistrationOptional(boolean registrationOptional)
When true, classes that have not been registered will not throw an exception. |
|
void |
setSerializer(java.lang.Class type,
Serializer serializer)
|
|
Kryo.RegisteredClass |
writeClass(java.nio.ByteBuffer buffer,
java.lang.Class type)
Writes the specified class to the buffer. |
|
void |
writeClassAndObject(java.nio.ByteBuffer buffer,
java.lang.Object object)
Writes the object's class to the buffer, then uses the serializer registered for that class to write the object to the buffer. |
|
void |
writeObject(java.nio.ByteBuffer buffer,
java.lang.Object object)
Uses the serializer registered for the object's class to write the object to the buffer. |
|
void |
writeObjectData(java.nio.ByteBuffer buffer,
java.lang.Object object)
Uses the serializer registered for the object's class to write the object to the buffer. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String version
| Constructor Detail |
|---|
public Kryo()
| Method Detail |
|---|
public void setRegistrationOptional(boolean registrationOptional)
registered will not throw an exception. Instead,
handleUnregisteredClass(Class) will be called. Default is false.
public Kryo.RegisteredClass register(java.lang.Class type,
Serializer serializer,
boolean useClassNameString)
If useClassNameString is true, the first time an object of the specified type is encountered, the class name String will be written to the serialized bytes. Each appearance in the graph after the first is stored as an integer ordinal.
If useClassNameString is false, the class is assigned an ordinal which will be written to the serialized bytes for objects of the specified type. This is more efficient than using the class name String, but has the drawback that the exact same classes must be registered in exactly the same order when the class is deserialized.
By default, primitive types, primitive wrappers, and java.lang.String are registered. All other classes must be registered
before they can be serialized. Note that JDK classes such as ArrayList, HashMap, etc and even array classes such as
"int[].class" or "short[][].class" must be registered. Optional registration can
be enabled to handle unregistered classes as they are encountered.
The Serializer specified will be used to serialize and deserialize objects of the specified type. Note that a
serializer can be wrapped with a Compressor for compression and/or encoding.
If the class is already registered, the serializer will be changed.
register(Class)
public Kryo.RegisteredClass register(java.lang.Class type,
Serializer serializer)
register(Class, Serializer, boolean)public Kryo.RegisteredClass register(java.lang.Class type)
newSerializer(Class) is used.
Note that some serializers allow additional information to be specified to make serialization more efficient in some cases
(eg, ArraySerializer.setElementsCanBeNull(boolean)). To use these features, call
register(Class, Serializer) with the configured serializer.
register(Class, Serializer, boolean)
public void register(java.lang.Class type,
Kryo.RegisteredClass registeredClass)
public Serializer newSerializer(java.lang.Class type)
| Type | Serializer |
|---|---|
| array (any number of dimensions) | ArraySerializer |
Enum |
EnumSerializer |
Collection |
CollectionSerializer |
Map |
MapSerializer |
CustomSerialization |
CustomSerializer |
class with DefaultSerializer annotation |
serializer specified in annotiation |
| any other class | serializer returned by newDefaultSerializer(Class) |
register(Class)protected Serializer newDefaultSerializer(java.lang.Class type)
newSerializer(Class) when a serializer could not otherwise be determined. The default implementation
returns a new FieldSerializer.
public Kryo.RegisteredClass getRegisteredClass(java.lang.Class type)
optional
registration is true, handleUnregisteredClass(Class) will be called if the class is not registered. Otherwise
IllegalArgumentException is thrown.
protected void handleUnregisteredClass(java.lang.Class type)
optional registration is true, this method is called the first time an
unregistered class is encountered. The default implementation registers the class to use the class name String in the
serialized bytes.
register(Class, Serializer, boolean)public Kryo.RegisteredClass getRegisteredClass(int classID)
public void setClassLoader(java.lang.ClassLoader classLoader)
public java.lang.ClassLoader getClassLoader()
public Serializer getSerializer(java.lang.Class type)
public void setSerializer(java.lang.Class type,
Serializer serializer)
public Kryo.RegisteredClass writeClass(java.nio.ByteBuffer buffer,
java.lang.Class type)
registered.
type - Can be null (writes a special ID for a null object).
public Kryo.RegisteredClass readClass(java.nio.ByteBuffer buffer)
public void writeClassAndObject(java.nio.ByteBuffer buffer,
java.lang.Object object)
object - Can be null (writes a special ID for a null object instead).
SerializationException - if an error occurred during serialization.
public void writeObject(java.nio.ByteBuffer buffer,
java.lang.Object object)
object - Can be null (writes a special ID for a null object instead).
SerializationException - if an error occurred during serialization.
public void writeObjectData(java.nio.ByteBuffer buffer,
java.lang.Object object)
object - Cannot be null.
SerializationException - if an error occurred during serialization.public java.lang.Object readClassAndObject(java.nio.ByteBuffer buffer)
SerializationException - if an error occurred during deserialization.
public <T> T readObject(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
SerializationException - if an error occurred during deserialization.
public <T> T readObjectData(java.nio.ByteBuffer buffer,
java.lang.Class<T> type)
SerializationException - if an error occurred during deserialization.public void addListener(Kryo.Listener listener)
public void removeListener(Kryo.Listener listener)
public void removeRemoteEntity(int remoteEntityID)
Context.getRemoteEntityID(),
addListener(Listener)public <T> T newInstance(java.lang.Class<T> type)
Serializer.newInstance(Kryo, Class) instead of calling this method directly.
SerializationException - if the class could not be constructed.public static boolean isFinal(java.lang.Class type)
public static Context getContext()
Context
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||