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

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

Introduction

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

Prototype

public static void writeVLong(DataOutput stream, long i) throws IOException 

Source Link

Document

Serializes a long to a binary stream with zero-compressed encoding.

Usage

From source file:Counter.java

License:Apache License

/**
 * Write the binary representation of the counter
 *///from  w  ww .ja  v a2 s. c om
@Override
public synchronized void write(DataOutput out) throws IOException {
    Text.writeString(out, name);
    boolean distinctDisplayName = !name.equals(displayName);
    out.writeBoolean(distinctDisplayName);
    if (distinctDisplayName) {
        Text.writeString(out, displayName);
    }
    WritableUtils.writeVLong(out, value);
}

From source file:hadoop_serialize.java

License:Apache License

public static void main(String[] args) throws java.io.IOException {
    //System.err.println("Writing byte stream to stdout");
    DataOutputStream os = new DataOutputStream(System.out);

    //System.err.println("Writing a sequence of numbers");

    //System.err.println("WritableUtils.writeVInt: 42, 4242, 424242, 42424242, -42");
    WritableUtils.writeVInt(os, 42);//from  www  . j a va2s  .c  o  m
    WritableUtils.writeVInt(os, 4242);
    WritableUtils.writeVInt(os, 424242);
    WritableUtils.writeVInt(os, 42424242);
    WritableUtils.writeVInt(os, -42);

    //System.err.println("WritableUtils.writeVLong 42, 424242, 4242424242");
    WritableUtils.writeVLong(os, 42L);
    WritableUtils.writeVLong(os, 424242L);
    WritableUtils.writeVLong(os, 4242424242L);
    //
    //System.err.println("WritableUtils.writeString \"hello world\"");
    WritableUtils.writeString(os, "hello world");
    WritableUtils.writeString(os, "oggi \u00e8 gioved\u00ec");

    // This file contains: writeVInt of 42, 4242, 424242, 42424242, -42; writeVLong of 42, 424242, 4242424242; 2 writeString calls

    //System.err.println("Text.write \"I'm a Text object\"");
    Text t = new Text("\u00e0 Text object");
    t.write(os);

    os.close();
}

From source file:accumulo.ingest.AbstractAccumuloCsvIngest.java

License:Apache License

protected Value longToValue(long l) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);

    try {//from  w  w w  .  j ava 2  s . c  o  m
        WritableUtils.writeVLong(dos, l);
    } catch (IOException e) {
        log.error("IOException writing to a byte array...", e);
        throw new RuntimeException(e);
    }

    return new Value(baos.toByteArray());
}

From source file:co.cask.cdap.data.stream.StreamInputSplit.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    super.write(out);
    if (indexPath == null) {
        out.writeBoolean(false);//www.  j  a  v a 2  s . c om
    } else {
        out.writeBoolean(true);
        WritableUtils.writeString(out, indexPath.toString());
    }
    WritableUtils.writeVLong(out, startTime);
    WritableUtils.writeVLong(out, endTime);
}

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:co.cask.cdap.hive.stream.StreamInputSplit.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    super.write(out);
    WritableUtils.writeString(out, eventPath.toString());
    if (indexPath == null) {
        out.writeBoolean(false);//  w w w  .j  av a  2 s  . c  o  m
    } else {
        out.writeBoolean(true);
        WritableUtils.writeString(out, indexPath.toString());
    }
    WritableUtils.writeVLong(out, startTime);
    WritableUtils.writeVLong(out, endTime);
}

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

License:Apache License

static void writeFragment(DataOutput out, DirectInputFragment fragment) throws IOException {
    WritableUtils.writeString(out, fragment.getPath());
    WritableUtils.writeVLong(out, fragment.getOffset());
    WritableUtils.writeVLong(out, fragment.getSize());
    List<String> ownerNodeNames = fragment.getOwnerNodeNames();
    WritableUtils.writeStringArray(out, ownerNodeNames.toArray(new String[ownerNodeNames.size()]));
    Map<String, String> attributes = fragment.getAttributes();
    writeMap(out, attributes);//w w w  .  j  a  v  a  2  s.c o  m
}

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());
            }// w w  w . jav  a  2 s.  co  m
        }
    }
    return new String(sink.toByteArray(), ASCII);
}

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  w w  .  ja  v a2s  . 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));
}

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);
}