Search in sources :

Example 1 with Hessian2Output

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);
}
Also used : Hessian2Output(com.alibaba.com.caucho.hessian.io.Hessian2Output) Hessian2Input(com.alibaba.com.caucho.hessian.io.Hessian2Input) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with Hessian2Output

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;
}
Also used : Hessian2Output(com.alibaba.com.caucho.hessian.io.Hessian2Output) OutputStream(java.io.OutputStream) CipherOutputStream(javax.crypto.CipherOutputStream) IOException(java.io.IOException)

Example 3 with Hessian2Output

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;
}
Also used : Hessian2Output(com.alibaba.com.caucho.hessian.io.Hessian2Output) OutputStream(java.io.OutputStream) IOException(java.io.IOException)

Example 4 with Hessian2Output

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();
}
Also used : Hessian2Output(com.alibaba.com.caucho.hessian.io.Hessian2Output) Hessian2Input(com.alibaba.com.caucho.hessian.io.Hessian2Input) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with Hessian2Output

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);
}
Also used : Hessian2Output(com.alibaba.com.caucho.hessian.io.Hessian2Output) Hessian2Input(com.alibaba.com.caucho.hessian.io.Hessian2Input) ByteArrayInputStream(java.io.ByteArrayInputStream)

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