Example usage for org.apache.hadoop.io WritableUtils writeVInt

List of usage examples for org.apache.hadoop.io WritableUtils writeVInt

Introduction

In this page you can find the example usage for org.apache.hadoop.io WritableUtils writeVInt.

Prototype

public static void writeVInt(DataOutput stream, int i) throws IOException 

Source Link

Document

Serializes an integer to a binary stream with zero-compressed encoding.

Usage

From source file:fi.tkk.ics.hadoop.bam.SequencedFragment.java

License:Open Source License

public void write(DataOutput out) throws IOException {
    // TODO:  reimplement with a serialization system (e.g. Avro)

    sequence.write(out);//from w  ww .  j a  va 2  s  .c  o m
    quality.write(out);

    int presentFlags = 0;
    if (instrument != null)
        presentFlags |= Instrument_Present;
    if (runNumber != null)
        presentFlags |= RunNumber_Present;
    if (flowcellId != null)
        presentFlags |= FlowcellId_Present;
    if (lane != null)
        presentFlags |= Lane_Present;
    if (tile != null)
        presentFlags |= Tile_Present;
    if (xpos != null)
        presentFlags |= Xpos_Present;
    if (ypos != null)
        presentFlags |= Ypos_Present;
    if (read != null)
        presentFlags |= Read_Present;
    if (filterPassed != null)
        presentFlags |= FilterPassed_Present;
    if (controlNumber != null)
        presentFlags |= ControlNumber_Present;
    if (indexSequence != null)
        presentFlags |= IndexSequence_Present;

    WritableUtils.writeVInt(out, presentFlags);

    if (instrument != null)
        WritableUtils.writeString(out, instrument);
    if (runNumber != null)
        WritableUtils.writeVInt(out, runNumber);
    if (flowcellId != null)
        WritableUtils.writeString(out, flowcellId);
    if (lane != null)
        WritableUtils.writeVInt(out, lane);
    if (tile != null)
        WritableUtils.writeVInt(out, tile);
    if (xpos != null)
        WritableUtils.writeVInt(out, xpos);
    if (ypos != null)
        WritableUtils.writeVInt(out, ypos);
    if (read != null)
        WritableUtils.writeVInt(out, read);
    if (filterPassed != null)
        WritableUtils.writeVInt(out, filterPassed ? 1 : 0);
    if (controlNumber != null)
        WritableUtils.writeVInt(out, controlNumber);
    if (indexSequence != null)
        WritableUtils.writeString(out, indexSequence);
}

From source file:gaffer.statistics.impl.CappedMinuteCount.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    /**/*w  w w .jav a 2  s . co m*/
     * Write out:
     *  - the max number of entries
     *  - whether this is full or not
     *  - if not full then write:
     *      - the number of entries in the map int -> long
     *      - the smallest int in the map and its long
     *      - from then on write the next int in the map by subtracting the smallest int
     *      (this will make the int smaller and hence potentially more compact to write out
     *      using the WritableUtils method) and its long
     */
    WritableUtils.writeVInt(out, maxEntries);
    out.writeBoolean(full);
    if (!full) {
        int size = minuteToCount.keySet().size();
        WritableUtils.writeVInt(out, size);
        int smallestInt = -1;
        for (int i : minuteToCount.keySet()) {
            if (smallestInt == -1) {
                smallestInt = i;
                WritableUtils.writeVInt(out, smallestInt);
            } else {
                WritableUtils.writeVInt(out, i - smallestInt);
            }
            WritableUtils.writeVLong(out, minuteToCount.get(i));
        }
    }
}

From source file:gaffer.statistics.impl.DailyCount.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, dayToCount.keySet().size());
    for (int i : dayToCount.keySet()) {
        WritableUtils.writeVInt(out, i);
        WritableUtils.writeVLong(out, dayToCount.get(i));
    }//  w  w  w  . j  a v  a 2s  .com
}

From source file:gaffer.statistics.impl.HourlyCount.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, hourToCount.keySet().size());
    for (int i : hourToCount.keySet()) {
        WritableUtils.writeVInt(out, i);
        WritableUtils.writeVLong(out, hourToCount.get(i));
    }/*from w w  w.  j a v  a 2s.  c  o m*/
}

From source file:ilps.hadoop.ResultObject.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {

    try {/*from   w  ww  .j  a  va2s.c  o  m*/

        out.writeLong(score);
        out.writeUTF(topic);
        out.writeUTF(stream_id);

        byte[] bytes = serializer.serialize(document);
        WritableUtils.writeVInt(out, bytes.length);
        out.write(bytes, 0, bytes.length);

    } catch (TException e) {
        e.printStackTrace();
        throw new IOException(e);
    }
}

From source file:ilps.hadoop.StreamItemWritable.java

License:Apache License

/**
 * Deserializes this object.// w w w.  j ava  2  s.co m
 */
@Override
public void write(DataOutput out) throws IOException {

    try {

        byte[] bytes = serializer.serialize(this);
        WritableUtils.writeVInt(out, bytes.length);
        out.write(bytes, 0, bytes.length);

    } catch (TException e) {
        e.printStackTrace();
        throw new IOException(e);
    }

}

From source file:io.bfscan.data.VByteDocVector.java

License:Apache License

public static void toBytesWritable(BytesWritable bytes, int[] termids, int length) {
    try {//w  w  w. j  a  v a2s  . com
        if (termids == null) {
            termids = new int[] {};
            length = 0;
        }

        ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        DataOutputStream dataOut = new DataOutputStream(bytesOut);

        WritableUtils.writeVInt(dataOut, length);
        for (int i = 0; i < length; i++) {
            WritableUtils.writeVInt(dataOut, termids[i]);
        }

        byte[] raw = bytesOut.toByteArray();
        bytes.set(raw, 0, raw.length);
    } catch (IOException e) {
        bytes.set(new byte[] {}, 0, 0);
    }
}

From source file:io.fluo.accumulo.data.WriteUtilImpl.java

License:Apache License

@Override
public void writeVInt(DataOutput stream, int i) throws IOException {
    WritableUtils.writeVInt(stream, i);
}

From source file:io.fluo.api.data.Bytes.java

License:Apache License

/**
 * Writes Bytes to DataOutput /*ww w  .  j  a v  a 2 s .  c  o m*/
 * 
 * @param out DataOutput
 * @param b Bytes
 * @throws IOException
 */
public static void write(DataOutput out, Bytes b) throws IOException {
    WritableUtils.writeVInt(out, b.length());
    if (b.isBackedByArray()) {
        out.write(b.getBackingArray(), b.offset(), b.length());
    } else {
        for (int i = 0; i < b.length(); i++) {
            out.write(b.byteAt(i) & 0xff);
        }
    }
}

From source file:io.fluo.api.data.Bytes.java

License:Apache License

/**
 * Concatenates of list of Bytes objects to create a byte array
 * /*from   w  ww.j a va 2 s.  c  o  m*/
 * @param listOfBytes
 * @return Bytes
 */
public static Bytes concat(Bytes... listOfBytes) {
    try {
        // TODO calculate exact array size needed
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);

        for (Bytes b : listOfBytes) {
            WritableUtils.writeVInt(dos, b.length());
            if (b.isBackedByArray()) {
                dos.write(b.getBackingArray(), b.offset(), b.length());
            } else {
                dos.write(b.toArray());
            }
        }

        dos.close();
        return wrap(baos.toByteArray());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}