Example usage for java.io ObjectInputStream readInt

List of usage examples for java.io ObjectInputStream readInt

Introduction

In this page you can find the example usage for java.io ObjectInputStream readInt.

Prototype

public int readInt() throws IOException 

Source Link

Document

Reads a 32 bit int.

Usage

From source file:org.eclipse.wb.internal.core.utils.IOUtils2.java

/**
 * @return the byte[] array, read length and then bytes.
 *///from   ww w  .j  av a 2s .com
public static byte[] readByteArray(ObjectInputStream ois) throws IOException {
    int length = ois.readInt();
    byte[] bytes = new byte[length];
    ois.readFully(bytes);
    return bytes;
}

From source file:org.apache.falcon.state.store.jdbc.BeanMapperUtil.java

/**
 * Converts instance entry of DB to instance of ExecutionInstance.
 * @param instanceBean/*  ww w  .  j  av a2  s.c  o  m*/
 * @return
 * @throws StateStoreException
 * @throws IOException
 */
public static InstanceState convertToInstanceState(InstanceBean instanceBean)
        throws StateStoreException, IOException {
    EntityType entityType = InstanceID.getEntityType(instanceBean.getId());
    ExecutionInstance executionInstance = getExecutionInstance(entityType, instanceBean);
    if (instanceBean.getActualEndTime() != null) {
        executionInstance.setActualEnd(new DateTime(instanceBean.getActualEndTime().getTime()));
    }
    if (instanceBean.getActualStartTime() != null) {
        executionInstance.setActualStart(new DateTime(instanceBean.getActualStartTime().getTime()));
    }
    executionInstance.setExternalID(instanceBean.getExternalID());
    executionInstance.setInstanceSequence(instanceBean.getInstanceSequence());

    byte[] result = instanceBean.getAwaitedPredicates();
    List<Predicate> predicates = new ArrayList<>();
    if (result != null && result.length != 0) {
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(result);
        ObjectInputStream in = null;
        try {
            in = new ObjectInputStream(byteArrayInputStream);
            int length = in.readInt();
            for (int i = 0; i < length; i++) {
                Predicate predicate = (Predicate) in.readObject();
                predicates.add(predicate);
            }
        } catch (ClassNotFoundException e) {
            throw new IOException(e);
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    executionInstance.setAwaitingPredicates(predicates);
    InstanceState instanceState = new InstanceState(executionInstance);
    instanceState.setCurrentState(InstanceState.STATE.valueOf(instanceBean.getCurrentState()));
    return instanceState;
}

From source file:org.aksw.dice.eaglet.uri.impl.FileBasedCachingUriCheckerManager.java

public static ObjectLongOpenHashMap<String> readCacheFile(File cacheFile) {
    if (!cacheFile.exists() || cacheFile.isDirectory()) {
        return null;
    }/* w  w  w .j  ava 2  s .  co m*/
    FileInputStream fin = null;
    ObjectInputStream oin = null;
    try {
        fin = new FileInputStream(cacheFile);
        oin = new ObjectInputStream(fin);
        // first, read the number of URIs
        int count = oin.readInt();
        String uri;
        ObjectLongOpenHashMap<String> cache = new ObjectLongOpenHashMap<String>(2 * count);
        for (int i = 0; i < count; ++i) {
            uri = (String) oin.readObject();
            cache.put(uri, oin.readLong());
        }
        return cache;
    } catch (Exception e) {
        LOGGER.error("Exception while reading cache file.", e);
    } finally {
        IOUtils.closeQuietly(oin);
        IOUtils.closeQuietly(fin);
    }
    return null;
}

From source file:Main.java

/**
 * Reads a <code>Stroke</code> object that has been serialised by the
 * {@link SerialUtilities#writeStroke(Stroke, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The stroke object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 */// w w  w .j  a va 2s.  c  o  m
public static Stroke readStroke(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Stroke result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (c.equals(BasicStroke.class)) {
            final float width = stream.readFloat();
            final int cap = stream.readInt();
            final int join = stream.readInt();
            final float miterLimit = stream.readFloat();
            final float[] dash = (float[]) stream.readObject();
            final float dashPhase = stream.readFloat();
            result = new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
        } else {
            result = (Stroke) stream.readObject();
        }
    }
    return result;

}

From source file:Main.java

public static Stroke readStroke(ObjectInputStream in) throws IOException, ClassNotFoundException {
    boolean wroteStroke = in.readBoolean();
    if (wroteStroke) {
        boolean serializedStroke = in.readBoolean();
        if (serializedStroke) {
            return (Stroke) in.readObject();
        } else {//from  ww w.  j  av a2s .  c  o  m
            float[] dash = null;
            int dashLength = in.read();

            if (dashLength != 0) {
                dash = new float[dashLength];
                for (int i = 0; i < dashLength; i++) {
                    dash[i] = in.readFloat();
                }
            }

            float lineWidth = in.readFloat();
            int endCap = in.readInt();
            int lineJoin = in.readInt();
            float miterLimit = in.readFloat();
            float dashPhase = in.readFloat();

            return new BasicStroke(lineWidth, endCap, lineJoin, miterLimit, dash, dashPhase);
        }
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * Reads a <code>AttributedString</code> object that has been serialised by
 * the {@link SerialUtilities#writeAttributedString(AttributedString,
 * ObjectOutputStream)} method./*from   w  w  w. j av  a2  s.c o  m*/
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The attributed string object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 */
public static AttributedString readAttributedString(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    AttributedString result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        // read string and attributes then create result
        String plainStr = (String) stream.readObject();
        result = new AttributedString(plainStr);
        char c = stream.readChar();
        int start = 0;
        while (c != CharacterIterator.DONE) {
            int limit = stream.readInt();
            Map atts = (Map) stream.readObject();
            result.addAttributes(atts, start, limit);
            start = limit;
            c = stream.readChar();
        }
    }
    return result;
}

From source file:org.hibernate.engine.ActionQueue.java

/**
 * Used by the owning session to explicitly control deserialization of the
 * action queue/*  w  w  w.j  av a2 s .  c  o  m*/
 *
 * @param ois The stream from which to read the action queue
 *
 * @throws IOException
 */
public static ActionQueue deserialize(ObjectInputStream ois, SessionImplementor session)
        throws IOException, ClassNotFoundException {
    log.trace("deserializing action-queue");
    ActionQueue rtn = new ActionQueue(session);

    int queueSize = ois.readInt();
    log.trace("starting deserialization of [" + queueSize + "] insertions entries");
    rtn.insertions = new ArrayList(queueSize);
    for (int i = 0; i < queueSize; i++) {
        rtn.insertions.add(ois.readObject());
    }

    queueSize = ois.readInt();
    log.trace("starting deserialization of [" + queueSize + "] deletions entries");
    rtn.deletions = new ArrayList(queueSize);
    for (int i = 0; i < queueSize; i++) {
        rtn.deletions.add(ois.readObject());
    }

    queueSize = ois.readInt();
    log.trace("starting deserialization of [" + queueSize + "] updates entries");
    rtn.updates = new ArrayList(queueSize);
    for (int i = 0; i < queueSize; i++) {
        rtn.updates.add(ois.readObject());
    }

    queueSize = ois.readInt();
    log.trace("starting deserialization of [" + queueSize + "] collectionUpdates entries");
    rtn.collectionUpdates = new ArrayList(queueSize);
    for (int i = 0; i < queueSize; i++) {
        rtn.collectionUpdates.add(ois.readObject());
    }

    queueSize = ois.readInt();
    log.trace("starting deserialization of [" + queueSize + "] collectionRemovals entries");
    rtn.collectionRemovals = new ArrayList(queueSize);
    for (int i = 0; i < queueSize; i++) {
        rtn.collectionRemovals.add(ois.readObject());
    }

    queueSize = ois.readInt();
    log.trace("starting deserialization of [" + queueSize + "] collectionCreations entries");
    rtn.collectionCreations = new ArrayList(queueSize);
    for (int i = 0; i < queueSize; i++) {
        rtn.collectionCreations.add(ois.readObject());
    }
    return rtn;
}

From source file:com.projity.pm.task.TaskSnapshot.java

public static TaskSnapshot deserialize(ObjectInputStream s, NormalTask hasAssignments)
        throws IOException, ClassNotFoundException {
    TaskSnapshot t = new TaskSnapshot();
    TaskSchedule schedule = TaskSchedule.deserialize(s);
    schedule.setTask(hasAssignments);//from w w w.  jav a 2  s . com
    t.setCurrentSchedule(schedule);
    t.hasAssignments = new HasAssignmentsImpl();//(HasAssignments)s.readObject();

    t.setFixedCost(s.readDouble());
    t.setFixedCostAccrual(s.readInt());
    t.setIgnoreResourceCalendar(s.readBoolean());

    if (hasAssignments.getVersion() >= 2) {
        t.hasAssignments.setSchedulingType(s.readInt());
        t.hasAssignments.setEffortDriven(s.readBoolean());
    }
    return t;
}

From source file:org.apache.flink.api.common.accumulators.ListAccumulator.java

@Override
public void read(ObjectInputStream in) throws IOException {
    int numItems = in.readInt();
    for (int i = 0; i < numItems; i++) {
        int len = in.readInt();
        byte[] obj = new byte[len];
        in.read(obj);/*from   ww  w . j a  v a2s . co m*/
        localValue.add(obj);
    }
}

From source file:org.apache.openjpa.lib.util.LRUMap.java

protected void doReadObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    _max = in.readInt();
    super.doReadObject(in);
}