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.accada.epcis.repository.query.QuerySubscription.java

/**
 * Updates the subscription in the database. This is required in order to
 * correctly re-initialize the subscriptions, especially the
 * lastTimeExecuted field, after a context restart.
 * <p>// www .ja  va 2  s . com
 * TODO: This is a back-end method: move this method to the
 * QueryOperationsBackend and delegate to it (thus we would need a reference
 * to the QueryOperationsBackend in this class).
 * 
 * @param lastTimeExecuted
 *            The new lastTimeExecuted.
 */
private void updateSubscription(final GregorianCalendar lastTimeExecuted) {
    String jndiName = getProperties().getProperty("jndi.datasource.name", "java:comp/env/jdbc/EPCISDB");
    try {
        // open a database connection
        Context ctx = new InitialContext();
        DataSource db = (DataSource) ctx.lookup(jndiName);
        Connection dbconnection = db.getConnection();

        // update the subscription in the database
        String update = "UPDATE subscription SET lastexecuted=(?), params=(?)" + " WHERE subscriptionid=(?);";
        PreparedStatement stmt = dbconnection.prepareStatement(update);
        LOG.debug("SQL: " + update);
        Timestamp ts = new Timestamp(lastTimeExecuted.getTimeInMillis());
        String time = ts.toString();
        stmt.setString(1, time);
        LOG.debug("       query param 1: " + time);
        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, subscriptionID);
        LOG.debug("       query param 3: " + subscriptionID);
        stmt.executeUpdate();

        // close the database connection
        dbconnection.close();
    } catch (SQLException e) {
        String msg = "An SQL error occurred while updating the subscriptions in the database.";
        LOG.error(msg, e);
    } catch (IOException e) {
        String msg = "Unable to update the subscription in the database: " + e.getMessage();
        LOG.error(msg, e);
    } catch (NamingException e) {
        String msg = "Unable to find JNDI data source with name " + jndiName;
        LOG.error(msg, e);
    }
}

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

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeObject(template);
    writeScan(out);//from   ww  w . j  av  a  2 s . co m
    out.writeBoolean(rowColumnMap != null);
    if (rowColumnMap != null) {
        out.writeInt(rowColumnMap.length);
        //noinspection ForLoopReplaceableByForEach
        for (int i = 0; i < rowColumnMap.length; ++i) {
            out.writeInt(rowColumnMap[i]);
        }
    }
    writeTxn(out);
    ArrayUtil.writeIntArray(out, keyColumnEncodingOrder);
    out.writeBoolean(keyColumnSortOrder != null);
    if (keyColumnSortOrder != null) {
        ArrayUtil.writeBooleanArray(out, keyColumnSortOrder);
    }
    ArrayUtil.writeIntArray(out, keyColumnTypes);
    out.writeBoolean(keyDecodingMap != null);
    if (keyDecodingMap != null) {
        ArrayUtil.writeIntArray(out, keyDecodingMap);
    }
    out.writeBoolean(baseColumnMap != null);
    if (baseColumnMap != null) {
        ArrayUtil.writeIntArray(out, baseColumnMap);
    }
    out.writeObject(accessedKeys);
    out.writeBoolean(reuseRowLocation);
    out.writeBoolean(oneSplitPerRegion);
    out.writeBoolean(indexName != null);
    if (indexName != null)
        out.writeUTF(indexName);
    out.writeBoolean(tableVersion != null);
    if (tableVersion != null)
        out.writeUTF(tableVersion);

    out.writeBoolean(fieldLengths != null);
    if (fieldLengths != null) {
        out.writeInt(fieldLengths.length);
        //noinspection ForLoopReplaceableByForEach
        for (int i = 0; i < fieldLengths.length; ++i) {
            out.writeInt(fieldLengths[i]);
        }
        out.writeInt(columnPositionMap.length);
        //noinspection ForLoopReplaceableByForEach
        for (int i = 0; i < columnPositionMap.length; ++i) {
            out.writeInt(columnPositionMap[i]);
        }
        out.writeLong(baseTableConglomId);
    }
    out.writeLong(demarcationPoint);
    out.writeBoolean(optionalProbeValue != null);
    if (optionalProbeValue != null)
        out.writeObject(optionalProbeValue);
    out.writeBoolean(pin);
    writeNullableString(delimited, out);
    writeNullableString(escaped, out);
    writeNullableString(lines, out);
    writeNullableString(storedAs, out);
    writeNullableString(location, out);
}

