Search in sources :

Example 1 with Hessian2Input

use of com.alibaba.com.caucho.hessian.io.Hessian2Input 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 Hessian2Input

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

the class X509Signature method unwrapHeaders.

public Hessian2Input unwrapHeaders(Hessian2Input in) throws IOException {
    if (_cert == null)
        throw new IOException("X509Signature.unwrap requires a certificate");
    InputStream is = new SignatureInputStream(in);
    Hessian2Input filter = new Hessian2Input(is);
    filter.setCloseStreamOnClose(true);
    return filter;
}
Also used : Hessian2Input(com.alibaba.com.caucho.hessian.io.Hessian2Input) CipherInputStream(javax.crypto.CipherInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 3 with Hessian2Input

use of com.alibaba.com.caucho.hessian.io.Hessian2Input 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 4 with Hessian2Input

use of com.alibaba.com.caucho.hessian.io.Hessian2Input 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)

Example 5 with Hessian2Input

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

the class X509Encryption method unwrapHeaders.

public Hessian2Input unwrapHeaders(Hessian2Input in) throws IOException {
    if (_privateKey == null)
        throw new IOException("X509Encryption.unwrap requires a private key");
    if (_cert == null)
        throw new IOException("X509Encryption.unwrap requires a certificate");
    InputStream is = new EncryptInputStream(in);
    Hessian2Input filter = new Hessian2Input(is);
    filter.setCloseStreamOnClose(true);
    return filter;
}
Also used : Hessian2Input(com.alibaba.com.caucho.hessian.io.Hessian2Input) CipherInputStream(javax.crypto.CipherInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

Hessian2Input (com.alibaba.com.caucho.hessian.io.Hessian2Input)5 Hessian2Output (com.alibaba.com.caucho.hessian.io.Hessian2Output)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CipherInputStream (javax.crypto.CipherInputStream)2 Test (org.junit.Test)1