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[], int off, int len) throws IOException;

Source Link

Document

Writes len bytes from array b, in order, to the output stream.

Usage

From source file:com.icloud.framework.core.util.FBUtilities.java

public static void writeByteArray(ByteBuffer bytes, DataOutput out) throws IOException {
    out.writeInt(bytes.remaining());//  w  w w.j  ava  2s . co m
    out.write(bytes.array(), bytes.position() + bytes.arrayOffset(), bytes.remaining());
}

From source file:com.wsc.myexample.decisionForest.MyDataset.java

public static void writeString(DataOutput out, String s) throws IOException {
    if (s != null) {
        byte[] buffer = s.getBytes("UTF-8");
        int len = buffer.length;
        out.writeInt(len);// www.  jav a 2s  .c  o m
        out.write(buffer, 0, len);
    } else {
        out.writeInt(-1);
    }
}

From source file:com.icloud.framework.core.util.FBUtilities.java

public static void writeShortByteArray(ByteBuffer name, DataOutput out) {
    int length = name.remaining();
    assert 0 <= length && length <= MAX_UNSIGNED_SHORT;
    try {/*  w  w w.j  av  a  2 s . co  m*/
        out.writeByte((length >> 8) & 0xFF);
        out.writeByte(length & 0xFF);
        out.write(name.array(), name.position() + name.arrayOffset(), name.remaining());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.glaf.core.util.ByteBufferUtils.java

public static void write(ByteBuffer buffer, DataOutput out) throws IOException {
    if (buffer.hasArray()) {
        out.write(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining());
    } else {//from  w w  w .j  av a2s  . co  m
        for (int i = buffer.position(); i < buffer.limit(); i++) {
            out.writeByte(buffer.get(i));
        }
    }
}

From source file:io.Text.java

/** Write a UTF8 encoded string to out
 *///from   ww  w.jav  a 2 s .c om
public static int writeString(DataOutput out, String s) throws IOException {
    ByteBuffer bytes = encode(s);
    int length = bytes.limit();
    WritableUtils.writeVInt(out, length);
    out.write(bytes.array(), 0, length);
    return length;
}

From source file:com.marklogic.mapreduce.DatabaseDocument.java

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(contentType.ordinal());
    WritableUtils.writeVInt(out, content.length);
    out.write(content, 0, content.length);
}

From source file:io.UTF8.java

public void write(DataOutput out) throws IOException {
    out.writeShort(length);
    out.write(bytes, 0, length);
}

From source file:com.buaa.cfs.io.UTF8.java

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

From source file:edu.umd.cloud9.collection.wikipedia.WikipediaPage.java

/**
 * Deserializes this object.//from w ww  .  j a  va  2 s  . c  o  m
 */
public void write(DataOutput out) throws IOException {
    byte[] bytes = page.getBytes();
    WritableUtils.writeVInt(out, bytes.length);
    out.write(bytes, 0, bytes.length);
    out.writeUTF(language);
}

From source file:edu.umn.cs.spatialHadoop.core.ZCurvePartitioner.java

@Override
public void write(DataOutput out) throws IOException {
    mbr.write(out);/*from  w w w.  j  ava 2s.  co  m*/
    out.writeInt(zSplits.length);
    ByteBuffer bbuffer = ByteBuffer.allocate(zSplits.length * 8);
    for (long zSplit : zSplits)
        bbuffer.putLong(zSplit);
    if (bbuffer.hasRemaining())
        throw new RuntimeException("Did not calculate buffer size correctly");
    out.write(bbuffer.array(), bbuffer.arrayOffset(), bbuffer.position());
}