use of com.alibaba.com.caucho.hessian.io.Hessian2Output in project dubbo by alibaba.
the class SerializationCompareTest method testH2oPerm.
@Test
public void testH2oPerm() throws Exception {
Bean bean = new Bean();
int len = 0;
long now = System.currentTimeMillis();
for (int i = 0; i < 500; i++) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
Hessian2Output out = new Hessian2Output(os);
out.writeObject(bean);
out.flushBuffer();
os.close();
if (i == 0)
len = os.toByteArray().length;
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Hessian2Input in = new Hessian2Input(is);
assertEquals(in.readObject().getClass(), Bean.class);
}
System.out.println("Hessian2 write and parse 500 times in " + (System.currentTimeMillis() - now) + "ms, size " + len);
}
use of com.alibaba.com.caucho.hessian.io.Hessian2Output in project dubbo by alibaba.
the class X509Encryption method wrap.
public Hessian2Output wrap(Hessian2Output out) throws IOException {
if (_cert == null)
throw new IOException("X509Encryption.wrap requires a certificate");
OutputStream os = new EncryptOutputStream(out);
Hessian2Output filterOut = new Hessian2Output(os);
filterOut.setCloseStreamOnClose(true);
return filterOut;
}
use of com.alibaba.com.caucho.hessian.io.Hessian2Output in project dubbo by alibaba.
the class X509Signature method wrap.
public Hessian2Output wrap(Hessian2Output out) throws IOException {
if (_privateKey == null)
throw new IOException("X509Signature.wrap requires a private key");
if (_cert == null)
throw new IOException("X509Signature.wrap requires a certificate");
OutputStream os = new SignatureOutputStream(out);
Hessian2Output filterOut = new Hessian2Output(os);
filterOut.setCloseStreamOnClose(true);
return filterOut;
}
use of com.alibaba.com.caucho.hessian.io.Hessian2Output in project dubbo by alibaba.
the class SerializeTestBase method baseHession2Serialize.
/**
* hession2 serialize util
*
* @param data
* @param <T>
* @return
* @throws IOException
*/
protected <T> T baseHession2Serialize(T data) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Hessian2Output out = new Hessian2Output(bout);
out.writeObject(data);
out.flush();
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
Hessian2Input input = new Hessian2Input(bin);
return (T) input.readObject();
}
use of com.alibaba.com.caucho.hessian.io.Hessian2Output in project dubbo by alibaba.
the class Java8TimeSerializerTest method testJava8Time.
private void testJava8Time(Object expected) throws IOException {
os.reset();
Hessian2Output output = new Hessian2Output(os);
output.setSerializerFactory(factory);
output.writeObject(expected);
output.flush();
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Hessian2Input input = new Hessian2Input(is);
input.setSerializerFactory(factory);
Object actual = input.readObject();
TestCase.assertEquals(expected, actual);
}
Aggregations