Example usage for org.apache.hadoop.util StringUtils byteToHexString

List of usage examples for org.apache.hadoop.util StringUtils byteToHexString

Introduction

In this page you can find the example usage for org.apache.hadoop.util StringUtils byteToHexString.

Prototype

public static String byteToHexString(byte b) 

Source Link

Document

Convert a byte to a hex string.

Usage

From source file:cascalog.TupleMemoryInputFormat.java

License:Open Source License

public static void setObject(JobConf conf, String key, Object o) {
    conf.set(key, StringUtils.byteToHexString(serialize(o)));
}

From source file:com.bigstep.datalake.JsonUtil.java

License:Apache License

/** Convert a MD5MD5CRC32FileChecksum to a Json string. */
public static String toJsonString(final MD5MD5CRC32FileChecksum checksum) {
    if (checksum == null) {
        return null;
    }//w  w w . j  av  a 2s  .  co m

    final Map<String, Object> m = new TreeMap<String, Object>();
    m.put("algorithm", checksum.getAlgorithmName());
    m.put("length", checksum.getLength());
    m.put("bytes", StringUtils.byteToHexString(checksum.getBytes()));
    return toJsonString(FileChecksum.class, m);
}

From source file:com.kylinolap.job.hadoop.cube.RangeKeyDistributionReducer.java

License:Apache License

@Override
protected void cleanup(Context context) throws IOException, InterruptedException {
    int nRegion = Math.round((float) gbPoints.size() / (float) cut);
    nRegion = Math.max(1, nRegion);
    nRegion = Math.min(MAX_REGION, nRegion);

    int gbPerRegion = gbPoints.size() / nRegion;
    gbPerRegion = Math.max(1, gbPerRegion);

    System.out.println(nRegion + " regions");
    System.out.println(gbPerRegion + " GB per region");

    for (int i = gbPerRegion; i < gbPoints.size(); i += gbPerRegion) {
        Text key = gbPoints.get(i);
        outputValue.set(i);// w w  w.j  ava 2 s  .  c  o  m
        System.out.println(StringUtils.byteToHexString(key.getBytes()) + "\t" + outputValue.get());
        context.write(key, outputValue);
    }
}

From source file:com.kylinolap.job.hadoop.hbase.CreateHTableJob.java

License:Apache License

@SuppressWarnings("deprecation")
public byte[][] getSplits(Configuration conf, Path path) throws Exception {
    FileSystem fs = path.getFileSystem(conf);
    if (fs.exists(path) == false) {
        System.err.println("Path " + path + " not found, no region split, HTable will be one region");
        return null;
    }//from  w  w  w.  j a  v  a  2s .c om

    List<byte[]> rowkeyList = new ArrayList<byte[]>();
    SequenceFile.Reader reader = null;
    try {
        reader = new SequenceFile.Reader(fs, path, conf);
        Writable key = (Writable) ReflectionUtils.newInstance(reader.getKeyClass(), conf);
        Writable value = (Writable) ReflectionUtils.newInstance(reader.getValueClass(), conf);
        while (reader.next(key, value)) {
            rowkeyList.add(((Text) key).copyBytes());
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    } finally {
        IOUtils.closeStream(reader);
    }

    System.out.println((rowkeyList.size() + 1) + " regions");
    System.out.println(rowkeyList.size() + " splits");
    for (byte[] split : rowkeyList) {
        System.out.println(StringUtils.byteToHexString(split));
    }

    byte[][] retValue = rowkeyList.toArray(new byte[rowkeyList.size()][]);
    return retValue.length == 0 ? null : retValue;
}

From source file:com.vertica.hadoop.VerticaConfiguration.java

License:Apache License

/**
 * Sets a collection of lists. Each list is passed to an input split and used
 * as arguments to the input query.// w  ww .j  a v  a  2 s  .  co m
 * 
 * @param segment_params
 * @throws IOException
*/
public void setInputParams(Collection<List<Object>> segment_params) throws IOException {
    String[] values = new String[segment_params.size()];
    int i = 0;
    for (List<Object> params : segment_params) {
        DataOutputBuffer out = new DataOutputBuffer();
        out.writeInt(params.size());
        for (Object obj : params) {
            int type = VerticaRecord.getType(obj);
            out.writeInt(type);
            VerticaRecord.write(obj, type, out);
        }
        values[i++] = StringUtils.byteToHexString(out.getData());
    }
    conf.setStrings(QUERY_PARAMS_PROP, values);
}

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void test() throws IOException {
        // vv BytesWritableTest
        BytesWritable b = new BytesWritable(new byte[] { 3, 5 });
        byte[] bytes = serialize(b);
        assertThat(StringUtils.byteToHexString(bytes), is("000000020305"));
        // ^^ BytesWritableTest

        // vv BytesWritableTest-Capacity
        b.setCapacity(11);/*from  www.j a v  a2 s .  c om*/
        assertThat(b.getLength(), is(2));
        assertThat(b.getBytes().length, is(11));
        // ^^ BytesWritableTest-Capacity
    }

From source file:crunch.MaxTemperature.java

License:Apache License

private void checkWalkthrough(IntWritable writable) throws IOException {
        // vv IntWritableTest-SerializedLength
        byte[] bytes = serialize(writable);
        assertThat(bytes.length, is(4));
        // ^^ IntWritableTest-SerializedLength

        // vv IntWritableTest-SerializedBytes
        assertThat(StringUtils.byteToHexString(bytes), is("000000a3"));
        // ^^ IntWritableTest-SerializedBytes

        // vv IntWritableTest-Deserialization
        IntWritable newWritable = new IntWritable();
        deserialize(newWritable, bytes);
        assertThat(newWritable.get(), is(163));
        // ^^ IntWritableTest-Deserialization
    }/*from ww  w .j av a  2 s . c  o  m*/

From source file:crunch.MaxTemperature.java

License:Apache License

@Test
    public void test() throws IOException {
        // vv VIntWritableTest
        byte[] data = serialize(new VIntWritable(163));
        assertThat(StringUtils.byteToHexString(data), is("8fa3"));
        // ^^ VIntWritableTest
    }/*  w  w w.  j  a  va2s  .  c  om*/

From source file:crunch.MaxTemperature.java

License:Apache License

public static String serializeToString(Writable src) throws IOException {
        return StringUtils.byteToHexString(serialize(src));
    }

From source file:crunch.MaxTemperature.java

License:Apache License

public static String writeTo(Writable src, Writable dest) throws IOException {
        byte[] data = deserialize(dest, serialize(src));
        return StringUtils.byteToHexString(data);
    }//from  w  w  w  .jav  a 2 s .  c  o  m