Example usage for java.io ObjectInput readUTF

List of usage examples for java.io ObjectInput readUTF

Introduction

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

Prototype

String readUTF() throws IOException;

Source Link

Document

Reads in a string that has been encoded using a modified UTF-8 format.

Usage

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

/**
 * //from  w w  w. j  av a2s.  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:com.inmobi.grill.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 " + qhandle + ":" + opHandle);
        }//from   ww w  .  j  a  v  a 2s. co  m
        LOG.info("HiveDriver recovered " + hiveHandles.size() + " queries");
        int numSessions = in.readInt();
        for (int i = 0; i < numSessions; i++) {
            String grillId = in.readUTF();
            SessionHandle sHandle = new SessionHandle((TSessionHandle) in.readObject(),
                    TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V6);
            grillToHiveSession.put(grillId, sHandle);
        }
        LOG.info("HiveDriver recovered " + grillToHiveSession.size() + " sessions");
    }
}

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  a  v  a 2 s. co m
        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");
    }
}

From source file:com.splicemachine.derby.impl.sql.execute.operations.scanner.TableScannerBuilder.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    template = (ExecRow) in.readObject();
    scan = readScan(in);/* w  w  w . ja v a  2s  . c  om*/
    if (in.readBoolean()) {
        rowColumnMap = new int[in.readInt()];
        for (int i = 0; i < rowColumnMap.length; ++i) {
            rowColumnMap[i] = in.readInt();
        }
    }
    txn = readTxn(in);
    keyColumnEncodingOrder = ArrayUtil.readIntArray(in);
    if (in.readBoolean()) {
        keyColumnSortOrder = ArrayUtil.readBooleanArray(in);
    }
    keyColumnTypes = ArrayUtil.readIntArray(in);
    if (in.readBoolean()) {
        keyDecodingMap = ArrayUtil.readIntArray(in);
    }
    if (in.readBoolean()) {
        baseColumnMap = ArrayUtil.readIntArray(in);
    }
    accessedKeys = (FormatableBitSet) in.readObject();
    reuseRowLocation = in.readBoolean();
    oneSplitPerRegion = in.readBoolean();
    if (in.readBoolean())
        indexName = in.readUTF();
    if (in.readBoolean())
        tableVersion = in.readUTF();

    if (in.readBoolean()) {
        int n = in.readInt();
        fieldLengths = new int[n];
        for (int i = 0; i < n; ++i) {
            fieldLengths[i] = in.readInt();
        }
        n = in.readInt();
        columnPositionMap = new int[n];
        for (int i = 0; i < n; ++i) {
            columnPositionMap[i] = in.readInt();
        }
        baseTableConglomId = in.readLong();
    }
    demarcationPoint = in.readLong();
    if (in.readBoolean())
        optionalProbeValue = (DataValueDescriptor) in.readObject();
    pin = in.readBoolean();
    if (in.readBoolean())
        delimited = in.readUTF();
    if (in.readBoolean())
        escaped = in.readUTF();
    if (in.readBoolean())
        lines = in.readUTF();
    if (in.readBoolean())
        storedAs = in.readUTF();
    if (in.readBoolean())
        location = in.readUTF();
}

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 www. j  a v  a 2  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  ww  . ja va  2  s.  com*/

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

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

    _visit = in.readObject();
}

From source file:org.codehaus.groovy.grails.web.util.StreamCharBuffer.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    int version = in.readInt();
    if (version != EXTERNALIZABLE_VERSION) {
        throw new IOException("Uncompatible version in serialization stream.");
    }/*from  w  ww  . ja  va2  s.c o  m*/
    reset();
    int len = in.readInt();
    if (len > 0) {
        char[] buf = new char[len];
        Reader reader = new InputStreamReader((InputStream) in, "UTF-8");
        reader.read(buf);
        String str = StringCharArrayAccessor.createString(buf);
        MultipartStringChunk mpStringChunk = new MultipartStringChunk(str);
        int partCount = in.readInt();
        for (int i = 0; i < partCount; i++) {
            EncodingStatePart current = new EncodingStatePart();
            mpStringChunk.appendEncodingStatePart(current);
            current.len = in.readInt();
            int encodersSize = in.readInt();
            Set<Encoder> encoders = null;
            if (encodersSize > 0) {
                encoders = new LinkedHashSet<Encoder>();
                for (int j = 0; j < encodersSize; j++) {
                    String codecName = in.readUTF();
                    boolean safe = in.readBoolean();
                    encoders.add(new SavedEncoder(codecName, safe));
                }
            }
            current.encodingState = new EncodingStateImpl(encoders);
        }
        addChunk(mpStringChunk);
    }
}

