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

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

Introduction

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

Prototype

public static int readVInt(DataInput stream) throws IOException 

Source Link

Document

Reads a zero-compressed encoded integer from input stream and returns it.

Usage

From source file:ivory.data.PrefixEncodedGlobalStatsWithIndex.java

License:Apache License

private void loadDfs(Path dfStatsPath) throws IOException {
    if (dfs != null)
        return;//from  www  .  ja v a 2s . co m
    FSDataInputStream dfStatsInput = fileSys.open(dfStatsPath);
    int l = dfStatsInput.readInt();
    if (l != prefixSet.length()) {
        throw new RuntimeException("df length mismatch: " + l + "\t" + prefixSet.length());
    }
    dfs = new int[l];
    for (int i = 0; i < l; i++)
        dfs[i] = WritableUtils.readVInt(dfStatsInput);
    dfStatsInput.close();
}

From source file:nl.cwi.kba.thrift.bin.StreamItemWritable.java

License:Apache License

/**
 * Serializes this object.//from w  w w  .  ja v  a 2  s .  co m
 */
@Override
public void readFields(DataInput in) throws IOException {
    try {

        int length = WritableUtils.readVInt(in);
        byte[] bytes = new byte[length];
        in.readFully(bytes, 0, length);

        deserializer.deserialize(this, bytes);

        // WikipediaPage.readPage(this, new String(bytes));
        // language = in.readUTF();

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

}

From source file:org.apache.accumulo.core.client.IteratorSetting.java

License:Apache License

/**
 * @since 1.5.0//ww  w . j av a2  s  .c o m
 * @see Writable
 */
@Override
public void readFields(DataInput din) throws IOException {
    priority = WritableUtils.readVInt(din);
    name = WritableUtils.readString(din);
    iteratorClass = WritableUtils.readString(din);
    properties.clear();
    int size = WritableUtils.readVInt(din);
    while (size > 0) {
        properties.put(WritableUtils.readString(din), WritableUtils.readString(din));
        size--;
    }
}

From source file:org.apache.accumulo.core.data.Key.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {
    // this method is a little screwy so it will be compatible with older
    // code that serialized data

    int colFamilyOffset = WritableUtils.readVInt(in);
    int colQualifierOffset = WritableUtils.readVInt(in);
    int colVisibilityOffset = WritableUtils.readVInt(in);
    int totalLen = WritableUtils.readVInt(in);

    row = new byte[colFamilyOffset];
    colFamily = new byte[colQualifierOffset - colFamilyOffset];
    colQualifier = new byte[colVisibilityOffset - colQualifierOffset];
    colVisibility = new byte[totalLen - colVisibilityOffset];

    in.readFully(row);/*from  www.  j  av a2  s .  c o m*/
    in.readFully(colFamily);
    in.readFully(colQualifier);
    in.readFully(colVisibility);

    timestamp = WritableUtils.readVLong(in);
    deleted = in.readBoolean();
}

From source file:org.apache.accumulo.core.data.Mutation.java

License:Apache License

@Override
public void readFields(DataInput in) throws IOException {

    // Clear out cached column updates and value lengths so
    // that we recalculate them based on the (potentially) new
    // data we are about to read in.
    updates = null;/*from w  ww  . jav a2s. co  m*/
    cachedValLens = -1;
    buffer = null;
    useOldDeserialize = false;

    byte first = in.readByte();
    if ((first & 0x80) != 0x80) {
        oldReadFields(first, in);
        useOldDeserialize = true;
        return;
    }

    int len = WritableUtils.readVInt(in);
    row = new byte[len];
    in.readFully(row);
    len = WritableUtils.readVInt(in);
    data = new byte[len];
    in.readFully(data);
    entries = WritableUtils.readVInt(in);

    boolean valuesPresent = (first & 0x01) == 0x01;
    if (!valuesPresent) {
        values = null;
    } else {
        values = new ArrayList<>();
        int numValues = WritableUtils.readVInt(in);
        for (int i = 0; i < numValues; i++) {
            len = WritableUtils.readVInt(in);
            byte val[] = new byte[len];
            in.readFully(val);
            values.add(val);
        }
    }

    if (0x02 == (first & 0x02)) {
        int numMutations = WritableUtils.readVInt(in);
        this.replicationSources = new HashSet<>();
        for (int i = 0; i < numMutations; i++) {
            replicationSources.add(WritableUtils.readString(in));
        }
    }
}

From source file:org.apache.accumulo.core.file.rfile.RelativeKey.java

License:Apache License

private static void read(DataInput in, MutableByteSequence mbseq) throws IOException {
    int len = WritableUtils.readVInt(in);
    read(in, mbseq, len);/*ww  w .j  av a 2s.  c o  m*/
}

From source file:org.apache.accumulo.core.file.rfile.RelativeKey.java

License:Apache License

private static byte[] readPrefix(DataInput in, ByteSequence prefixSource) throws IOException {
    int prefixLen = WritableUtils.readVInt(in);
    int remainingLen = WritableUtils.readVInt(in);
    byte[] data = new byte[prefixLen + remainingLen];
    if (prefixSource.isBackedByArray()) {
        System.arraycopy(prefixSource.getBackingArray(), prefixSource.offset(), data, 0, prefixLen);
    } else {//  w w w. j  a  v a 2  s.c om
        byte[] prefixArray = prefixSource.toArray();
        System.arraycopy(prefixArray, 0, data, 0, prefixLen);
    }
    // read remaining
    in.readFully(data, prefixLen, remainingLen);
    return data;
}

From source file:org.apache.accumulo.core.file.rfile.RelativeKey.java

License:Apache License

private static void readPrefix(DataInput in, MutableByteSequence dest, ByteSequence prefixSource)
        throws IOException {
    int prefixLen = WritableUtils.readVInt(in);
    int remainingLen = WritableUtils.readVInt(in);
    int len = prefixLen + remainingLen;
    if (dest.getBackingArray().length < len) {
        dest.setArray(new byte[UnsynchronizedBuffer.nextArraySize(len)], 0, 0);
    }//w  w w  . j a v a  2  s . co  m
    if (prefixSource.isBackedByArray()) {
        System.arraycopy(prefixSource.getBackingArray(), prefixSource.offset(), dest.getBackingArray(), 0,
                prefixLen);
    } else {
        byte[] prefixArray = prefixSource.toArray();
        System.arraycopy(prefixArray, 0, dest.getBackingArray(), 0, prefixLen);
    }
    // read remaining
    in.readFully(dest.getBackingArray(), prefixLen, remainingLen);
    dest.setLength(len);
}

From source file:org.apache.accumulo.core.file.rfile.RelativeKey.java

License:Apache License

private static byte[] read(DataInput in) throws IOException {
    int len = WritableUtils.readVInt(in);
    byte[] data = new byte[len];
    in.readFully(data);/*from w  w w.ja  v a 2  s . c o  m*/
    return data;
}

From source file:org.apache.accumulo.core.iterators.aggregation.NumArraySummation.java

License:Apache License

public static long[] bytesToLongArray(byte[] b) throws IOException {
    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(b));
    int len = WritableUtils.readVInt(dis);

    long[] la = new long[len];

    for (int i = 0; i < len; i++) {
        la[i] = WritableUtils.readVLong(dis);
    }/*from  w  w w .  j av  a  2s .c o m*/

    return la;
}