com.alibaba.com.caucho.hessian.io.Hessian2Input Java Examples

The following examples show how to use com.alibaba.com.caucho.hessian.io.Hessian2Input. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: X509Encryption.java    From dubbo-hessian-lite with Apache License 2.0 6 votes vote down vote up
@Override
public Hessian2Input unwrap(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");

    int version = in.readEnvelope();

    String method = in.readMethod();

    if (!method.equals(getClass().getName()))
        throw new IOException("expected hessian Envelope method '" +
                getClass().getName() + "' at '" + method + "'");

    return unwrapHeaders(in);
}
 
Example #2
Source File: SerializationCompareTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: SerializationCompareTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: X509Encryption.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public void close()
        throws IOException {
    Hessian2Input in = _in;
    _in = null;

    if (in != null) {
        _cipherIn.close();
        _bodyIn.close();

        int len = in.readInt();

        if (len != 0)
            throw new IOException("Unexpected footer");

        in.completeEnvelope();

        in.close();
    }
}
 
Example #5
Source File: X509Encryption.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public Hessian2Input unwrap(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");

    int version = in.readEnvelope();

    String method = in.readMethod();

    if (!method.equals(getClass().getName()))
        throw new IOException("expected hessian Envelope method '" +
                getClass().getName() + "' at '" + method + "'");

    return unwrapHeaders(in);
}
 
Example #6
Source File: SerializationCompareTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source File: SerializationCompareTest.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: SerializationCompareTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #9
Source File: X509Encryption.java    From dubbo-hessian-lite with Apache License 2.0 6 votes vote down vote up
@Override
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;
}
 
Example #10
Source File: X509Signature.java    From dubbo-hessian-lite with Apache License 2.0 6 votes vote down vote up
@Override
public Hessian2Input unwrap(Hessian2Input in)
        throws IOException {
    if (_cert == null)
        throw new IOException("X509Signature.unwrap requires a certificate");

    int version = in.readEnvelope();

    String method = in.readMethod();

    if (!method.equals(getClass().getName()))
        throw new IOException("expected hessian Envelope method '" +
                getClass().getName() + "' at '" + method + "'");

    return unwrapHeaders(in);
}
 
Example #11
Source File: X509Encryption.java    From dubbo-hessian-lite with Apache License 2.0 6 votes vote down vote up
@Override
public void close()
        throws IOException {
    Hessian2Input in = _in;
    _in = null;

    if (in != null) {
        _cipherIn.close();
        _bodyIn.close();

        int len = in.readInt();

        if (len != 0)
            throw new IOException("Unexpected footer");

        in.completeEnvelope();

        in.close();
    }
}
 
Example #12
Source File: SerializeTestBase.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
/**
 * hessian2 serialize util
 *
 * @param data
 * @param <T>
 * @return
 * @throws IOException
 */
protected <T> T baseHessian2Serialize(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();
}
 
Example #13
Source File: Java8TimeSerializerTest.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #14
Source File: X509Signature.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
@Override
public void close()
        throws IOException {
    Hessian2Input in = _in;
    _in = null;

    if (in != null) {
        _bodyIn.close();

        int len = in.readInt();
        byte[] signature = null;

        for (int i = 0; i < len; i++) {
            String header = in.readString();

            if ("signature".equals(header))
                signature = in.readBytes();
        }

        in.completeEnvelope();
        in.close();


        if (signature == null)
            throw new IOException("Expected signature");

        byte[] sig = _mac.doFinal();

        if (sig.length != signature.length)
            throw new IOException("mismatched signature");

        for (int i = 0; i < sig.length; i++) {
            if (signature[i] != sig[i])
                throw new IOException("mismatched signature");
        }

        // XXX: save principal
    }
}
 
Example #15
Source File: HessianUtil.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T decode(byte[] data) throws IOException {
    Object obj = null;
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    Hessian2Input hessian2Input = new Hessian2Input(in);
    hessian2Input.setSerializerFactory(serializerFactory);

    try {
        obj = hessian2Input.readObject();
    } finally {
        closeableQuietly(in);
        closeQuietly(hessian2Input);
    }
    return (T) obj;
}
 
Example #16
Source File: HessianUtil.java    From j360-dubbo-app-all with Apache License 2.0 5 votes vote down vote up
private static void closeQuietly(Hessian2Input hessian2Input) {
    try {
        if (hessian2Input != null) {
            hessian2Input.close();
        }
    } catch (IOException e) {
        logger.warn("close hessian2Input failed");
    }
}
 
Example #17
Source File: X509Signature.java    From dubbo-hessian-lite with Apache License 2.0 5 votes vote down vote up
@Override
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;
}
 
Example #18
Source File: X509Signature.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public Hessian2Input unwrap(Hessian2Input in)
        throws IOException {
    if (_cert == null)
        throw new IOException("X509Signature.unwrap requires a certificate");

    int version = in.readEnvelope();

    String method = in.readMethod();

    if (!method.equals(getClass().getName()))
        throw new IOException("expected hessian Envelope method '" +
                getClass().getName() + "' at '" + method + "'");

    return unwrapHeaders(in);
}
 
Example #19
Source File: X509Signature.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void close()
        throws IOException {
    Hessian2Input in = _in;
    _in = null;

    if (in != null) {
        _bodyIn.close();

        int len = in.readInt();
        byte[] signature = null;

        for (int i = 0; i < len; i++) {
            String header = in.readString();

            if ("signature".equals(header))
                signature = in.readBytes();
        }

        in.completeEnvelope();
        in.close();


        if (signature == null)
            throw new IOException("Expected signature");

        byte[] sig = _mac.doFinal();

        if (sig.length != signature.length)
            throw new IOException("mismatched signature");

        for (int i = 0; i < sig.length; i++) {
            if (signature[i] != sig[i])
                throw new IOException("mismatched signature");
        }

        // XXX: save principal
    }
}
 
Example #20
Source File: Hessian2ObjectInput.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public Hessian2ObjectInput(InputStream is) {
    mH2i = new Hessian2Input(is);
    mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
}
 
Example #21
Source File: Hessian2ObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Hessian2ObjectInput(InputStream is)
{
	mH2i = new Hessian2Input(is);
	mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
}
 
Example #22
Source File: Hessian2ObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Hessian2ObjectInput(InputStream is)
{
	mH2i = new Hessian2Input(is);
	mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
}
 
Example #23
Source File: X509Encryption.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #24
Source File: Hessian2ObjectInput.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public Hessian2ObjectInput(InputStream is)
{
	mH2i = new Hessian2Input(is);
	mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
}
 
Example #25
Source File: Hessian2ObjectInput.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public Hessian2ObjectInput(InputStream is)
{
	mH2i = new Hessian2Input(is);
	mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
}
 
Example #26
Source File: Hessian2ObjectInput.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public Hessian2ObjectInput(InputStream is)
{
	mH2i = new Hessian2Input(is);
	mH2i.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY);
}
 
Example #27
Source File: X509Signature.java    From dubbo3 with Apache License 2.0 3 votes vote down vote up
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;
}