Package org.daiitech.naftah.utils
Class Base64SerializationUtils
java.lang.Object
org.daiitech.naftah.utils.Base64SerializationUtils
Utility class for serializing and deserializing Java objects to and from Base64 strings.
Supports both in-memory and file-based operations. All methods are static and the class cannot be instantiated.
Usage examples:
String base64 = Base64SerializationUtils.serialize(myObject);
MyClass obj = (MyClass) Base64SerializationUtils.deserialize(base64);
- Author:
- Chakib Daii
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePrivate constructor to prevent instantiation. -
Method Summary
Modifier and TypeMethodDescriptionstatic Objectdeserialize(File file) Deserializes an object from a file containing a Base64-encoded string.static ObjectDeserializes an object from a Base64-encoded string.static Objectdeserialize(Path path) Deserializes an object from a file containing a Base64-encoded string.static StringSerializes aSerializableobject to a Base64-encoded string.static Stringserialize(Serializable o, File file) Serializes aSerializableobject to a Base64-encoded string and writes it to a file.static Stringserialize(Serializable o, Path path) Serializes aSerializableobject to a Base64-encoded string and writes it to a file.
-
Constructor Details
-
Base64SerializationUtils
private Base64SerializationUtils()Private constructor to prevent instantiation.
-
-
Method Details
-
serialize
Serializes aSerializableobject to a Base64-encoded string.- Parameters:
o- the serializable object to serialize- Returns:
- a Base64-encoded string representation of the object
- Throws:
IOException- if an I/O error occurs during serialization
-
serialize
Serializes aSerializableobject to a Base64-encoded string and writes it to a file.- Parameters:
o- the serializable object to serializepath- the file path where the Base64 string should be saved- Returns:
- the string path to the file
- Throws:
IOException- if an I/O error occurs during serialization or file writing
-
serialize
Serializes aSerializableobject to a Base64-encoded string and writes it to a file.- Parameters:
o- the serializable object to serializefile- the file where the Base64 string should be saved- Returns:
- the string path to the file
- Throws:
IOException- if an I/O error occurs during serialization or file writing
-
deserialize
Deserializes an object from a Base64-encoded string.- Parameters:
s- the Base64 string to deserialize- Returns:
- the deserialized object
- Throws:
IOException- if an I/O error occurs during deserializationClassNotFoundException- if the class of the serialized object cannot be found
-
deserialize
Deserializes an object from a file containing a Base64-encoded string.- Parameters:
path- the path to the file- Returns:
- the deserialized object
- Throws:
IOException- if an I/O error occurs during file reading or deserializationClassNotFoundException- if the class of the serialized object cannot be found
-
deserialize
Deserializes an object from a file containing a Base64-encoded string.- Parameters:
file- the file containing the Base64 string- Returns:
- the deserialized object
- Throws:
IOException- if an I/O error occurs during file reading or deserializationClassNotFoundException- if the class of the serialized object cannot be found
-