java快速序列化库FST

来源:互联网 发布:vk聊天软件下载 编辑:程序博客网 时间:2024/05/16 09:12

FST fast-serialization 是重新实现的 Java 快速对象序列化的开发包。序列化速度更快(2-10倍)、体积更小,而且兼容 JDK 原生的序列化。要求 JDK 1.7 支持。

Maven:

1<dependency>2    <groupId>de.ruedigermoeller</groupId>3    <artifactId>fst</artifactId>4    <version>1.36</version>5</dependency>


示例代码:

01// ! reuse this Object, it caches metadata. Performance degrades massively02// if you create a new Configuration Object with each serialization !03static FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();04...05public MyClass myreadMethod(InputStream stream) throws IOException, ClassNotFoundException06{07    FSTObjectInput in = conf.getObjectInput(stream);08    MyClass result = in.readObject(MyClass.class);09    // DON'T: in.close(); here prevents reuse and will result in an exception      10    stream.close();11    return result;12}13 14public void mywriteMethod( OutputStream stream, MyClass toWrite ) throws IOException 15{16    FSTObjectOutput out = conf.getObjectOutput(stream);17    out.writeObject( toWrite, MyClass.class );18    // DON'T out.close() when using factory method;19    out.flush();20    stream.close();21}

开源中国:http://www.oschina.net/p/fst

1 0
原创粉丝点击