Example usage for java.io DataOutput write

List of usage examples for java.io DataOutput write

Introduction

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

Prototype

void write(byte b[]) throws IOException;

Source Link

Document

Writes to the output stream all the bytes in array b.

Usage

From source file:org.gradoop.model.impl.properties.PropertyValueList.java

@Override
public void write(DataOutput dataOutput) throws IOException {
    dataOutput.writeShort(bytes.length);
    dataOutput.write(bytes);
}

From source file:org.jcodec.containers.mp4.boxes.Box.java

public void write(DataOutput out) throws IOException {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    doWrite(new DataOutputStream(bout));
    byte[] bytes = bout.toByteArray();

    header.setBodySize(bytes.length);/*from w  ww . ja v a  2s.  c  om*/
    header.write(out);
    out.write(bytes);
}

From source file:org.kalypso.shape.dbf.DBFField.java

@Override
public void write(final DataOutput output, final Charset charset) throws IOException {
    final byte[] bytes = new byte[32];
    Arrays.fill(bytes, 0, bytes.length, (byte) 0);

    // copy name into the first 11 bytes
    final String name = getName();
    final byte[] nameBytes = name.getBytes(charset);
    final int nameLength = Math.min(nameBytes.length, 11);
    System.arraycopy(nameBytes, 0, bytes, 0, nameLength);
    Arrays.fill(bytes, nameLength, 11, (byte) 0);

    final FieldType type = getType();
    bytes[11] = (byte) type.getName();
    bytes[16] = (byte) getLength();
    bytes[17] = (byte) getDecimalCount();

    bytes[20] = 1; // work area id (don't know if it should be 1)

    bytes[31] = 0x00; // has no index tag in a MDX file

    output.write(bytes);
}

From source file:org.kiji.schema.mapreduce.KijiDelete.java

/** {@inheritDoc} */
@Override/*from   w ww .ja v a 2s  .  c o m*/
public void write(DataOutput out) throws IOException {
    // EntityId.
    final byte[] bytes = mEntityId.getHBaseRowKey();
    out.writeInt(bytes.length);
    out.write(bytes);

    // Family/Qualifier/Timestamp.
    writeOptionalValue(mFamily, out);
    writeOptionalValue(mQualifier, out);
    writeOptionalValue(mTimestamp, out);
    writeOptionalValue(mOperation, out);
}

From source file:org.kiji.schema.mapreduce.KijiIncrement.java

/** {@inheritDoc} */
@Override//from  w  w  w.  jav  a  2 s  .c o  m
public void write(DataOutput out) throws IOException {
    final byte[] bytes = mEntityId.getHBaseRowKey();
    out.writeInt(bytes.length);
    out.write(bytes);

    // Family/Qualifier/Amount.
    out.writeUTF(mFamily);
    out.writeUTF(mQualifier);
    out.writeLong(mAmount);
}

From source file:org.kiji.schema.mapreduce.KijiPut.java

/** {@inheritDoc} */
@Override/*  ww w .  j av  a  2  s  .co  m*/
public void write(DataOutput out) throws IOException {
    // EntityId.
    final byte[] bytes = mEntityId.getHBaseRowKey();
    out.writeInt(bytes.length);
    out.write(bytes);

    // Family/Qualifier/Timestamp.
    out.writeUTF(mFamily);
    out.writeUTF(mQualifier);
    out.writeLong(mTimestamp);

    // Avro.
    final KijiCellEncoder encoder = new KijiCellEncoder(null);
    final byte[] cellData = encoder.encode(mCell, KijiCellFormat.NONE);
    out.writeUTF(mCell.getWriterSchema().toString());
    out.writeInt(cellData.length);
    out.write(cellData);
}

From source file:org.lealone.cluster.utils.ByteBufferUtil.java

public static void writeWithShortLength(byte[] buffer, DataOutput out) throws IOException {
    int length = buffer.length;
    assert 0 <= length && length <= Utils.MAX_UNSIGNED_SHORT : length;
    out.writeShort(length);/*w ww .j  ava2  s.  c o  m*/
    out.write(buffer);
}

From source file:org.lilyproject.repository.impl.id.AbsoluteRecordIdImpl.java

@Override
public byte[] toBytes() {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DataOutput dataOutput = new DataOutputStream(byteArrayOutputStream);
    byte[] tableBytes = table.getBytes();
    byte[] recordIdBytes = recordId.toBytes();
    try {/*from  www. j  ava2 s .c  o  m*/
        dataOutput.writeInt(tableBytes.length);
        dataOutput.write(tableBytes);
        dataOutput.writeInt(recordIdBytes.length);
        dataOutput.write(recordIdBytes);
    } catch (IOException ioe) {
        throw new RuntimeException("Error serializing AbsoluteRecordId: " + toString(), ioe);
    }
    return byteArrayOutputStream.toByteArray();
}

From source file:org.lwes.MapEvent.java

@Override
public int serialize(DataOutput output) throws IOException {
    final byte[] bytes = serialize();
    output.write(bytes);
    return bytes.length;
}

From source file:org.mhisoft.common.util.FileUtils.java

/**
 * Write the string to file, return the total number of bytes occupied.
 *
 * @param out/*from w  ww.  j  a v a  2s .  c  o  m*/
 * @param str
 * @return
 * @throws IOException
 */
public static int writeString(DataOutput out, String str) throws IOException {
    if (str == null)
        throw new RuntimeException("input str is null");

    byte[] content = StringUtils.getBytes(str);
    //write size
    byte[] size = ByteArrayHelper.intToBytes(content.length);
    out.write(size);
    out.write(content);
    return size.length + content.length;

}