Example usage for java.io ObjectOutput write

List of usage examples for java.io ObjectOutput write

Introduction

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

Prototype

public void write(byte b[]) throws IOException;

Source Link

Document

Writes an array of bytes.

Usage

From source file:com.delphix.session.impl.frame.SessionHandle.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(handle.length);/*from w w  w . ja  v a 2s . c om*/
    out.write(handle);
}

From source file:com.splicemachine.derby.stream.compaction.SparkCompactionFunction.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    byte[] hriBytes = hri.toByteArray();
    super.writeExternal(out);
    out.writeLong(smallestReadPoint);//from  ww  w . j  ava2  s . c o  m
    out.writeInt(namespace.length);
    out.write(namespace);
    out.writeInt(tableName.length);
    out.write(tableName);
    out.writeInt(hriBytes.length);
    out.write(hriBytes);
    out.writeInt(storeColumn.length);
    out.write(storeColumn);
}

From source file:com.ning.metrics.serialization.event.SmileEnvelopeEvent.java

/**
 * The object implements the writeExternal method to save its contents
 * by calling the methods of DataOutput for its primitive values or
 * calling the writeObject method of ObjectOutput for objects, strings,
 * and arrays./*from  ww w.  jav  a  2s  .  com*/
 *
 * @param out the stream to write the object to
 * @throws java.io.IOException Includes any I/O exceptions that may occur
 * @serialData Overriding methods should use this tag to describe
 * the data layout of this Externalizable object.
 * List the sequence of element types and, if possible,
 * relate the element to a public/protected field and/or
 * method of this Externalizable class.
 */
@Override
public void writeExternal(final ObjectOutput out) throws IOException {
    // Name of the event
    final byte[] eventNameBytes = eventName.getBytes(NAME_CHARSET);
    out.writeInt(eventNameBytes.length);
    out.write(eventNameBytes);

    final byte[] payloadBytes = getSerializedEvent();

    // Size of Smile payload. Needed for deserialization, see below
    out.writeInt(payloadBytes.length);

    out.write(payloadBytes);
}

From source file:com.talis.storage.s3.ExternalizableS3Object.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    out.writeUTF(getKey());/*w w w .j av  a 2  s.c o  m*/
    out.writeUTF(getBucketName());
    out.writeObject(getAcl());
    out.writeBoolean(isMetadataComplete());
    out.writeObject(getMetadataMap());
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
        IOUtils.copy(this.getDataInputStream(), buffer);
    } catch (S3ServiceException e) {
        LOG.error("Error copying entity stream", e);
        throw new IOException("Error serializing object", e);
    }
    out.writeInt(buffer.toByteArray().length);
    out.write(buffer.toByteArray());
}

From source file:com.openlapi.AddressInfo.java

public void writeExternal(ObjectOutput out) throws IOException {
    byte[] attributeFlags = new byte[NUM_FIELDS];
    int attributeCount = 0;
    for (int i = 1; i <= NUM_FIELDS; i++) {
        if (getField(i) != null) {
            attributeFlags[i - 1] = BYTE_ONE;
            attributeCount++;// w ww  .  ja  v  a 2 s.co  m
        }
    }

    out.write(attributeCount);

    if (attributeCount > 0) {

        Integer[] attributes = new Integer[attributeCount];

        int j = attributeCount;

        for (int i = 0; i < NUM_FIELDS; i++) {
            if (attributeFlags[i] == BYTE_ONE) {
                j--;
                attributes[j] = i;
            }
        }

        out.writeUTF(StringUtils.join(attributes, ","));

        for (int i = 0; i < attributeCount; i++) {
            int attribute = attributes[i];
            out.writeUTF(getField(attribute + 1));
        }

    }

}

From source file:com.px100systems.util.serialization.SerializationDefinition.java

/**
 * Externalizable helper - should be used in Externalizable implementations.
 * @param out output/*from   w  ww.j a va2  s .c om*/
 * @param bean bean
 */
public void write(ObjectOutput out, Object bean) {
    DataStream ds = new DataStream();
    try {
        write(ds, bean);
        byte[] data = ds.getData();
        out.writeInt(data.length);
        out.write(data);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        ds.close();
    }
}

From source file:com.splicemachine.derby.stream.function.RowAndIndexGenerator.java

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    try {//from   w w w .jav  a 2s  . c  o m
        out.writeLong(heapConglom);
        out.writeBoolean(operationContext != null);
        if (operationContext != null)
            out.writeObject(operationContext);
        SIDriver.driver().getOperationFactory().writeTxn(txn, out);
        ArrayUtil.writeIntArray(out, pkCols);
        out.writeUTF(tableVersion);
        out.writeObject(execRowDefinition);
        out.writeInt(autoIncrementRowLocationArray.length);
        for (int i = 0; i < autoIncrementRowLocationArray.length; i++)
            out.writeObject(autoIncrementRowLocationArray[i]);
        out.writeInt(spliceSequences.length);
        for (int i = 0; i < spliceSequences.length; i++) {
            out.writeObject(spliceSequences[i]);
        }
        out.writeLong(heapConglom);
        out.writeInt(tentativeIndices.size());
        for (DDLMessage.TentativeIndex ti : tentativeIndices) {
            byte[] message = ti.toByteArray();
            out.writeInt(message.length);
            out.write(message);
        }
    } catch (Exception e) {
        throw new IOException(e);
    }

}

From source file:org.apache.rahas.Token.java

/**
 * Implementing serialize logic according to our own protocol. We had to follow this, because
 * OMElement class is not serializable. Making OMElement serializable will have an huge impact
 * on other components. Therefore implementing serialization logic according to a manual
 * protocol./*from   w  w  w .j av  a  2s .c om*/
 * @param out Stream which writes serialized bytes.
 * @throws IOException If unable to serialize particular member.
 */
public void writeExternal(ObjectOutput out) throws IOException {

    out.writeObject(this.id);

    out.writeInt(this.state);

    String stringElement = convertOMElementToString(this.token);
    out.writeObject(stringElement);

    stringElement = convertOMElementToString(this.previousToken);
    out.writeObject(stringElement);

    stringElement = convertOMElementToString(this.attachedReference);
    out.writeObject(stringElement);

    stringElement = convertOMElementToString(this.unattachedReference);
    out.writeObject(stringElement);

    out.writeObject(this.properties);

    out.writeBoolean(this.changed);

    int secretLength = 0;
    if (null != this.secret) {
        secretLength = this.secret.length;
    }

    // First write the length of secret
    out.writeInt(secretLength);
    if (0 != secretLength) {
        out.write(this.secret);
    }

    out.writeObject(this.created);

    out.writeObject(this.expires);

    out.writeObject(this.issuerAddress);

    out.writeObject(this.encrKeySha1Value);
}

From source file:org.apache.shindig.gadgets.http.HttpResponse.java

public void writeExternal(ObjectOutput out) throws IOException {
    out.writeInt(httpStatusCode);/*from  w  w  w  .jav a 2  s  . co m*/
    // Write out multimap as a map (see above)
    Map<String, List<String>> map = Maps.newHashMap();
    for (String key : headers.keySet()) {
        map.put(key, Lists.newArrayList(headers.get(key)));
    }
    out.writeObject(Maps.newHashMap(map));
    out.writeInt(responseBytes.length);
    out.write(responseBytes);
}

From source file:org.codehaus.wadi.core.session.LazyAttributes.java

public synchronized void writeExternal(ObjectOutput oo) throws IOException {
    bytes = serialise();//  ww w.j  av a 2  s .co  m
    oo.writeInt(bytes.length);
    oo.write(bytes);
}