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.asakusafw.runtime.value.DecimalOption.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    if (nullValue) {
        out.writeByte(HEAD_NULL);/*from  w  ww  . ja va2s .co  m*/
    } else {
        DecimalBuffer buffer = BUFFER_MAIN.get();
        buffer.set(entity);

        int head = MASK_PRESENT;
        if (buffer.plus) {
            head |= MASK_PLUS;
        }
        out.writeByte(head);
        WritableUtils.writeVInt(out, buffer.scale);
        byte[] bs = buffer.unsigned;
        int length = bs.length;
        for (int i = 0; i < bs.length; i++) {
            if (bs[i] == 0) {
                length--;
            } else {
                break;
            }
        }
        WritableUtils.writeVInt(out, length);
        if (length != 0) {
            out.write(bs, bs.length - length, length);
        }
    }
}

From source file:com.bah.culvert.data.CKeyValue.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    // Write out the byte length
    WritableUtils.writeVInt(out, this.rowId.length);
    WritableUtils.writeVInt(out, this.family.length);
    WritableUtils.writeVInt(out, this.qualifier.length);
    WritableUtils.writeVInt(out, this.value.length);

    // Write out the actual values
    out.write(this.rowId);
    out.write(this.family);
    out.write(this.qualifier);
    out.write(this.value);

    WritableUtils.writeVLong(out, this.timestamp);
}

From source file:com.bah.culvert.data.CRange.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    // Write out the byte length
    WritableUtils.writeVInt(out, start.length);
    WritableUtils.writeVInt(out, end.length);

    // Write out the actual values
    out.write(start);//from  w  w w. jav  a 2s.c om
    out.write(end);

    out.writeBoolean(startInclusive);
    out.writeBoolean(endInclusive);
}

From source file:com.blm.orc.OrcNewSplit.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    //serialize path, offset, length using FileSplit
    super.write(out);

    int flags = (hasBase ? OrcSplit.BASE_FLAG : 0) | (isOriginal ? OrcSplit.ORIGINAL_FLAG : 0)
            | (hasFooter ? OrcSplit.FOOTER_FLAG : 0);
    out.writeByte(flags);// www  .  j  a  v  a  2s  . co  m
    out.writeInt(deltas.size());
    for (Long delta : deltas) {
        out.writeLong(delta);
    }
    if (hasFooter) {
        // serialize FileMetaInfo fields
        Text.writeString(out, fileMetaInfo.compressionType);
        WritableUtils.writeVInt(out, fileMetaInfo.bufferSize);
        WritableUtils.writeVInt(out, fileMetaInfo.metadataSize);

        // serialize FileMetaInfo field footer
        ByteBuffer footerBuff = fileMetaInfo.footerBuffer;
        footerBuff.reset();

        // write length of buffer
        WritableUtils.writeVInt(out, footerBuff.limit() - footerBuff.position());
        out.write(footerBuff.array(), footerBuff.position(), footerBuff.limit() - footerBuff.position());
        WritableUtils.writeVInt(out, fileMetaInfo.writerVersion.getId());
    }
}

From source file:com.blm.orc.OrcSplit.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    //serialize path, offset, length using FileSplit
    super.write(out);

    int flags = (hasBase ? BASE_FLAG : 0) | (isOriginal ? ORIGINAL_FLAG : 0) | (hasFooter ? FOOTER_FLAG : 0);
    out.writeByte(flags);//from   w  w  w.j av  a  2 s  .  com
    out.writeInt(deltas.size());
    for (Long delta : deltas) {
        out.writeLong(delta);
    }
    if (hasFooter) {
        // serialize FileMetaInfo fields
        Text.writeString(out, fileMetaInfo.compressionType);
        WritableUtils.writeVInt(out, fileMetaInfo.bufferSize);
        WritableUtils.writeVInt(out, fileMetaInfo.metadataSize);

        // serialize FileMetaInfo field footer
        ByteBuffer footerBuff = fileMetaInfo.footerBuffer;
        footerBuff.reset();

        // write length of buffer
        WritableUtils.writeVInt(out, footerBuff.limit() - footerBuff.position());
        out.write(footerBuff.array(), footerBuff.position(), footerBuff.limit() - footerBuff.position());
        WritableUtils.writeVInt(out, fileMetaInfo.writerVersion.getId());
    }
}

From source file:com.chinamobile.bcbsp.action.Directive.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    out.writeInt(faultSSStep);//w w w.j a v  a 2 s .  c o m
    out.writeLong(this.timestamp);
    out.writeInt(this.type.value());
    if (getType().value() == Directive.Type.Request.value()) {
        if (this.actionList == null) {
            WritableUtils.writeVInt(out, 0);
        } else {
            WritableUtils.writeVInt(out, actionList.size());
            for (WorkerManagerAction action : this.actionList) {
                WritableUtils.writeEnum(out, action.getActionType());
                action.write(out);
            }
        }

        WritableUtils.writeCompressedStringArray(out, this.workerManagersName);
    } else if (getType().value() == Directive.Type.Response.value()) {
        this.status.write(out);
    } else {
        throw new IllegalStateException("Wrong directive type:" + getType());
    }

    /* Zhicheng Liu added */
    out.writeInt(this.migrateSSStep);

}

From source file:com.chinamobile.bcbsp.client.BSPJobClient.java

License:Apache License

/**
 * Write splits file header./*from   w w w .j  av a  2s  .c  om*/
 * @param conf Configuration
 * @param filename path of file
 * @param length size of split
 * @return DataOutputStream
 * @throws IOException
 */
private DataOutputStream writeSplitsFileHeader(Configuration conf, Path filename, int length)
        throws IOException {
    // write the splits to a file for the job tracker
    FileSystem files = filename.getFileSystem(conf);
    BSPFSDataOutputStream bspout = new BSPFSDataOutputStreamImpl(files, filename,
            new BSPFspermissionImpl(0).getFp());
    bspout.write(SPLIT_FILE_HEADER);
    WritableUtils.writeVInt(bspout.getOut(), CURRENT_SPLIT_FILE_VERSION);
    WritableUtils.writeVInt(bspout.getOut(), length);
    return bspout.getOut();
}

From source file:com.chinamobile.bcbsp.pipes.BinaryProtocol.java

License:Apache License

/**Send the start command to c++ process and start it.
 * @throws IOException e*//*from   ww w.  ja va2  s . c  o m*/
public void start() throws IOException {
    LOG.debug("starting downlink");
    WritableUtils.writeVInt(outPutstream, MessageType.COMMAND_START.code);
    WritableUtils.writeVInt(outPutstream, CURRENT_PROTOCOL_VERSION);
    flush();
}

From source file:com.chinamobile.bcbsp.pipes.BinaryProtocol.java

License:Apache License

/**Send the close command to c++ process .
 * @throws IOException e*///from   w w  w.jav a 2s .c  o  m
public void endOfInput() throws IOException {
    WritableUtils.writeVInt(outPutstream, MessageType.COMMAND_CLOSE.code);
    this.flush();
    LOG.info("debug:Sent close command");
}

From source file:com.chinamobile.bcbsp.pipes.BinaryProtocol.java

License:Apache License

/**Send the abort command to c++ process.
 * @throws IOException e*///from  w w  w  . java 2  s.co m
public void abort() throws IOException {
    WritableUtils.writeVInt(outPutstream, MessageType.COMMAND_ABORT.code);
    this.flush();
    LOG.debug("Sent abort command");
}