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:edu.caltechUcla.sselCassel.projects.jMarkets.server.control.DispatchServ.java

/** TCP: This method opens up a ServerSocket at the given port then starts a thread that waits
 *  for TCPMonitorReceivers to attempt to connect. Each connecting TCPMonitorReceiver creates an
 *  individual Socket connection, which is then attached to a TCPMonitorTransmitter. The MonitorServ
 *  uses the transmitter to communicate with the receiver, which in turn manipulates the monitor.
 *///from   w ww.  j av  a  2s .  c  om
private int activateTCPMonitorTunnel(int port) {
    try {
        log.info("DispatchServ is creating a TCP ServerSocket on port " + port
                + " for use in server-monitor communication");
        servSock = new ServerSocket(port);

        Runnable registrar = new Runnable() {

            public void run() {

                while (!stopRegThread) {
                    try {
                        monitorSocket = servSock.accept();

                        log.debug(
                                "Communication socket accepted from new monitor, opening input/output streams...");

                        ObjectInputStream inputStream = new ObjectInputStream(monitorSocket.getInputStream());
                        ObjectOutputStream outputStream = new ObjectOutputStream(
                                monitorSocket.getOutputStream());

                        outputStream.flush();

                        log.debug("Input stream opened, reading session ID from connecting monitor");
                        int sessionId = inputStream.readInt();
                        log.debug("Session ID " + sessionId
                                + " read from new monitor socket, pairing TCP receiver with a transmitter");

                        MonitorTransmitter transmitter = new TCPMonitorTransmitter(monitorSocket, inputStream,
                                outputStream);
                        registerMonitorTransmitter(transmitter, sessionId);
                    } catch (Exception e) {
                        log.warn(
                                "Error while accepting a monitor socket connection -- returning to 'waiting for accept' state",
                                e);
                        System.out.println(
                                "Error while accepting a monitor socket connection -- returning to 'waiting for accept' state");
                        e.printStackTrace();
                        continue;
                    }
                }
                /*log.error("exited while loop");
                try{
                monitorSocket.close();
                } catch( IOException ioe ){
                log.warn("Error while trying to close monitorSocket");
                ioe.printStackTrace();
                }*/
            }
        };

        registrationThread = new Thread(registrar);
        registrationThread.setDaemon(true);
        registrationThread.start();

        return port;
    } catch (Exception re) {
        log.error("Error activating ServerSocket for use in TCP monitor communication", re);
        return OPERATION_FAILED;
    }
}

From source file:IntHashMap.java

/**
 * Reconstitute the <tt>HashMap</tt> instance from a stream (i.e.,
 * deserialize it)./*from  ww w .j a  v  a2 s . c o m*/
 * 
 * @param s
 * @throws IOException
 * @throws ClassNotFoundException
 */
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in the threshold, loadfactor, and any hidden stuff
    s.defaultReadObject();

    // Read in number of buckets and allocate the bucket array;
    int numBuckets = s.readInt();
    table = new Entry[numBuckets];

    init(); // Give subclass a chance to do its thing.

    // Read in size (number of Mappings)
    int size = s.readInt();

    // Read the keys and values, and put the mappings in the HashMap
    for (int i = 0; i < size; i++) {
        int key = s.readInt();
        Object value = s.readObject();
        putForCreate(key, value);
    }
}

From source file:IntHashMap.java

/**
 * Reconstitute the <tt>HashMap</tt> instance from a stream (i.e., deserialize it).
 * //w w w  .j  a  v  a 2  s .com
 * @param s
 * @throws IOException
 * @throws ClassNotFoundException
 */
@SuppressWarnings("unchecked")
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException {
    // Read in the threshold, loadfactor, and any hidden stuff
    s.defaultReadObject();

    // Read in number of buckets and allocate the bucket array;
    int numBuckets = s.readInt();
    table = new Entry[numBuckets];

    init(); // Give subclass a chance to do its thing.

    // Read in size (number of Mappings)
    int size = s.readInt();

    // Read the keys and values, and put the mappings in the HashMap
    for (int i = 0; i < size; i++) {
        int key = s.readInt();
        V value = (V) s.readObject();
        putForCreate(key, value);
    }
}

From source file:org.dishevelled.multimap.impl.AbstractHashedMap.java

/**
 * Reads the map data from the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 *
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.//from  w w  w . ja  va 2 s.com
 *
 * The solution adopted here is to deserialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>readObject()</code> of the first serializable subclass.
 *
 * Subclasses may override if the subclass has a specific field that must be present
 * before <code>put()</code> or <code>calculateThreshold()</code> will work correctly.
 *
 * @param in the input stream
 * @throws IOException if an I/O error occurs
 * @throws ClassNotFoundException if a deserialized class cannot be found
 */
