Example usage for java.io ObjectOutput writeObject

List of usage examples for java.io ObjectOutput writeObject

Introduction

In this page you can find the example usage for java.io ObjectOutput writeObject.

Prototype

public void writeObject(Object obj) throws IOException;

Source Link

Document

Write an object to the underlying storage or stream.

Usage

From source file:org.openide.windows.TopComponent.java

/** Serialize this top component.
* Subclasses wishing to store state must call the super method, then write to the stream.
* @param out the stream to serialize to/*  w  ww  . ja va 2s.  c o m*/
*/
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(new Short(serialVersion));

    out.writeInt(closeOperation);
    out.writeObject(getName());
    out.writeObject(getToolTipText());

    Node.Handle h = nodeName == null ? null : nodeName.node.getHandle();
    out.writeObject(h);
}

From source file:com.moscona.dataSpace.persistence.DirectoryDataStore.java

@Override
public void dump(DataSpace dataSpace) throws DataSpaceException {
    stats.startTimerFor(TIMING_DUMP_DATA_SPACE);
    String file = dataSpaceFileName();
    try {/*www. ja v  a2  s. c  o  m*/
        OutputStream out = new FileOutputStream(file);
        try {
            ObjectOutput objOut = new ObjectOutputStream(out);
            try {
                objOut.writeObject(dataSpace);
            } finally {
                objOut.close();
            }
        } finally {
            out.close();
        }
        //dumpDataSpaceSummary(dataSpace);
    } catch (Exception e) {
        throw new DataSpaceException("Exception while saving data space " + file + ": " + e, e);
    } finally {
        stopTimerFor(TIMING_DUMP_DATA_SPACE);
    }
}

From source file:org.openfaces.component.table.TableDataModel.java

public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(sortingRules);
    ValueBindings.writeValueExpression(out, rowKeyExpression);
    ValueBindings.writeValueExpression(out, rowDataByKeyExpression);
    out.writeInt(pageSize);/*  w  ww . j  av a 2 s.  c om*/
    out.writeInt(pageIndex);
    out.writeObject(extractedRowKeys);
}

From source file:com.moscona.dataSpace.persistence.DirectoryDataStore.java

@Override
public void dumpSegment(IVectorSegment segment) throws DataSpaceException {
    stats.startTimerFor(TIMING_DUMP_SEGMENT);
    try {/*ww w  .j a v a  2 s .  co  m*/
        AbstractVectorSegment abstractSegment = (AbstractVectorSegment) segment;
        SegmentFileInfo fileInfo = new SegmentFileInfo(segment);

        File file = new File(fileInfo.filePath);
        File parent = file.getParentFile();
        ensureDirExists(parent.getAbsolutePath());

        IVectorSegmentBackingArray backingArray = abstractSegment.getBackingArray();
        try {
            OutputStream out = new FileOutputStream(file);
            try {
                ObjectOutput objOut = new ObjectOutputStream(new GZIPOutputStream(out));
                try {
                    objOut.writeObject(backingArray);
                } finally {
                    objOut.close();
                }
            } finally {
                out.close();
            }
        } catch (Exception e) {
            throw new DataSpaceException(
                    "Exception while saving backing array to " + fileInfo.filePath + ": " + e, e);
        }
        markSwappedIn(abstractSegment);
    } catch (InvalidStateException e) {
        throw new DataSpaceException("Exception while dumping segment: " + e, e);
    } finally {
        stopTimerFor(TIMING_DUMP_SEGMENT);
    }
}

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

/**
 * Implementation of the {@link Externalizable} interface to write
 * the properties returned by {@link #toProperties}.
 *//*w  w w  .  j a v a  2s . c o m*/
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(toProperties(true));
    out.writeObject(_props);
    out.writeBoolean(_globals);
}

From source file:LayeredPaneDemo4.java

public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(m_titleBarBackground);
    out.writeObject(m_titleBarForeground);
    out.writeObject(m_BorderColor);/*from   w ww. j a va2  s .  c  o m*/
    out.writeObject(m_selectedTitleBarBackground);
    out.writeObject(m_selectedBorderColor);

    out.writeObject(m_title);

    out.writeBoolean(m_iconizeable);
    out.writeBoolean(m_resizeable);
    out.writeBoolean(m_closeable);
    out.writeBoolean(m_maximizeable);

    out.writeObject(m_frameIcon);
    out.writeObject(getBounds());
}

From source file:SequencedHashMap.java

/**
 * Serializes this map to the given stream.
 *
 * @param out the stream to serialize to
 * @throws IOException if the stream raises it
 *///from ww  w  .  j ava  2s .c  o  m
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(size());
    for (Entry pos = sentinel.next; pos != sentinel; pos = pos.next) {
        out.writeObject(pos.getKey());
        out.writeObject(pos.getValue());
    }
}

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

public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(_docid);
    out.writeObject(_store);
}

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

/**
 * {@inheritDoc}/*  w ww  . j  a  v  a  2 s. co  m*/
 */
public void storeSupscriptions(final QueryOperationsSession session, QueryParams queryParams, String dest,
        String subscrId, SubscriptionControls controls, String trigger,
        QuerySubscriptionScheduled newSubscription, String queryName, Schedule schedule)
        throws SQLException, ImplementationExceptionResponse {
    String insert = "INSERT INTO subscription (subscriptionid, "
            + "params, dest, sched, trigg, initialrecordingtime, "
            + "exportifempty, queryname, lastexecuted) VALUES "
            + "((?), (?), (?), (?), (?), (?), (?), (?), (?))";
    PreparedStatement stmt = session.getConnection().prepareStatement(insert);
    LOG.debug("QUERY: " + insert);
    try {
        stmt.setString(1, subscrId);
        LOG.debug("       query param 1: " + subscrId);

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(outStream);
        out.writeObject(queryParams);
        ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
        stmt.setBinaryStream(2, inStream, inStream.available());
        LOG.debug("       query param 2: [" + inStream.available() + " bytes]");

        stmt.setString(3, dest.toString());
        LOG.debug("       query param 3: " + dest);

        outStream = new ByteArrayOutputStream();
        out = new ObjectOutputStream(outStream);
        out.writeObject(schedule);
        inStream = new ByteArrayInputStream(outStream.toByteArray());
        stmt.setBinaryStream(4, inStream, inStream.available());
        LOG.debug("       query param 4: [" + inStream.available() + " bytes]");

        stmt.setString(5, trigger);
        LOG.debug("       query param 5: " + trigger);

        Calendar cal = newSubscription.getInitialRecordTime();
        Timestamp ts = new Timestamp(cal.getTimeInMillis());
        String time = ts.toString();
        stmt.setString(6, time);
        LOG.debug("       query param 6: " + time);

        stmt.setBoolean(7, controls.isReportIfEmpty());
        LOG.debug("       query param 7: " + controls.isReportIfEmpty());

        stmt.setString(8, queryName);
        LOG.debug("       query param 8: " + queryName);

        stmt.setString(9, time);
        LOG.debug("       query param 9: " + time);

        stmt.executeUpdate();
    } catch (IOException e) {
        String msg = "Unable to store the subscription to the database: " + e.getMessage();
        LOG.error(msg);
        ImplementationException iex = new ImplementationException();
        iex.setReason(msg);
        iex.setSeverity(ImplementationExceptionSeverity.ERROR);
        throw new ImplementationExceptionResponse(msg, iex, e);
    }
}

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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*  w  ww .  j  a  va 2  s.  c  om*/
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));
}