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:com.ibm.sbt.services.client.base.datahandlers.EntityList.java

@Override
public void writeExternal(ObjectOutput outputStream) throws IOException {

    // Serialize the data elements
    outputStream.writeObject(requestData);
    outputStream.writeObject(entities);//from  w  ww. jav a2 s.c om
    outputStream.writeObject(getService());
}

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

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    super.writeExternal(out);
    out.writeBoolean(isRollup);//w ww .j a  va2  s .  c om
    out.writeObject(groupedAggregateContext);
}

From source file:org.jfree.data.xy.junit.XIntervalSeriesCollectionTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from www  .jav  a 2 s  . c o m
public void testSerialization() {
    XIntervalSeriesCollection c1 = new XIntervalSeriesCollection();
    XIntervalSeries s1 = new XIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    XIntervalSeriesCollection c2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(c1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        c2 = (XIntervalSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

From source file:org.jfree.data.xy.junit.YIntervalSeriesCollectionTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from w w w  . j  a v  a 2  s. c  o m*/
public void testSerialization() {
    YIntervalSeriesCollection c1 = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("Series");
    s1.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeriesCollection c2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(c1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        c2 = (YIntervalSeriesCollection) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(c1, c2);
}

From source file:org.wso2.carbon.ml.core.spark.models.MLMatrixFactorizationModel.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    // can't save the whole MatrixFactorizationModel, hence saving relevant attributes separately.
    out.writeInt(model.rank());/*from   www  .ja  va2  s.co  m*/
    out.writeObject(model.userFeatures().toJavaRDD().collect());
    out.writeObject(model.productFeatures().toJavaRDD().collect());

    if (log.isDebugEnabled()) {
        log.debug("Rank, user features and product features of MatrixFactorizationModel were serialized "
                + "successfully.");
    }
}

From source file:com.conwet.silbops.model.AbstractMappingTest.java

@Test
public void shouldExternalize() throws IOException, ClassNotFoundException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutput output = new ObjectOutputStream(baos);

    output.writeObject(instance);
    output.close();/*from w w  w. j av a2s  .  c  om*/

    ObjectInput input = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    T decoded = instance.getThisType().cast(input.readObject());

    assertThat(decoded).isEqualTo(instance);
}

From source file:xbird.xquery.expr.opt.ShippedVariable.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(_type);
    out.writeObject(_varName);/*from w ww . java  2s.  co m*/
    out.writeInt(_identifier);
    final Sequence result = _result;
    if (result == null) {
        out.writeBoolean(false);
        final XQExpression value = _value;
        if (value == null) {
            throw new IllegalStateException();
        }
        out.writeObject(value);
    } else {
        out.writeBoolean(true);
        if (result instanceof RemoteSequence) {
            out.writeBoolean(true);
            RemoteSequence remote = (RemoteSequence) result;
            remote.writeExternal(out);
        } else {
            out.writeBoolean(false);
            final StopWatch sw = new StopWatch("Elapsed time for encoding `$" + getName() + '\'');
            final XQEventEncoder encoder = new XQEventEncoder(out);
            try {
                encoder.emit(result);
            } catch (XQueryException xqe) {
                throw new IllegalStateException("failed encoding `$" + getName() + '\'', xqe);
            } catch (Throwable e) {
                LOG.fatal(e);
                throw new IllegalStateException("failed encoding `$" + getName() + '\'', e);
            }
            if (LOG.isInfoEnabled()) {
                LOG.info(sw);
            }
        }
    }
}

From source file:org.lunarray.model.descriptor.model.extension.impl.ExtensionContainerImpl.java

/** {@inheritDoc} */
@Override//from   ww  w  .  ja  v  a  2 s  . co m
public void writeExternal(final ObjectOutput out) throws IOException {
    Validate.notNull(out, "Output stream may not be null.");
    out.writeObject(this.extensionReferences);
}

From source file:org.rhq.enterprise.server.plugins.alertMicroblog.MicroblogServerPluginComponent.java

private String storeAccessToken(AccessToken token) throws IOException {
    //use buffering
    String filePath = null;//from   w w w. ja v a  2  s. c  o  m
    if (this.context.getDataDirectory().exists() || this.context.getDataDirectory().mkdir()) {

        filePath = this.context.getDataDirectory().getAbsolutePath() + "/OAuthAccessToken_" + token.getUserId()
                + ".ser";

        // merge the PLugin Configuration to store the token file path reference.
        // this property will be user by Microblog AlertSender to load the accessToken from file system
        this.context.getPluginConfiguration().put(new PropertySimple("accessTokenFilePath", filePath));
        this.persistConfiguration(this.context.getPluginConfiguration());

        OutputStream file = new FileOutputStream(filePath);
        OutputStream buffer = new BufferedOutputStream(file);
        ObjectOutput output = new ObjectOutputStream(buffer);

        try {
            output.writeObject(token);
        } finally {
            output.close();

            log.info("AccessToken saved at " + filePath);
        }
    } else
        throw new IOException("AccessToken not stored!");

    return filePath;
}

From source file:com.edsoft.teknosaproject.bean.TreeNodeBean.java

public void saveFile() {
    Path path = Paths.get("E:", "TREE", "hiyerari.txt");
    //Path path = Paths.get("E:", "Hiyerari", "hiyerari.txt");
    OutputStream stream;/*from w  w  w . ja  va2 s.  c om*/
    ObjectOutput object;
    try {
        stream = new FileOutputStream(path.toFile());
        object = new ObjectOutputStream(stream);
        object.writeObject(root);
        object.flush();
        object.close();
        stream.close();
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, "TAMMA", "Baarl"));
    } catch (IOException ex) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "HATA", "Kayt srasnda hata oldu"));
    }
}