Search in sources :

Example 1 with FSTObjectOutput

use of org.nustaq.serialization.FSTObjectOutput in project jfinal by jfinal.

the class FstSerializer method valueToBytes.

public byte[] valueToBytes(Object value) {
    FSTObjectOutput fstOut = null;
    try {
        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        fstOut = new FSTObjectOutput(bytesOut);
        fstOut.writeObject(value);
        fstOut.flush();
        return bytesOut.toByteArray();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (fstOut != null)
            try {
                fstOut.close();
            } catch (IOException e) {
                LogKit.error(e.getMessage(), e);
            }
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FSTObjectOutput(org.nustaq.serialization.FSTObjectOutput) IOException(java.io.IOException)

Example 2 with FSTObjectOutput

use of org.nustaq.serialization.FSTObjectOutput in project chuidiang-ejemplos by chuidiang.

the class FstExample method main.

public static void main(String[] args) throws Exception {
    FSTConfiguration conf = FSTConfiguration.createDefaultConfiguration();
    SomeMediumClass mediumClass = new SomeMediumClass();
    byte[] barray = conf.asByteArray(mediumClass);
    System.out.println(barray.length);
    SomeMediumClass object = (SomeMediumClass) conf.asObject(barray);
    System.out.println(object);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    FSTObjectOutput output = new FSTObjectOutput(outputStream);
    output.writeObject(mediumClass);
    output.close();
    FSTObjectInput input = new FSTObjectInput(new ByteArrayInputStream(outputStream.toByteArray()));
    object = (SomeMediumClass) input.readObject(SomeMediumClass.class);
    System.out.println(object);
}
Also used : FSTConfiguration(org.nustaq.serialization.FSTConfiguration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FSTObjectOutput(org.nustaq.serialization.FSTObjectOutput) FSTObjectInput(org.nustaq.serialization.FSTObjectInput)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FSTObjectOutput (org.nustaq.serialization.FSTObjectOutput)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 FSTConfiguration (org.nustaq.serialization.FSTConfiguration)1 FSTObjectInput (org.nustaq.serialization.FSTObjectInput)1