protected void doReadObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    loadFactor = in.readFloat();
    int capacity = in.readInt();
    int size = in.readInt();
    init();
    data = new HashEntry[capacity];
    for (int i = 0; i < size; i++) {
        K key = (K) in.readObject();
        V value = (V) in.readObject();
        put(key, value);
    }
    threshold = calculateThreshold(data.length, loadFactor);
}

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

public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session)
        throws IOException, ClassNotFoundException {
    log.trace("deserializing persistent-context");
    StatefulPersistenceContext rtn = new StatefulPersistenceContext(session);

    // during deserialization, we need to reconnect all proxies and
    // collections to this session, as well as the EntityEntry and
    // CollectionEntry instances; these associations are transient
    // because serialization is used for different things.

    try {/*from w w w .j a va2  s. c o m*/
        rtn.defaultReadOnly = ois.readBoolean();
        // todo : we can actually just determine this from the incoming EntityEntry-s
        rtn.hasNonReadOnlyEntities = ois.readBoolean();

        int count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] entitiesByKey entries");
        rtn.entitiesByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitiesByKey.put(EntityKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] entitiesByUniqueKey entries");
        rtn.entitiesByUniqueKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitiesByUniqueKey.put(EntityUniqueKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] proxiesByKey entries");
        rtn.proxiesByKey = new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK,
                count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count, .75f);
        for (int i = 0; i < count; i++) {
            EntityKey ek = EntityKey.deserialize(ois, session);
            Object proxy = ois.readObject();
            if (proxy instanceof HibernateProxy) {
                ((HibernateProxy) proxy).getHibernateLazyInitializer().setSession(session);
                rtn.proxiesByKey.put(ek, proxy);
            } else {
                log.trace("encountered prunded proxy");
            }
            // otherwise, the proxy was pruned during the serialization process
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] entitySnapshotsByKey entries");
        rtn.entitySnapshotsByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitySnapshotsByKey.put(EntityKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] entityEntries entries");
        rtn.entityEntries = IdentityMap.instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            Object entity = ois.readObject();
            EntityEntry entry = EntityEntry.deserialize(ois, session);
            rtn.entityEntries.put(entity, entry);
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] collectionsByKey entries");
        rtn.collectionsByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.collectionsByKey.put(CollectionKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] collectionEntries entries");
        rtn.collectionEntries = IdentityMap
                .instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            final PersistentCollection pc = (PersistentCollection) ois.readObject();
            final CollectionEntry ce = CollectionEntry.deserialize(ois, session);
            pc.setCurrentSession(session);
            rtn.collectionEntries.put(pc, ce);
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] arrayHolders entries");
        rtn.arrayHolders = IdentityMap.instantiate(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.arrayHolders.put(ois.readObject(), ois.readObject());
        }

        count = ois.readInt();
        log.trace("staring deserialization of [" + count + "] nullifiableEntityKeys entries");
        rtn.nullifiableEntityKeys = new HashSet();
        for (int i = 0; i < count; i++) {
            rtn.nullifiableEntityKeys.add(EntityKey.deserialize(ois, session));
        }

    } catch (HibernateException he) {
        throw new InvalidObjectException(he.getMessage());
    }

    return rtn;
}

From source file:org.hibernate.engine.internal.StatefulPersistenceContext.java

