Java serialization library - compact, fast, transparent
Fast and compact serialization of Java object.
Use the provided static methods to serialize and/or deserialize your object(s). There is two ways:
The serialization used our Snappy based specialized compressors.
import java.io.*;
import com.qwazr.externalizor.Externalizor;
public class FastSerialization {
public FastSerialization() {
MyClass object = new MyClass();
byte[] bytes;
// Serialization
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
Externalizor.serializeRaw(object, output);
bytes = output.toByteArray();
}
// Deserialization
try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
MyClass object = Externalizor.deserializeRaw(input);
}
}
}
In addition of the specialized compression (snappy) a GZIP compression is used on the final serialized stream
(slower but more compact).
import java.io.*;
import com.qwazr.externalizor.Externalizor;
public class CompactSerialization {
public CompactSerialization() {
MyClass object = new MyClass();
byte[] bytes;
// Serialization
try (ByteArrayOutputStream input = new ByteArrayOutputStream()) {
Externalizor.serialize(object, output);
bytes = output.toByteArray();
}
// Deserialization
try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
object = Externalizor.deserialize(input);
}
}
}
In Maven’s central repository:
central.maven.org/maven2/com/qwazr/externalizor
Add the following dependency to your pom.xml:
<dependency>
<groupId>com.qwazr</groupId>
<artifactId>externalizor</artifactId>
<version>1.3.2</version>
</dependency>
The code of the benchmark is here:
BenchmarkTest
Bytes sizes. Smaller is better.
Number of serialization and deserialization per seconds. Bigger is better.
Post bug reports or feature request to the Issue Tracker:
https://github.com/qwazr/externalizor/issues