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:SequencedHashMap.java

/**
 * Deserializes this map from the given stream.
 *
 * @param in the stream to deserialize from
 * @throws IOException            if the stream raises it
 * @throws ClassNotFoundException if the stream raises it
 *///w ww.  j  av  a 2s  .c o  m
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        Object key = in.readObject();
        Object value = in.readObject();
        put(key, value);
    }
}

From source file:ArraySet.java

@SuppressWarnings("unchecked")
public final void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {

    int num = in.readInt();
    mapTable = createArray(num);/*from   ww w  .  java 2  s .c  om*/
    listTable = createArray(num);
    threshold = (int) (num * LOAD_FACTOR);
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        K key = (K) in.readObject();
        V value = (V) in.readObject();
        put(key, value);
    }
}

From source file:org.ecoinformatics.seek.ecogrid.EcoGridServicesController.java

public void readServices() {

    File saveFile = new File(_saveFileName);

    if (saveFile.exists()) {
        try {/*from w  ww.jav a  2s.c om*/
            InputStream is = new FileInputStream(saveFile);
            ObjectInput oi = new ObjectInputStream(is);
            Object newObj = oi.readObject();
            oi.close();

            Vector<EcoGridService> servs = (Vector<EcoGridService>) newObj;
            for (EcoGridService egs : servs) {
                addService(egs);
            }

            return;
        } catch (Exception e1) {
            // problem reading file, try to delete it
            log.warn("Exception while reading EcoGridServices file: " + e1.getMessage());
            try {
                saveFile.delete();
            } catch (Exception e2) {
                log.warn("Unable to delete EcoGridServices file: " + e2.getMessage());
            }
        }
    } else {
        // initialize default services from the Config.xml file
        readServicesFromConfig();
    }
}

From source file:org.apache.openjpa.lib.conf.ConfigurationImpl.java

/**
 * Implementation of the {@link Externalizable} interface to read from
 * the properties written by {@link #writeExternal}.
 *//*from   w w  w. j  av  a  2 s.  c o m*/
@SuppressWarnings("unchecked")
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    fromProperties((Map) in.readObject());
    _props = (Map) in.readObject();
    _globals = in.readBoolean();
}

From source file:LayeredPaneDemo4.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    setTitleBarBackground((Color) in.readObject());
    setTitleBarForeground((Color) in.readObject());
    setBorderColor((Color) in.readObject());
    setSelectedTitleBarBackground((Color) in.readObject());
    setSelectedBorderColor((Color) in.readObject());

    setTitle((String) in.readObject());

    setIconizeable(in.readBoolean());/*from  www .  ja  v a 2s  .co  m*/
    setResizeable(in.readBoolean());
    setCloseable(in.readBoolean());
    setMaximizeable(in.readBoolean());
    setSelected(false);

    setFrameIcon((ImageIcon) in.readObject());
    Rectangle r = (Rectangle) in.readObject();
    r.x = getX();
    r.y = getY();
    setBounds(r.x, r.x, r.width, r.height);
}

From source file:org.jfree.data.time.junit.TimeSeriesTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from  w  ww .j  a  v  a2  s. c o  m*/
public void testSerialization() {
    TimeSeries s1 = new TimeSeries("A test");
    s1.add(new Year(2000), 13.75);
    s1.add(new Year(2001), 11.90);
    s1.add(new Year(2002), null);
    s1.add(new Year(2005), 19.32);
    s1.add(new Year(2007), 16.89);
    TimeSeries s2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(s1);
        out.close();
        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        s2 = (TimeSeries) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertTrue(s1.equals(s2));
}

From source file:org.accada.epcis.repository.query.QueryOperationsBackendSQL.java

/**
 * {@inheritDoc}//  w ww .  j a  v a 2 s  .  co  m
 */
