Search in sources :

Example 6 with Hessian2Output

use of com.alibaba.com.caucho.hessian.io.Hessian2Output in project dubbo by alibaba.

the class SerializationCompareTest method test_CompareSerializeLength.

@Test
public void test_CompareSerializeLength() throws Exception {
    long[] data = new long[] { -1l, 2l, 3l, 4l, 5l };
    ByteArrayOutputStream os;
    os = new ByteArrayOutputStream();
    ObjectOutputStream jos = new ObjectOutputStream(os);
    jos.writeObject(data);
    System.out.println("java:" + Bytes.bytes2hex(os.toByteArray()) + ":" + os.size());
    os = new ByteArrayOutputStream();
    CompactedObjectOutputStream oos = new CompactedObjectOutputStream(os);
    oos.writeObject(data);
    System.out.println("compacted java:" + Bytes.bytes2hex(os.toByteArray()) + ":" + os.size());
    os = new ByteArrayOutputStream();
    Hessian2Output h2o = new Hessian2Output(os);
    h2o.writeObject(data);
    h2o.flushBuffer();
    System.out.println("hessian:" + Bytes.bytes2hex(os.toByteArray()) + ":" + os.size());
    os = new ByteArrayOutputStream();
    Builder<long[]> lb = Builder.register(long[].class);
    lb.writeTo(data, os);
    System.out.println("DataOutput:" + Bytes.bytes2hex(os.toByteArray()) + ":" + os.size());
}
Also used : Hessian2Output(com.alibaba.com.caucho.hessian.io.Hessian2Output) CompactedObjectOutputStream(com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CompactedObjectOutputStream(com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Test(org.junit.Test)

Aggregations

Hessian2Output (com.alibaba.com.caucho.hessian.io.Hessian2Output)6 Hessian2Input (com.alibaba.com.caucho.hessian.io.Hessian2Input)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2 CompactedObjectOutputStream (com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 CipherOutputStream (javax.crypto.CipherOutputStream)1