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:cn.iie.haiep.hbase.value.Bytes.java

License:Apache License

/**
 * Write byte-array to out with a vint length prefix.
 * @param out output stream//from  w w  w .j  av  a  2 s . co  m
 * @param b array
 * @param offset offset into array
 * @param length length past offset
 * @throws IOException e
 */
public static void writeByteArray(final DataOutput out, final byte[] b, final int offset, final int length)
        throws IOException {
    WritableUtils.writeVInt(out, length);
    out.write(b, offset, length);
}

From source file:co.cask.cdap.examples.purchase.Purchase.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeString(out, customer);
    WritableUtils.writeString(out, product);
    WritableUtils.writeVInt(out, quantity);
    WritableUtils.writeVInt(out, price);
    WritableUtils.writeVLong(out, purchaseTime);
    WritableUtils.writeString(out, catalogId);
}

From source file:com.asakusafw.bridge.hadoop.directio.Util.java

License:Apache License

static void writeMap(DataOutput out, Map<String, String> map) throws IOException {
    if (map == null) {
        WritableUtils.writeVInt(out, 0);
    } else {/*from   w w w.  j a v  a  2  s.  co m*/
        WritableUtils.writeVInt(out, map.size());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            Text.writeString(out, entry.getKey());
            Text.writeString(out, entry.getValue());
        }
    }
}

From source file:com.asakusafw.runtime.io.util.WritableRawComparableUnion.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, position);
    objects[position].write(out);
}

From source file:com.asakusafw.runtime.stage.collector.SortableSlot.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, slotNumber);
    WritableUtils.writeVInt(out, buffer.getReadLimit());
    out.write(buffer.getData(), 0, buffer.getReadLimit());
}

From source file:com.asakusafw.runtime.stage.collector.WritableSlot.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, buffer.getReadRemaining());
    out.write(buffer.getData(), buffer.getReadPosition(), buffer.getReadRemaining());
}

From source file:com.asakusafw.runtime.stage.input.StageInputDriver.java

License:Apache License

private static String encode(List<StageInput> inputList) throws IOException {
    assert inputList != null;
    String[] dictionary = buildDictionary(inputList);
    ByteArrayOutputStream sink = new ByteArrayOutputStream();
    try (DataOutputStream output = new DataOutputStream(new GZIPOutputStream(new Base64OutputStream(sink)))) {
        WritableUtils.writeVLong(output, SERIAL_VERSION);
        WritableUtils.writeStringArray(output, dictionary);
        WritableUtils.writeVInt(output, inputList.size());
        for (StageInput input : inputList) {
            writeEncoded(output, dictionary, input.getPathString());
            writeEncoded(output, dictionary, input.getFormatClass().getName());
            writeEncoded(output, dictionary, input.getMapperClass().getName());
            WritableUtils.writeVInt(output, input.getAttributes().size());
            for (Map.Entry<String, String> attribute : input.getAttributes().entrySet()) {
                writeEncoded(output, dictionary, attribute.getKey());
                writeEncoded(output, dictionary, attribute.getValue());
            }/*from   ww  w. ja va 2s  .  c o m*/
        }
    }
    return new String(sink.toByteArray(), ASCII);
}

From source file:com.asakusafw.runtime.stage.input.StageInputDriver.java

License:Apache License

private static void writeEncoded(DataOutput output, String[] dictionary, String value) throws IOException {
    assert output != null;
    assert dictionary != null;
    assert value != null;
    int index = Arrays.binarySearch(dictionary, value);
    if (index < 0) {
        throw new IllegalStateException(MessageFormat.format("Value is not in dictionary: value={0}, dict={1}",
                value, Arrays.toString(dictionary)));
    }//from   w w w .j a v  a  2 s . com
    WritableUtils.writeVInt(output, index);
}

From source file:com.asakusafw.runtime.stage.input.StageInputSplit.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    writeClassByName(out, mapperClass);//w  ww .j  av  a  2 s .  c o m
    WritableUtils.writeVInt(out, sources.size());
    for (Source source : sources) {
        Class<? extends InputSplit> splitClass = source.getSplit().getClass();
        writeClassByName(out, source.getFormatClass());
        writeClassByName(out, splitClass);
        ((Writable) source.getSplit()).write(out);
    }
    if (locations == null) {
        WritableUtils.writeVInt(out, -1);
    } else {
        WritableUtils.writeVInt(out, locations.length);
        for (String string : locations) {
            WritableUtils.writeString(out, string);
        }
    }
}

From source file:com.asakusafw.runtime.stage.output.BridgeOutputFormat.java

License:Apache License

private static void save(Configuration conf, List<OutputSpec> specs) {
    assert conf != null;
    assert specs != null;
    for (OutputSpec spec : specs) {
        if (spec.resolved) {
            throw new IllegalStateException();
        }//from w  ww. ja  v a2  s  . c  om
    }
    ByteArrayOutputStream sink = new ByteArrayOutputStream();
    try (DataOutputStream output = new DataOutputStream(new GZIPOutputStream(new Base64OutputStream(sink)))) {
        WritableUtils.writeVLong(output, SERIAL_VERSION);
        WritableUtils.writeVInt(output, specs.size());
        for (OutputSpec spec : specs) {
            WritableUtils.writeString(output, spec.basePath);
            WritableUtils.writeVInt(output, spec.deletePatterns.size());
            for (String pattern : spec.deletePatterns) {
                WritableUtils.writeString(output, pattern);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    conf.set(KEY, new String(sink.toByteArray(), ASCII));
}