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:org.apache.accumulo.core.file.rfile.RelativeKey.java

License:Apache License

private static void writePrefix(DataOutput out, ByteSequence bs, int commonPrefixLength) throws IOException {
    WritableUtils.writeVInt(out, commonPrefixLength);
    WritableUtils.writeVInt(out, bs.length() - commonPrefixLength);
    out.write(bs.getBackingArray(), bs.offset() + commonPrefixLength, bs.length() - commonPrefixLength);
}

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

License:Apache License

public static byte[] longArrayToBytes(long[] la) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);

    WritableUtils.writeVInt(dos, la.length);
    for (int i = 0; i < la.length; i++) {
        WritableUtils.writeVLong(dos, la[i]);
    }//from   w  ww  . j a  v  a  2  s. c o m

    return baos.toByteArray();
}

From source file:org.apache.accumulo.core.summary.SummaryWriter.java

License:Apache License

public void writeConfig(SummarizerConfiguration conf, DataOutputStream dos) throws IOException {
    // save class (and its config) used to generate summaries
    dos.writeUTF(conf.getClassName());//from   w  ww  .  j av a 2  s.  com
    dos.writeUTF(conf.getPropertyId());
    WritableUtils.writeVInt(dos, conf.getOptions().size());
    for (Entry<String, String> entry : conf.getOptions().entrySet()) {
        dos.writeUTF(entry.getKey());
        dos.writeUTF(entry.getValue());
    }
}

From source file:org.apache.accumulo.core.summary.SummaryWriter.java

License:Apache License

@Override
public void close() throws IOException {

    DataOutputStream out = writer.createMetaStore(METASTORE_INDEX);
    out.writeLong(MAGIC);/*from  www.j a  v  a 2s .c o m*/
    out.write(VER);
    WritableUtils.writeVInt(out, summaryStores.length);

    // Could possibly inline small summaries in the future. Breaking summaries into multiple block is better for caching a subset of summaries. Also, keeping
    // the index small is good for the case where summaries that do not exist are requested. However multiple blocks cause more random I/O in the case when its
    // not yet in the cache.

    for (int i = 0; i < summaryStores.length; i++) {
        writeConfig(summaryStores[i].getSummarizerConfiguration(), out);
        // write if summary is inlined in index... support for possible future optimizations.
        out.writeBoolean(false);
        // write pointer to block that will contain summary data
        WritableUtils.writeVInt(out, i);
        // write offset of summary data within block. This is not currently used, but it supports storing multiple summaries in an external block in the
        // future without changing the code.
        WritableUtils.writeVInt(out, 0);
    }
    out.close();

    for (int i = 0; i < summaryStores.length; i++) {
        DataOutputStream summaryOut = writer.createMetaStore(METASTORE_PREFIX + "." + i);
        summaryStores[i].save(summaryOut);
        summaryOut.close();
    }

    writer.close();
}

From source file:org.apache.accumulo.core.util.UnsynchronizedBufferTest.java

License:Apache License

@Test
public void compareWithWritableUtils() throws Exception {
    byte[] hadoopBytes;
    byte[] accumuloBytes;
    int oneByteInt = 0x7f;
    int threeByteInt = 0x7fff;
    long sixByteLong = 0x7fffffffffL;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos)) {
        WritableUtils.writeVInt(dos, oneByteInt);
        WritableUtils.writeVInt(dos, threeByteInt);
        WritableUtils.writeVLong(dos, sixByteLong);
        dos.flush();/*from   w  ww .  j a va  2 s. c  o  m*/
        hadoopBytes = baos.toByteArray();
    }
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
            DataOutputStream dos = new DataOutputStream(baos)) {
        UnsynchronizedBuffer.writeVInt(dos, new byte[5], oneByteInt);
        UnsynchronizedBuffer.writeVInt(dos, new byte[5], threeByteInt);
        UnsynchronizedBuffer.writeVLong(dos, new byte[9], sixByteLong);
        dos.flush();
        accumuloBytes = baos.toByteArray();
    }
    assertTrue("The byte array written to by UnsynchronizedBuffer is not equal to WritableUtils",
            Arrays.equals(hadoopBytes, accumuloBytes));
}

From source file:org.apache.accumulo.server.security.delegation.AuthenticationKey.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    if (null == authKey) {
        WritableUtils.writeVInt(out, 0);
        return;/*from   ww  w  .j  a  v  a 2 s . c  o m*/
    }
    ThriftMessageUtil util = new ThriftMessageUtil();
    ByteBuffer serialized = util.serialize(authKey);
    WritableUtils.writeVInt(out, serialized.limit() - serialized.arrayOffset());
    ByteBufferUtil.write(out, serialized);
}

From source file:org.apache.blur.mapreduce.lib.v2.DocumentWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    int numberOfFields = _document.size();
    WritableUtils.writeVInt(out, numberOfFields);
    for (int i = 0; i < numberOfFields; i++) {
        IndexableField field = _document.get(i);
        write(out, field);//  www . j  a  v a  2  s .c om
    }
}

From source file:org.apache.blur.mapreduce.lib.v2.DocumentWritable.java

License:Apache License

private void writeString(DataOutput out, String value) throws IOException {
    byte[] bs = value.getBytes(UTF_8);
    WritableUtils.writeVInt(out, bs.length);
    out.write(bs);/*www.  jav a 2 s  .  co m*/
}

From source file:org.apache.crunch.types.writable.GenericArrayWritable.java

License:Apache License

public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, values.length);
    if (values.length > 0) {
        int nulls = 0;
        for (int i = 0; i < values.length; i++) {
            if (values[i] == null) {
                nulls++;//from w  w w  .ja va  2  s . c o m
            }
        }
        WritableUtils.writeVInt(out, nulls);
        if (values.length - nulls > 0) {
            if (valueClass == null) {
                throw new IllegalStateException("Value class not set by constructor or read");
            }
            Text.writeString(out, valueClass.getName());
            for (int i = 0; i < values.length; i++) {
                if (values[i] != null) {
                    values[i].write(out);
                }
            }
        }
    }
}

From source file:org.apache.crunch.types.writable.UnionWritable.java

License:Apache License

@Override
public void write(DataOutput out) throws IOException {
    WritableUtils.writeVInt(out, index);
    value.write(out);
}