Example usage for java.io ObjectInput close

List of usage examples for java.io ObjectInput close

Introduction

In this page you can find the example usage for java.io ObjectInput close.

Prototype

public void close() throws IOException;

Source Link

Document

Closes the input stream.

Usage

From source file:org.kepler.objectmanager.cache.LocalRepositoryManager.java

/**
 * /*from w w w.j a va  2 s . c o m*/
 */
private void initLocalSaveRepo() {
    File localSaveRepoFile = new File(_localSaveRepoFileName);

    if (localSaveRepoFile.exists()) {
        if (isDebugging) {
            log.debug("localSaveRepo exists: " + localSaveRepoFile.toString());
        }

        try {
            InputStream is = null;
            ObjectInput oi = null;
            try {
                is = new FileInputStream(localSaveRepoFile);
                oi = new ObjectInputStream(is);
                Object newObj = oi.readObject();
                setLocalSaveRepo((File) newObj);
                return;
            } finally {
                if (oi != null) {
                    oi.close();
                }
                if (is != null) {
                    is.close();
                }
            }
        } catch (Exception e1) {
            // problem reading file, try to delete it
            log.warn("Exception while reading localSaveRepoFile: " + e1.getMessage());
            try {
                localSaveRepoFile.delete();
            } catch (Exception e2) {
                log.warn("Unable to delete localSaveRepoFile: " + e2.getMessage());
            }
        }
    }
    try {
        setDefaultSaveRepo();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.weibo.api.motan.protocol.rpc.CompressRpcCodec.java

/**
 * //from w ww  .j  av a2s.com
 * @param body
 * @param dataType
 * @param requestId
 * @param rpcProtocolVersion rpc??????????
 * @param serialization
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
private Object decodeResponse(byte[] body, byte dataType, long requestId, byte rpcProtocolVersion,
        Serialization serialization) throws IOException, ClassNotFoundException {

    ObjectInput input = createInput(getInputStream(body));

    long processTime = input.readLong();

    DefaultResponse response = new DefaultResponse();
    response.setRequestId(requestId);
    response.setProcessTime(processTime);

    if (dataType == MotanConstants.FLAG_RESPONSE_VOID) {
        return response;
    }

    String className = input.readUTF();
    Class<?> clz = ReflectUtil.forName(className);

    Object result = deserialize((byte[]) input.readObject(), clz, serialization);

    if (dataType == MotanConstants.FLAG_RESPONSE) {
        response.setValue(result);
    } else if (dataType == MotanConstants.FLAG_RESPONSE_ATTACHMENT) {
        response.setValue(result);
        Map<String, String> attachment = decodeRequestAttachments(input);
        checkAttachment(attachment);
    } else if (dataType == MotanConstants.FLAG_RESPONSE_EXCEPTION) {
        response.setException((Exception) result);
    } else {
        throw new MotanFrameworkException("decode error: response dataType not support " + dataType,
                MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
    }

    response.setRequestId(requestId);

    input.close();

    return response;
}

From source file:com.weibo.api.motan.protocol.rpc.CompressRpcCodec.java

private Object decodeRequest(byte[] body, long requestId, String remoteIp, Serialization serialization)
        throws IOException, ClassNotFoundException {

    ObjectInput input = createInput(getInputStream(body));
    String interfaceName = null;/* w ww .j  a v a  2 s  .  c o m*/
    String methodName = null;
    String paramtersDesc = null;
    String group = null;
    String version = null;

    String flag = input.readUTF();

    if (SIGN_FLAG.equals(flag)) {// ???
        String sign = input.readUTF();
        MethodInfo mInfo = SIGN_METHOD_MAP.get(sign);
        if (mInfo == null) {
            throw new MotanFrameworkException("decode error: invalid method sign: " + sign,
                    MotanErrorMsgConstant.FRAMEWORK_DECODE_ERROR);
        }
        interfaceName = mInfo.getInterfaceName();
        methodName = mInfo.getMethodName();
        paramtersDesc = mInfo.getParamtersDesc();
        group = mInfo.getGroup();
        version = mInfo.getVersion();
    } else {
        interfaceName = flag;
        methodName = input.readUTF();
        paramtersDesc = input.readUTF();
    }

    DefaultRequest rpcRequest = new DefaultRequest();
    rpcRequest.setRequestId(requestId);
    rpcRequest.setInterfaceName(interfaceName);
    rpcRequest.setMethodName(methodName);
    rpcRequest.setParamtersDesc(paramtersDesc);
    rpcRequest.setArguments(decodeRequestParameter(input, paramtersDesc, serialization));
    rpcRequest.setAttachments(decodeRequestAttachments(input));
    rpcRequest.setRpcProtocolVersion(RpcProtocolVersion.VERSION_2.getVersion());

    input.close();
    Map<String, String> attachments = rpcRequest.getAttachments();
    putSignedAttachment(attachments, remoteIp);// ???client?
    if (attachments.get(URLParamType.group.name()) == null) {
        // attachment sign?methodsigngroup?
        attachments.put(URLParamType.group.name(), group);
        attachments.put(URLParamType.version.name(), version);
    }

    return rpcRequest;
}