public static StatefulPersistenceContext deserialize(ObjectInputStream ois, SessionImplementor session)
        throws IOException, ClassNotFoundException {
    LOG.trace("Serializing persistent-context");
    StatefulPersistenceContext rtn = new StatefulPersistenceContext(session);

    // during deserialization, we need to reconnect all proxies and
    // collections to this session, as well as the EntityEntry and
    // CollectionEntry instances; these associations are transient
    // because serialization is used for different things.

    try {/* w w  w.jav  a  2 s. c  o  m*/
        rtn.defaultReadOnly = ois.readBoolean();
        // todo : we can actually just determine this from the incoming EntityEntry-s
        rtn.hasNonReadOnlyEntities = ois.readBoolean();

        int count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] entitiesByKey entries");
        rtn.entitiesByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitiesByKey.put(EntityKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] entitiesByUniqueKey entries");
        rtn.entitiesByUniqueKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitiesByUniqueKey.put(EntityUniqueKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] proxiesByKey entries");
        rtn.proxiesByKey = new ReferenceMap(AbstractReferenceMap.HARD, AbstractReferenceMap.WEAK,
                count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count, .75f);
        for (int i = 0; i < count; i++) {
            EntityKey ek = EntityKey.deserialize(ois, session);
            Object proxy = ois.readObject();
            if (proxy instanceof HibernateProxy) {
                ((HibernateProxy) proxy).getHibernateLazyInitializer().setSession(session);
                rtn.proxiesByKey.put(ek, proxy);
            } else
                LOG.trace("Encountered prunded proxy");
            // otherwise, the proxy was pruned during the serialization process
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] entitySnapshotsByKey entries");
        rtn.entitySnapshotsByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.entitySnapshotsByKey.put(EntityKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] entityEntries entries");
        rtn.entityEntries = IdentityMap.instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            Object entity = ois.readObject();
            EntityEntry entry = EntityEntry.deserialize(ois, session);
            rtn.entityEntries.put(entity, entry);
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] collectionsByKey entries");
        rtn.collectionsByKey = new HashMap(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.collectionsByKey.put(CollectionKey.deserialize(ois, session), ois.readObject());
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] collectionEntries entries");
        rtn.collectionEntries = IdentityMap
                .instantiateSequenced(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            final PersistentCollection pc = (PersistentCollection) ois.readObject();
            final CollectionEntry ce = CollectionEntry.deserialize(ois, session);
            pc.setCurrentSession(session);
            rtn.collectionEntries.put(pc, ce);
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries");
        rtn.arrayHolders = IdentityMap.instantiate(count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count);
        for (int i = 0; i < count; i++) {
            rtn.arrayHolders.put(ois.readObject(), ois.readObject());
        }

        count = ois.readInt();
        LOG.trace("Starting deserialization of [" + count + "] nullifiableEntityKey entries");
        rtn.nullifiableEntityKeys = new HashSet();
        for (int i = 0; i < count; i++) {
            rtn.nullifiableEntityKeys.add(EntityKey.deserialize(ois, session));
        }

    } catch (HibernateException he) {
        throw new InvalidObjectException(he.getMessage());
    }

    return rtn;
}

From source file:edu.umd.cs.marmoset.modelClasses.Project.java

private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    int thisMinorVersion = stream.readInt();
    if (thisMinorVersion != serialMinorVersion)
        throw new IOException("Illegal minor version " + thisMinorVersion + ", expecting minor version "
                + serialMinorVersion);/*from ww w  .  j  ava  2  s  . c om*/
    stream.defaultReadObject();
}

From source file:CopyOnWriteArrayList.java

/**
 * Reconstitute the list from a stream (i.e., deserialize it).
 * @param s the stream/*from w w w.j  a va2 s  . com*/
 */
private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException {

    // Read in size, and any hidden stuff
    s.defaultReadObject();

    // Read in array length and allocate array
    int len = s.readInt();
    Object[] elements = new Object[len];

    // Read in all elements in the proper order.
    for (int i = 0; i < len; i++)
        elements[i] = s.readObject();
    setArray(elements);

}

From source file:CopyOnWriteArrayList.java

/**
 * Reconstitute the list from a stream (i.e., deserialize it).
 * @param s //from   w ww.  ja va 2s  . c o  m
 * @throws java.io.IOException 
 * @throws ClassNotFoundException 
 */
private synchronized void readObject(java.io.ObjectInputStream s)
        throws java.io.IOException, ClassNotFoundException {
    // Read in size, and any hidden stuff
    s.defaultReadObject();

    // Read in array length and allocate array
    int arrayLength = s.readInt();
    Object[] elementData = new Object[arrayLength];

    // Read in all elements in the proper order.
    for (int i = 0; i < elementData.length; i++)
        elementData[i] = s.readObject();
    array_ = elementData;
}

From source file:ddf.catalog.data.impl.MetacardImpl.java

/**
 * Deserializes this {@link MetacardImpl}'s instance.
 *
 * @param stream the {@link ObjectInputStream} that contains the bytes of the object
 * @throws IOException//from  ww w .jav  a2  s . com
 * @throws ClassNotFoundException
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {

    /*
     * defaultReadObject() is invoked for greater flexibility and compatibility. See the
     * *Serialization Note* in MetacardImpl's class Javadoc.
     */
    stream.defaultReadObject();

    map = new HashMap<String, Attribute>();

    wrappedMetacard = null;

    type = (MetacardType) stream.readObject();

    if (type == null) {
        throw new InvalidObjectException(MetacardType.class.getName() + " instance cannot be null.");
    }

    int numElements = stream.readInt();

    for (int i = 0; i < numElements; i++) {

        Attribute attribute = (Attribute) stream.readObject();

        if (attribute != null) {

            AttributeDescriptor attributeDescriptor = getMetacardType()
                    .getAttributeDescriptor(attribute.getName());

            if (attributeDescriptor != null && attribute.getValue() != null) {
                attributeDescriptor.getType().getAttributeFormat();
                attributeDescriptor.getType().getClass();
            }

        }

        setAttribute(attribute);
    }

}