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