Example usage for java.io ObjectInput readObject

List of usage examples for java.io ObjectInput readObject

Introduction

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

Prototype

public Object readObject() throws ClassNotFoundException, IOException;

Source Link

Document

Read and return an object.

Usage

From source file:gnu.trove.map.custom_hash.TObjectCharCustomHashMap.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    // VERSION/*from   ww  w.  ja  v a2 s  . c  o m*/
    in.readByte();

    // SUPER
    super.readExternal(in);

    // STRATEGY
    strategy = (HashingStrategy<K>) in.readObject();

    // NO_ENTRY_VALUE
    no_entry_value = in.readChar();

    // NUMBER OF ENTRIES
    int size = in.readInt();
    setUp(size);

    // ENTRIES
    while (size-- > 0) {
        //noinspection unchecked
        K key = (K) in.readObject();
        char val = in.readChar();
        put(key, val);
    }
}

From source file:gnu.trove.map.custom_hash.TObjectDoubleCustomHashMap.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    // VERSION/*  w  w w .  j av  a  2s. c  o m*/
    in.readByte();

    // SUPER
    super.readExternal(in);

    // STRATEGY
    strategy = (HashingStrategy<K>) in.readObject();

    // NO_ENTRY_VALUE
    no_entry_value = in.readDouble();

    // NUMBER OF ENTRIES
    int size = in.readInt();
    setUp(size);

    // ENTRIES
    while (size-- > 0) {
        //noinspection unchecked
        K key = (K) in.readObject();
        double val = in.readDouble();
        put(key, val);
    }
}

From source file:gnu.trove.map.custom_hash.TObjectFloatCustomHashMap.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

    // VERSION/*www. j a  va2 s  .c  o  m*/
    in.readByte();

    // SUPER
    super.readExternal(in);

    // STRATEGY
    strategy = (HashingStrategy<K>) in.readObject();

    // NO_ENTRY_VALUE
    no_entry_value = in.readFloat();

    // NUMBER OF ENTRIES
    int size = in.readInt();
    setUp(size);

    // ENTRIES
    while (size-- > 0) {
        //noinspection unchecked
        K key = (K) in.readObject();
        float val = in.readFloat();
        put(key, val);
    }
}

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

private Object[] decodeRequestParameter(ObjectInput input, String parameterDesc, Serialization serialization)
        throws IOException, ClassNotFoundException {
    if (parameterDesc == null || parameterDesc.equals("")) {
        return null;
    }//  w w w . j  a v  a  2s.c  o m

    Class<?>[] classTypes = ReflectUtil.forNames(parameterDesc);

    Object[] paramObjs = new Object[classTypes.length];

    for (int i = 0; i < classTypes.length; i++) {
        paramObjs[i] = deserialize((byte[]) input.readObject(), classTypes[i], serialization);
    }

    return paramObjs;
}

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

/**
 * //from  w  ww .ja  v  a  2 s .  c  o  m
 * @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:org.openfaces.component.table.impl.TableDataModel.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    groupingRules = (List<GroupingRule>) in.readObject();
    sortingRules = (List<SortingRule>) in.readObject();
    rowKeyExpression = ValueBindings.readValueExpression(in);
    rowDataByKeyExpression = ValueBindings.readValueExpression(in);
    pageSize = in.readInt();/*ww w.  java 2  s . com*/
    pageIndex = in.readInt();
    setWrappedData(null);

    // restoring old extracted row keys is needed for correct restoreRows/restoreRowIndexes functionality, which
    // in turn is required for correct data submission in case of concurrent data modifications
    extractedRowKeys = (List) in.readObject();
}

