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);
}
}
}
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);
}
Aggregations