java快速序列化库FST

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 massively
02      // if you create a new Configuration Object with each serialization !
03      static FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
04      ...
05      public MyClass myreadMethod(InputStream stream) throws IOException, ClassNotFoundException
06      {
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       
14      public 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