From source file:org.apache.lens.driver.hive.HiveDriver.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    synchronized (hiveHandles) {
        int numHiveHnadles = in.readInt();
        for (int i = 0; i < numHiveHnadles; i++) {
            QueryHandle qhandle = (QueryHandle) in.readObject();
            OperationHandle opHandle = new OperationHandle((TOperationHandle) in.readObject());
            hiveHandles.put(qhandle, opHandle);
            log.debug("Hive driver {} recovered {}:{}", getFullyQualifiedName(), qhandle, opHandle);
        }/*from   w w w .  j av a2 s .  c o m*/
        log.info("Hive driver {} recovered {} queries", getFullyQualifiedName(), hiveHandles.size());
        int numSessions = in.readInt();
        for (int i = 0; i < numSessions; i++) {
            String lensId = in.readUTF();
            SessionHandle sHandle = new SessionHandle((TSessionHandle) in.readObject(),
                    TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6);
            lensToHiveSession.put(lensId, sHandle);
        }
        log.info("Hive driver {} recovered {} sessions", getFullyQualifiedName(), lensToHiveSession.size());
    }
    int numOpHandles = in.readInt();
    for (int i = 0; i < numOpHandles; i++) {
        OperationHandle opHandle = new OperationHandle((TOperationHandle) in.readObject());
        SessionHandle sHandle = new SessionHandle((TSessionHandle) in.readObject(),
                TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6);
        opHandleToSession.put(opHandle, sHandle);
    }
    log.info("Hive driver {} recovered {} operation handles", getFullyQualifiedName(),
            opHandleToSession.size());
    int numOrphanedSessions = in.readInt();
    for (int i = 0; i < numOrphanedSessions; i++) {
        SessionHandle sHandle = new SessionHandle((TSessionHandle) in.readObject(),
                TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6);
        orphanedHiveSessions.add(sHandle);
    }
    log.info("Hive driver {} recovered {} orphaned sessions", getFullyQualifiedName(),
            orphanedHiveSessions.size());
}

From source file:org.apache.tapestry.engine.AbstractEngine.java

/**
 *  Reads the state serialized by {@link #writeExternal(ObjectOutput)}.
 *
 *  <p>This always set the stateful flag.  By default, a deserialized
 *  session is stateful (else, it would not have been serialized).
 **//*from   w  w w.j a v a2 s  .  c  o  m*/

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    _stateful = true;

    String localeName = in.readUTF();
    _locale = Tapestry.getLocale(localeName);

    _visit = in.readObject();
}

From source file:com.inmobi.grill.server.query.QueryExecutionServiceImpl.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    Map<String, GrillDriver> driverMap = new HashMap<String, GrillDriver>();
    synchronized (drivers) {
        drivers.clear();/*from  www  .  j  av a  2s. c om*/
        int numDrivers = in.readInt();
        for (int i = 0; i < numDrivers; i++) {
            String driverClsName = in.readUTF();
            GrillDriver driver;
            try {
                Class<? extends GrillDriver> driverCls = (Class<? extends GrillDriver>) Class
                        .forName(driverClsName);
                driver = (GrillDriver) driverCls.newInstance();
                driver.configure(conf);
            } catch (Exception e) {
                LOG.error("Could not instantiate driver:" + driverClsName);
                throw new IOException(e);
            }
            driver.readExternal(in);
            drivers.add(driver);
            driverMap.put(driverClsName, driver);
        }
    }
    synchronized (allQueries) {
        int numQueries = in.readInt();
        for (int i = 0; i < numQueries; i++) {
            QueryContext ctx = (QueryContext) in.readObject();
            allQueries.put(ctx.getQueryHandle(), ctx);
            boolean driverAvailable = in.readBoolean();
            if (driverAvailable) {
                String clsName = in.readUTF();
                ctx.setSelectedDriver(driverMap.get(clsName));
            }
            try {
                ctx.setConf(getGrillConf(null, ctx.getQconf()));
            } catch (GrillException e) {
                LOG.error("Could not set query conf");
            }
        }

        // populate the query queues
        for (QueryContext ctx : allQueries.values()) {
            switch (ctx.getStatus().getStatus()) {
            case NEW:
            case QUEUED:
                // queued queries wont recovered.
                try {
                    setFailedStatus(ctx, "Launching query failed due to server restart", "Server is restarted");
                } catch (GrillException e) {
                    LOG.error("Failing query " + ctx.getQueryHandle() + " failed", e);
                }
                break;
            case LAUNCHED:
            case RUNNING:
                launchedQueries.add(ctx);
                break;
            case SUCCESSFUL:
            case FAILED:
            case CANCELED:
                updateFinishedQuery(ctx, null);
                break;
            case CLOSED:
                allQueries.remove(ctx.getQueryHandle());
            }
        }
        LOG.info("Recovered " + allQueries.size() + " queries");
    }
}