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:com.newland.bi.bigdata.hdfs.Configuration.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Properties props = getProps();
    WritableUtils.writeVInt(out, props.size());
    for (Map.Entry<Object, Object> item : props.entrySet()) {
        org.apache.hadoop.io.Text.writeString(out, (String) item.getKey());
        org.apache.hadoop.io.Text.writeString(out, (String) item.getValue());
        WritableUtils.writeCompressedStringArray(out, updatingResource.get(item.getKey()));
    }//www. j a  v  a2s .  c om
}

From source file:com.ning.metrics.action.hdfs.data.RowSmile.java

License:Apache License

/**
 * Serialize the row into the DataOutput
 *
 * @param out DataOutput to write/*from w  ww .  jav  a  2s  .com*/
 * @throws java.io.IOException generic serialization error
 */
@Override
public void write(DataOutput out) throws IOException {
    schema.write(out);
    WritableUtils.writeVInt(out, data.size());

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    JsonGenerator gen = objectMapper.getJsonFactory().createJsonGenerator(outStream, JsonEncoding.UTF8);
    for (JsonNodeComparable dataItem : data) {
        objectMapper.writeValue(gen, dataItem);
    }
    gen.close();

    // Size of Smile payload. Needed for deserialization, see below
    WritableUtils.writeVInt(out, outStream.size());

    out.write(outStream.toByteArray());
}

From source file:com.ning.metrics.action.hdfs.data.RowText.java

License:Apache License

/**
 * Serialize the row into the DataOutput
 *
 * @param out DataOutput to write//  w w w  .j a  v  a 2 s.c om
 * @throws java.io.IOException generic serialization error
 */
@Override
public void write(DataOutput out) throws IOException {
    schema.write(out);
    WritableUtils.writeVInt(out, data.size());

    for (String dataItem : data) {
        byte[] bytes = dataItem.getBytes();

        out.writeInt(bytes.length);
        out.write(bytes);
    }
}

From source file:com.ning.metrics.action.hdfs.data.RowThrift.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    schema.write(out);//  w  ww. j  a va 2s  . c  o m
    WritableUtils.writeVInt(out, data.size());

    for (DataItem dataItem : data) {
        dataItem.write(out);
    }
}

From source file:com.placeiq.piqconnect.BlockWritable.java

License:Apache License

@Override
public void write(DataOutput dataOutput) throws IOException {
    if (!TYPE.MATRIX.equals(type)) {
        int v = (vectorElemValues.size() << 2) | (type.getValue() & 0x03);
        WritableUtils.writeVInt(dataOutput, v);
        for (int i = 0; i < vectorElemValues.size(); i++) {
            if (vectorElemValues.getQuick(i) != -1) {
                WritableUtils.writeVInt(dataOutput, i);
                WritableUtils.writeVLong(dataOutput, vectorElemValues.getQuick(i));
            }/*from w w  w  . j  a va 2  s. c om*/
        }
        WritableUtils.writeVInt(dataOutput, END_OF_LIST);
    } else {
        int v = (matrixElemIndexes.size() << 2) | (type.getValue() & 0x03);
        WritableUtils.writeVInt(dataOutput, v);
        WritableUtils.writeVLong(dataOutput, blockRow);
        for (int i = 0; i < matrixElemIndexes.size(); i++) {
            WritableUtils.writeVInt(dataOutput, matrixElemIndexes.get(i));
        }
    }
}

From source file:cosmos.records.impl.MapRecord.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Text.writeString(out, this.docId);

    byte[] cvBytes = this.docVisibility.flatten();
    WritableUtils.writeVInt(out, cvBytes.length);
    out.write(cvBytes);/*from   w  w w.  j  a va 2s  .c o m*/

    WritableUtils.writeVInt(out, this.document.size());
    for (Entry<Column, RecordValue<?>> entry : this.document.entrySet()) {
        entry.getKey().write(out);
        entry.getValue().write(out);
    }
}

From source file:cosmos.records.impl.MultimapRecord.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    Text.writeString(out, this.docId);

    byte[] cvBytes = this.docVisibility.getExpression();
    WritableUtils.writeVInt(out, cvBytes.length);
    out.write(cvBytes);/*from  w  w w  .  j  a  va 2s  .c o  m*/

    WritableUtils.writeVInt(out, this.document.size());
    for (Entry<Column, RecordValue<?>> entry : this.document.entries()) {
        entry.getKey().write(out);
        entry.getValue().write(out);
    }
}

From source file:cosmos.records.values.IntegerRecordValue.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeString(out, IntegerRecordValue.class.getName());
    writeVisibility(out);/* ww  w .j  a v a2s.  co  m*/
    WritableUtils.writeVInt(out, value);
}

From source file:cosmos.records.values.RecordValue.java

License:Apache License

protected void writeVisibility(DataOutput out) throws IOException {
    byte[] cvBytes = this.visibility.getExpression();
    WritableUtils.writeVInt(out, cvBytes.length);
    out.write(cvBytes);/*w ww .j  a  va2  s .c  om*/
}

From source file:edu.gslis.streamcorpus.StreamItemWritable.java

License:Apache License

/**
 * Deserializes this object./*  w  w w.  ja  v a 2  s .c o  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);
        // out.writeUTF(language);

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

}