Example usage for java.io DataOutput writeInt

List of usage examples for java.io DataOutput writeInt

Introduction

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

Prototype

void writeInt(int v) throws IOException;

Source Link

Document

Writes an int value, which is comprised of four bytes, to the output stream.

Usage

From source file:org.xdi.oxauth.cert.fingerprint.FingerprintHelper.java

private static void writeDataWithLength(byte[] data, DataOutput byteBuffer) throws IOException {
    byteBuffer.writeInt(data.length);
    byteBuffer.write(data);//from  w w  w .java2  s.c  o  m
}

From source file:Main.java

public static void writeByteBuffer(byte[] buf, int offset, int length, DataOutput out) throws Exception {
    if (buf != null) {
        out.write(1);/*from w ww .j  av  a 2 s.co  m*/
        out.writeInt(length);
        out.write(buf, offset, length);
    } else {
        out.write(0);
    }
}

From source file:org.jactr.io.antlr3.serialization.Serializer.java

static public void write(CommonTree tree, DataOutput output) throws IOException {
    output.writeInt(tree.getType());
    output.writeUTF(tree.getText());/*w  ww .  jav  a  2s.  c om*/

    // we ignore the token

    CommonToken token = (CommonToken) tree.getToken();
    output.writeInt(token.getType());
    output.writeUTF(token.getText());
    output.writeInt(token.getStartIndex());
    output.writeInt(token.getStopIndex());
    output.writeInt(token.getLine());
    output.writeInt(token.getCharPositionInLine());

    output.writeInt(tree.getTokenStartIndex());
    output.writeInt(tree.getTokenStopIndex());

    int start = -1;
    int end = -1;
    String url = "";
    if (tree instanceof DetailedCommonTree) {
        start = ((DetailedCommonTree) tree).getStartOffset();
        end = ((DetailedCommonTree) tree).getStopOffset();
        if (((DetailedCommonTree) tree).getSource() != null)
            url = ((DetailedCommonTree) tree).getSource().toString();
    }

    output.writeInt(start);
    output.writeInt(end);
    output.writeUTF(url);

    // children
    output.writeInt(tree.getChildCount());
    for (int i = 0; i < tree.getChildCount(); i++)
        write((CommonTree) tree.getChild(i), output);
}

From source file:org.mrgeo.utils.StringUtils.java

public static void write(String str, DataOutput out) throws IOException {
    if (str == null) {
        out.writeInt(-1);
    } else {/*from  w w w  .  j av  a 2s. com*/
        byte[] data = str.getBytes("UTF-8");
        out.writeInt(data.length);
        out.write(data);
    }
}

From source file:org.apache.mahout.classifier.df.DFUtils.java

/**
 * Writes an int[] into a DataOutput//from ww  w  .  ja  va  2 s .c  om
 * @throws java.io.IOException
 */
public static void writeArray(DataOutput out, int[] array) throws IOException {
    out.writeInt(array.length);
    for (int value : array) {
        out.writeInt(value);
    }
}

From source file:org.apache.mahout.classifier.df.DFUtils.java

/**
 * Writes an Node[] into a DataOutput/*from www.  j  av  a  2 s  .  com*/
 * @throws java.io.IOException
 */
public static void writeArray(DataOutput out, Node[] array) throws IOException {
    out.writeInt(array.length);
    for (Node w : array) {
        w.write(out);
    }
}

From source file:org.apache.mahout.classifier.df.DFUtils.java

/**
 * Writes a double[] into a DataOutput/*from w  w  w  .j a  v  a  2 s. c  om*/
 * @throws java.io.IOException
 */
public static void writeArray(DataOutput out, double[] array) throws IOException {
    out.writeInt(array.length);
    for (double value : array) {
        out.writeDouble(value);
    }
}

From source file:com.willetinc.hadoop.mapreduce.dynamodb.AttributeValueIOUtils.java

public static void writeCollection(Types type, Collection<AttributeValue> values, DataOutput out)
        throws IOException {
    int size = values.size();
    out.writeInt(size);
    for (AttributeValue value : values) {
        write(type, value, out);/*from ww  w.  j a va  2s . c  o m*/
    }
}

From source file:mobi.hsz.idea.gitignore.indexing.IgnoreEntryOccurrence.java

/**
 * Static helper to write given {@link IgnoreEntryOccurrence} to the output stream.
 *
 * @param out   output stream//  w ww  .j  av  a 2s  .  com
 * @param entry entry to write
 * @throws IOException I/O exception
 */
public static synchronized void serialize(@NotNull DataOutput out, @NotNull IgnoreEntryOccurrence entry)
        throws IOException {
    out.writeUTF(entry.getFile().getPath());
    out.writeInt(entry.items.size());
    for (Pair<Pattern, Boolean> item : entry.items) {
        out.writeUTF(item.first.pattern());
        out.writeBoolean(item.second);
    }
}

From source file:com.bah.culvert.util.Bytes.java

/**
 * Write the bytes to the output stream//from w  w  w . j a  v a2 s . com
 * @param out to write to
 * @param bytes to write
 * @throws IOException on failure to write
 */
public static void writeByteArray(DataOutput out, byte[] bytes) throws IOException {
    out.writeInt(bytes.length);
    out.write(bytes);
}