From source file:org.apache.lens.server.query.QueryExecutionServiceImpl.java

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    super.readExternal(in);
    // Restore drivers
    synchronized (drivers) {
        int numDrivers = in.readInt();
        String driverQualifiedName;
        String driverClsName;//from  w w  w.  ja  va 2s.c o m
        for (int i = 0; i < numDrivers; i++) {
            driverQualifiedName = in.readUTF();
            driverClsName = in.readUTF();
            LensDriver driver = drivers.get(driverQualifiedName);
            if (driver == null) {
                // this driver is removed in the current server restart
                // we will create an instance and read its state still.
                try {
                    Class<? extends LensDriver> driverCls = (Class<? extends LensDriver>) Class
                            .forName(driverClsName);
                    driver = driverCls.newInstance();
                    String[] driverTypeAndName = StringUtils.split(driverQualifiedName, '/');
                    driver.configure(conf, driverTypeAndName[0], driverTypeAndName[1]);
                } catch (Exception e) {
                    log.error("Could not instantiate driver:{} represented by class {}", driverQualifiedName,
                            driverClsName, e);
                    throw new IOException(e);
                }
                log.info("Driver state for {} will be ignored", driverQualifiedName);
            }
            driver.readExternal(in);
        }
    }

    // Restore queries
    synchronized (allQueries) {
        int numQueries = in.readInt();

        for (int i = 0; i < numQueries; i++) {
            QueryContext ctx = (QueryContext) in.readObject();
            ctx.initTransientState();

            //Create DriverSelectorQueryContext by passing all the drivers and the user query
            //Driver conf gets reset in start
            DriverSelectorQueryContext driverCtx = new DriverSelectorQueryContext(ctx.getUserQuery(),
                    new Configuration(), drivers.values());
            ctx.setDriverContext(driverCtx);
            boolean driverAvailable = in.readBoolean();
            // set the selected driver if available, if not available for the cases of queued queries,
            // query service will do the selection from existing drivers and update
            if (driverAvailable) {
                String selectedDriverQualifiedName = in.readUTF();
                if (drivers.get(selectedDriverQualifiedName) != null) {
                    ctx.getDriverContext().setSelectedDriver(drivers.get(selectedDriverQualifiedName));
                    ctx.setDriverQuery(ctx.getSelectedDriver(), ctx.getSelectedDriverQuery());
                } else {
                    log.info("Ignoring {} as the driver is not loaded", ctx.getQueryHandle());
                    continue;
                }
            }
            allQueries.put(ctx.getQueryHandle(), ctx);
        }
    }
}

From source file:org.grails.buffer.StreamCharBuffer.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    int version = in.readInt();
    if (version != EXTERNALIZABLE_VERSION) {
        throw new IOException("Uncompatible version in serialization stream.");
    }/*w  w  w.j a va 2s. com*/
    reset();
    int len = in.readInt();
    if (len > 0) {
        char[] buf = new char[len];
        Reader reader = new InputStreamReader((InputStream) in, "UTF-8");
        reader.read(buf);
        String str = StringCharArrayAccessor.createString(buf);
        MultipartStringChunk mpStringChunk = new MultipartStringChunk(str);
        int partCount = in.readInt();
        for (int i = 0; i < partCount; i++) {
            EncodingStatePart current = new EncodingStatePart();
            mpStringChunk.appendEncodingStatePart(current);
            current.len = in.readInt();
            int encodersSize = in.readInt();
            Set<Encoder> encoders = null;
            if (encodersSize > 0) {
                encoders = new LinkedHashSet<Encoder>();
                for (int j = 0; j < encodersSize; j++) {
                    String codecName = in.readUTF();
                    boolean safe = in.readBoolean();
                    encoders.add(new SavedEncoder(codecName, safe));
                }
            }
            current.encodingState = new EncodingStateImpl(encoders, null);
        }
        addChunk(mpStringChunk);
    }
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

@Override
public void readExternal(ObjectInput input) throws IOException, ClassNotFoundException {
    @SuppressWarnings("unused")
    long sid = input.readLong();
    progressVisible = input.readInt();//w  ww . j  ava2  s.  co m
    progressCancelBtnText = input.readUTF();
    progressMsgText = input.readUTF();
    lclPos = input.readInt();
    lclPosTop = input.readInt();
    profPos = input.readInt();
    profPosTop = input.readInt();
    remPos = input.readInt();
    remPosTop = input.readInt();
    dialogVisible = input.readInt();
    dialogMsgText = input.readUTF();
}