Search in sources :

Example 1 with CompactedObjectOutputStream

use of com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream in project dubbo by alibaba.

the class SerializationCompareTest method testCompactedJavaOutputPerm.

@Test
public void testCompactedJavaOutputPerm() throws Exception {
    Bean bean = new Bean();
    int len = 0;
    long now = System.currentTimeMillis();
    for (int i = 0; i < 500; i++) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        CompactedObjectOutputStream out = new CompactedObjectOutputStream(os);
        out.writeObject(bean);
        os.close();
        if (i == 0)
            len = os.toByteArray().length;
        ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
        CompactedObjectInputStream in = new CompactedObjectInputStream(is);
        assertEquals(in.readObject().getClass(), Bean.class);
    }
    System.out.println("compacted java write and parse 500 times in " + (System.currentTimeMillis() - now) + "ms, size " + len);
}
Also used : CompactedObjectOutputStream(com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CompactedObjectInputStream(com.alibaba.dubbo.common.serialize.support.java.CompactedObjectInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with CompactedObjectOutputStream

use of com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream 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

CompactedObjectOutputStream (com.alibaba.dubbo.common.serialize.support.java.CompactedObjectOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 Hessian2Output (com.alibaba.com.caucho.hessian.io.Hessian2Output)1 CompactedObjectInputStream (com.alibaba.dubbo.common.serialize.support.java.CompactedObjectInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1