Java Code Examples for com.caucho.hessian.io.AbstractHessianInput#close()

The following examples show how to use com.caucho.hessian.io.AbstractHessianInput#close() . 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: HessianSerializerUtils.java    From zkdoctor with Apache License 2.0 5 votes vote down vote up
/**
 * 反序列化
 *
 * @param bytes 待反序列化字节数组
 * @return
 */
public static Object deserialize(byte[] bytes) {
    ByteArrayInputStream ips = new ByteArrayInputStream(bytes);
    AbstractHessianInput in = new Hessian2Input(ips);
    in.setSerializerFactory(new SerializerFactory());
    Object value;
    try {
        value = in.readObject();
        in.close();
    } catch (IOException e) {
        LOGGER.error("Hessian deserialize failed", e);
        throw new RuntimeException("Hessian deserialize failed");
    }
    return value;
}
 
Example 2
Source File: HessianSerializer.java    From AutoLoadCache with Apache License 2.0 5 votes vote down vote up
@Override
public Object deserialize(final byte[] bytes, final Type returnType) throws Exception {
    if (null == bytes || bytes.length == 0) {
        return null;
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
    AbstractHessianInput input = new Hessian2Input(inputStream);
    input.setSerializerFactory(SERIALIZER_FACTORY);
    Object obj = input.readObject();
    input.close();
    return obj;
}
 
Example 3
Source File: HessianSkeleton.java    From sofa-hessian with Apache License 2.0 4 votes vote down vote up
/**
 * Invoke the object with the request from the input stream.
 *
 * @param in the Hessian input stream
 * @param out the Hessian output stream
 */
public void invoke(InputStream is, OutputStream os,
                   SerializerFactory serializerFactory)
    throws Exception
{
    boolean isDebug = false;

    if (isDebugInvoke()) {
        isDebug = true;

        PrintWriter dbg = createDebugPrintWriter();
        HessianDebugInputStream dIs = new HessianDebugInputStream(is, dbg);
        dIs.startTop2();
        is = dIs;
        HessianDebugOutputStream dOs = new HessianDebugOutputStream(os, dbg);
        dOs.startTop2();
        os = dOs;
    }

    HessianInputFactory.HeaderType header = _inputFactory.readHeader(is);

    AbstractHessianInput in;
    AbstractHessianOutput out;

    switch (header) {
        case CALL_1_REPLY_1:
            in = _hessianFactory.createHessianInput(is);
            out = _hessianFactory.createHessianOutput(os);
            break;

        case CALL_1_REPLY_2:
            in = _hessianFactory.createHessianInput(is);
            out = _hessianFactory.createHessian2Output(os);
            break;

        case HESSIAN_2:
            in = _hessianFactory.createHessian2Input(is);
            in.readCall();
            out = _hessianFactory.createHessian2Output(os);
            break;

        default:
            throw new IllegalStateException(header + " is an unknown Hessian call");
    }

    if (serializerFactory != null) {
        in.setSerializerFactory(serializerFactory);
        out.setSerializerFactory(serializerFactory);
    }

    try {
        invoke(_service, in, out);
    } finally {
        in.close();
        out.close();

        if (isDebug)
            os.close();
    }
}