Java 快速序列化库,FST 2.09 发布

jopen 9年前

FST 2.09 发布,该版本修复了自定义序列化器无法工作的问题,详情请看 Issue 34

下载地址:fst-2.09.zip

FST fast-serialization 是重新实现的 Java 快速对象序列化的开发包。专注于速度,大小,兼容性。序列化速度更快(2-10倍)、体积更小,而且兼容 JDK 原生的序列化。要求 JDK 1.7 支持。使用该库替换原来的基本不需要修改代码。

特性:

  • Faster serialization and smaller object size.
  • drop-in replacement. Does not require special getters/setters/Constructors/Interfaces to serialize a class. Extends Outputstream, implements ObjectInput/ObjectOutput. Few code changes required.
  • Full support of JDK-serialization features such as Externalizable writeObject/readObject/readReplace/validation/putField/getField, hooks etc.. If an object is serializable with JDK, it should be serializable with FST without any further work.
  • preserves links inside the serialized object graph same as JDK default serialization
  • custom optimization using annotations, custom serializers
  • conditional decoding (skip decoding parts of an object/stream in case)

支持 java 1.7+

  • Fast serialization should be adaptable to 1.6 (no use of 1.7 features). A build is here
  • FST-structs does require 1.7 API

示例:

// ! reuse this Object, it caches metadata. Performance degrades massively  // if you create a new Configuration Object with each serialization !  static FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();  ...  public MyClass myreadMethod(InputStream stream) throws IOException, ClassNotFoundException  {      FSTObjectInput in = conf.getObjectInput(stream);      MyClass result = in.readObject(MyClass.class);      // DON'T: in.close(); here prevents reuse and will result in an exception            stream.close();      return result;  }     public void mywriteMethod( OutputStream stream, MyClass toWrite ) throws IOException   {      FSTObjectOutput out = conf.getObjectOutput(stream);      out.writeObject( toWrite, MyClass.class );      // DON'T out.close() when using factory method;      out.flush();      stream.close();  }