Class DataSerializer
This class provides serialization capabilities using different serializers, currently supporting Kryo and JavaBin serialization formats. The serializer type is determined by the crawler data serializer configuration.
The class is thread-safe and uses ThreadLocal to maintain Kryo instances per thread to avoid synchronization overhead.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringConstant for JavaBin serializer type.protected static final StringConstant for Kryo serializer type.protected final ThreadLocal<com.esotericsoftware.kryo.Kryo> ThreadLocal container for Kryo instances to ensure thread safety. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectdeserializeWithKryo(byte[] bytes) Deserializes a byte array using Kryo deserialization.fromBinaryToObject(byte[] bytes) Deserializes a byte array back to an object.byte[]fromObjectToBinary(Object obj) Serializes an object to a byte array.protected StringGets the configured serializer type from the Fess configuration.protected byte[]serializeWithKryo(Object obj) Serializes an object using Kryo serialization.
-
Field Details
-
JAVABIN
Constant for JavaBin serializer type.- See Also:
-
KRYO
Constant for Kryo serializer type.- See Also:
-
kryoThreadLocal
ThreadLocal container for Kryo instances to ensure thread safety.
-
-
Constructor Details
-
DataSerializer
public DataSerializer()Constructs a new DataSerializer.Initializes the ThreadLocal Kryo instances with appropriate configuration. The Kryo instances are configured to not require class registration for flexibility, and debug mode warnings are enabled when debug logging is active.
-
-
Method Details
-
getSerializerType
Gets the configured serializer type from the Fess configuration.- Returns:
- the serializer type (either "kryo" or "javabin")
-
fromObjectToBinary
Serializes an object to a byte array.The serialization method used depends on the configured serializer type. Supported types are Kryo and JavaBin serialization.
- Parameters:
obj- the object to serialize- Returns:
- the serialized object as a byte array
- Throws:
IllegalArgumentException- if an unsupported serializer type is configuredorg.codelibs.core.exception.IORuntimeException- if an I/O error occurs during serialization
-
fromBinaryToObject
Deserializes a byte array back to an object.The deserialization method used depends on the configured serializer type. Supported types are Kryo and JavaBin deserialization.
- Parameters:
bytes- the byte array to deserialize- Returns:
- the deserialized object
- Throws:
IllegalArgumentException- if an unsupported serializer type is configuredorg.codelibs.core.exception.IORuntimeException- if an I/O error occurs during deserialization
-
serializeWithKryo
Serializes an object using Kryo serialization.Uses the thread-local Kryo instance to serialize the object along with its class information. The serialized data is written to a byte array output stream.
- Parameters:
obj- the object to serialize- Returns:
- the serialized object as a byte array
- Throws:
org.codelibs.core.exception.IORuntimeException- if an I/O error occurs during serialization
-
deserializeWithKryo
Deserializes a byte array using Kryo deserialization.Uses the thread-local Kryo instance to read both the class information and object data from the byte array input stream.
- Parameters:
bytes- the byte array to deserialize- Returns:
- the deserialized object
-