java序列化(七) - fst 序列化

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

java序列化(七) - fst 序列化

github

https://github.com/RuedigerMoeller/fast-serialization

实践

https://gitee.com/mengzhang6/serializable-demo.git

maven依赖



    de.ruedigermoeller
    fst
    2.57


开始上手

// ! 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();
}

参考资料

https://www.oschina.net/p/fst http://hao.jobbole.com/fst/

转载于:https://my.oschina.net/mengzhang6/blog/2251138

你可能感兴趣的:(java序列化(七) - fst 序列化)