public Map<String, QuerySubscriptionScheduled> fetchSubscriptions(final QueryOperationsSession session)
        throws SQLException, ImplementationExceptionResponse {
    String query = "SELECT * FROM subscription";
    LOG.debug("SQL: " + query);
    Statement stmt = session.getConnection().createStatement();
    QuerySubscriptionScheduled storedSubscription;
    GregorianCalendar initrectime = new GregorianCalendar();

    ResultSet rs = stmt.executeQuery(query);
    Map<String, QuerySubscriptionScheduled> subscribedMap = new HashMap<String, QuerySubscriptionScheduled>();
    while (rs.next()) {
        try {
            String subscrId = rs.getString("subscriptionid");

            ObjectInput in = new ObjectInputStream(rs.getBinaryStream("params"));

            QueryParam[] paramArray = (QueryParam[]) in.readObject();
            // convert QueryParam[] to QueryParams
            QueryParams params = new QueryParams();
            for (int i = 0; i < paramArray.length; i++) {
                params.getParam().add(paramArray[i]);
            }
            String dest = rs.getString("dest");

            in = new ObjectInputStream(rs.getBinaryStream("sched"));
            Schedule sched = (Schedule) in.readObject();

            initrectime.setTime(rs.getTimestamp("initialrecordingtime"));

            boolean exportifempty = rs.getBoolean("exportifempty");

            String queryName = rs.getString("queryname");
            String trigger = rs.getString("trigg");

            if (trigger == null || trigger.length() == 0) {
                storedSubscription = new QuerySubscriptionScheduled(subscrId, params, dest,
                        Boolean.valueOf(exportifempty), initrectime, new GregorianCalendar(), sched, queryName);
            } else {
                storedSubscription = new QuerySubscriptionTriggered(subscrId, params, dest,
                        Boolean.valueOf(exportifempty), initrectime, new GregorianCalendar(), queryName,
                        trigger, sched);
            }
            subscribedMap.put(subscrId, storedSubscription);
        } catch (SQLException e) {
            // sql exceptions are passed on
            throw e;
        } catch (Exception e) {
            // all other exceptions are caught
            String msg = "Unable to restore subscribed queries from the database.";
            LOG.error(msg, e);
            ImplementationException iex = new ImplementationException();
            iex.setReason(msg);
            iex.setSeverity(ImplementationExceptionSeverity.ERROR);
            throw new ImplementationExceptionResponse(msg, iex, e);
        }
    }
    return subscribedMap;
}

From source file:org.fosstrak.epcis.repository.query.QueryOperationsBackendSQL.java

/**
 * {@inheritDoc}/*  ww w . j av a  2 s  .c o  m*/
 */
public Map<String, QuerySubscriptionScheduled> fetchSubscriptions(final QueryOperationsSession session)
        throws SQLException, ImplementationExceptionResponse {
    String query = "SELECT * FROM subscription";
    LOG.debug("SQL: " + query);
    Statement stmt = session.getConnection().createStatement();
    QuerySubscriptionScheduled storedSubscription;
    GregorianCalendar initrectime = new GregorianCalendar();

    ResultSet rs = stmt.executeQuery(query);
    Map<String, QuerySubscriptionScheduled> subscribedMap = new HashMap<String, QuerySubscriptionScheduled>();
    while (rs.next()) {
        try {
            String subscrId = rs.getString("subscriptionid");

            ObjectInput in = new ObjectInputStream(rs.getBinaryStream("params"));
            QueryParams params = (QueryParams) in.readObject();

            String dest = rs.getString("dest");

            in = new ObjectInputStream(rs.getBinaryStream("sched"));
            Schedule sched = (Schedule) in.readObject();

            initrectime.setTime(rs.getTimestamp("initialrecordingtime"));

            boolean exportifempty = rs.getBoolean("exportifempty");

            String queryName = rs.getString("queryname");
            String trigger = rs.getString("trigg");

            if (trigger == null || trigger.length() == 0) {
                storedSubscription = new QuerySubscriptionScheduled(subscrId, params, dest,
                        Boolean.valueOf(exportifempty), initrectime, new GregorianCalendar(), sched, queryName);
            } else {
                storedSubscription = new QuerySubscriptionTriggered(subscrId, params, dest,
                        Boolean.valueOf(exportifempty), initrectime, new GregorianCalendar(), queryName,
                        trigger, sched);
            }
            subscribedMap.put(subscrId, storedSubscription);
        } catch (SQLException e) {
            // sql exceptions are passed on
            throw e;
        } catch (Exception e) {
            // all other exceptions are caught
            String msg = "Unable to restore subscribed queries from the database.";
            LOG.error(msg, e);
            ImplementationException iex = new ImplementationException();
            iex.setReason(msg);
            iex.setSeverity(ImplementationExceptionSeverity.ERROR);
            throw new ImplementationExceptionResponse(msg, iex, e);
        }
    }
    return subscribedMap;
}

From source file:xbird.xquery.dm.instance.DocumentTableModel.java

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
    this._docid = in.readInt();
    final IDocumentTable doctbl = (IDocumentTable) in.readObject();
    if (doctbl instanceof MemoryMappedDocumentTable) {
        this._mmapedStore = true;
        MemoryMappedDocumentTable mmDoctbl = (MemoryMappedDocumentTable) doctbl;
        String docId = mmDoctbl.getDocumentIdentifer();
        if (docId != null) {
            setPool(mmDoctbl, docId);/*from w  w w  . jav a  2 s  .co  m*/
        }
    }
    this._store = doctbl;
}

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

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

    // VERSION//from w w  w  .j  a  v a2  s. c  om
    in.readByte();

    // SUPER
    super.readExternal(in);

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

    // NO_ENTRY_VALUE
    no_entry_value = in.readByte();

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

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