项目作者: qwazr

项目描述 :
Java serialization library - compact, fast, transparent
高级语言: Java
项目地址: git://github.com/qwazr/externalizor.git
创建时间: 2016-10-15T10:19:57Z
项目社区:https://github.com/qwazr/externalizor

开源协议:Apache License 2.0

下载


Externalizor

Build Status
Maven Central
Coverage Status
Javadocs

Fast and compact serialization of Java object.

  • Concrete Collections (Map, Set, Vector, List) with compression/decompression using Snappy
  • Primitive types: int, long, short, double, float, boolean, char, byte, enum
  • Primitive array: with compression/decompression using Snappy
  • Time types: Date, LocalDate, LocalTime, LocalDateTime, Instant, Duration, Period, MonthDay, Year
  • Other types are serialized using Java’s default serialization

Usage

Use the provided static methods to serialize and/or deserialize your object(s). There is two ways:

  • Raw serialization: the fastest
  • Compressed serialization: slower but more compact

Raw serialization (fastest)

The serialization used our Snappy based specialized compressors.

  1. import java.io.*;
  2. import com.qwazr.externalizor.Externalizor;
  3. public class FastSerialization {
  4. public FastSerialization() {
  5. MyClass object = new MyClass();
  6. byte[] bytes;
  7. // Serialization
  8. try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
  9. Externalizor.serializeRaw(object, output);
  10. bytes = output.toByteArray();
  11. }
  12. // Deserialization
  13. try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
  14. MyClass object = Externalizor.deserializeRaw(input);
  15. }
  16. }
  17. }

Compressed serialization (slower but more compact)

In addition of the specialized compression (snappy) a GZIP compression is used on the final serialized stream
(slower but more compact).

  1. import java.io.*;
  2. import com.qwazr.externalizor.Externalizor;
  3. public class CompactSerialization {
  4. public CompactSerialization() {
  5. MyClass object = new MyClass();
  6. byte[] bytes;
  7. // Serialization
  8. try (ByteArrayOutputStream input = new ByteArrayOutputStream()) {
  9. Externalizor.serialize(object, output);
  10. bytes = output.toByteArray();
  11. }
  12. // Deserialization
  13. try (ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
  14. object = Externalizor.deserialize(input);
  15. }
  16. }
  17. }

Maven dependency

In Maven’s central repository:
central.maven.org/maven2/com/qwazr/externalizor

Add the following dependency to your pom.xml:

  1. <dependency>
  2. <groupId>com.qwazr</groupId>
  3. <artifactId>externalizor</artifactId>
  4. <version>1.3.2</version>
  5. </dependency>

Benchmark

The code of the benchmark is here:
BenchmarkTest

  • Serialization raw: Default Java serialization without compression.
  • Serialization compressed: Default Java serialization with Gzip compression.
  • Externalizor raw: Using Externalizor without compression.
  • Externalizor compressed: Using Externalizor with Gzip compression.

Average size of the serialized objects

Bytes sizes. Smaller is better.

Byte size

Serialization/Deserialization rate

Number of serialization and deserialization per seconds. Bigger is better.

Rate

Issues

Post bug reports or feature request to the Issue Tracker:
https://github.com/qwazr/externalizor/issues

Open source license

Apache2 license