From source file:org.jclouds.blobstore.integration.internal.StubAsyncBlobStore.java

public MutableBlobMetadata copy(MutableBlobMetadata in) {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ObjectOutput os;
    try {/*  w w w  . j a  va  2s. c om*/
        os = new ObjectOutputStream(bout);
        os.writeObject(in);
        ObjectInput is = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
        MutableBlobMetadata metadata = (MutableBlobMetadata) is.readObject();
        convertUserMetadataKeysToLowercase(metadata);
        return metadata;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:StringMap.java

public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
    HashMap map = new HashMap(this);
    out.writeObject(map);
}

From source file:com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(VERSION);//  w w w.j  a  v a 2s.  co  m
    out.writeInt(id);
    out.writeInt(packageId);
    ExternalizableUtils.writeUTF(out, name);
    ExternalizableUtils.writeUTF(out, version);
    ExternalizableUtils.writeUTF(out, release);
    out.writeObject(completionTime);
    out.writeObject(creationTime);
    ExternalizableUtils.writeUTF(out, nvr);
    out.writeObject(taskId);
    out.writeObject(ownerId);
    ExternalizableUtils.writeUTF(out, ownerName);
    out.writeObject(buildState);
    out.writeObject(creationEventId);
    ExternalizableUtils.writeUTF(out, mavenGroupId);
    ExternalizableUtils.writeUTF(out, mavenArtifactId);
    ExternalizableUtils.writeUTF(out, mavenVersion);
    ExternalizableUtils.writeUTF(out, platform);
    out.writeObject(extra);
    ExternalizableUtils.writeUTF(out, source);
    // XXX: This has @JsonIgnore
    out.writeObject(typeNames);
    ExternalizableUtils.writeUTF(out, volumeName);
}

From source file:org.perf.log.logger.PerfLogData.java

private void writeStr(String outStr, ObjectOutput out) {
    try {/*from  w w  w.j a  v a 2s  .c o m*/
        if (outStr != null) {
            out.writeInt(outStr.length());
            out.writeObject(outStr);
        } else {
            out.writeInt(0);
        }
    } catch (IOException e) {

        e.printStackTrace();
    }
}

From source file:org.t2framework.commons.util.ArrayMap.java

 public final void writeExternal(final ObjectOutput out) throws IOException {
   out.writeInt(listTable.length);//from ww w. j av a  2 s.co  m
   out.writeInt(size);
   for (int i = 0; i < size; i++) {
      out.writeObject(listTable[i].key_);
      out.writeObject(listTable[i].value_);
   }
}

From source file:com.splicemachine.db.iapi.types.UserType.java

/** 
   @exception IOException error writing data
        /*  w ww.  j  a  v  a  2s  .co m*/
*/
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeBoolean(isNull());
    if (!isNull())
        out.writeObject(value);
}

From source file:StringMap.java

public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException {
    HashMap map = new HashMap(this);
    out.writeBoolean(_ignoreCase);//from  w  ww  .  jav  a 2s .co m
    out.writeObject(map);
}

From source file:ezbake.data.mongo.MongoDriverHandler.java

protected byte[] ser(Object o) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ObjectOutput output = null;
    try {/*from   www.ja v a2s  . co  m*/
        output = new ObjectOutputStream(bOut);
        output.writeObject(o);
    } catch (IOException e) {
        appLog.error(e.toString());
    }
    return bOut.toByteArray();
}