Example usage for org.apache.hadoop.hdfs DFSUtilClient bytes2String

List of usage examples for org.apache.hadoop.hdfs DFSUtilClient bytes2String

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSUtilClient bytes2String.

Prototype

public static String bytes2String(byte[] bytes) 

Source Link

Document

Converts a byte array to a string using UTF8 encoding.

Usage

From source file:TestDFSUtilClient.java

License:Apache License

@Test
public void testBytes2String() {
    final long numLoop = 100000000;
    final byte[] bytes = "testBytes2String".getBytes(StandardCharsets.UTF_8);
    String str = null;//from   ww  w  . j  ava2 s.  c om
    long start = Time.monotonicNow();
    for (int i = 0; i < numLoop; i++) {
        str = DFSUtilClient.bytes2String(bytes);
    }
    long end = Time.monotonicNow();
    System.out.println(str);
    System.out.println("Elapsed time: " + (end - start));

    start = Time.monotonicNow();
    for (int i = 0; i < numLoop; i++) {
        str = new String(bytes, StandardCharsets.UTF_8);
    }
    end = Time.monotonicNow();
    System.out.println(str);
    System.out.println("Elapsed time: " + (end - start));

    start = Time.monotonicNow();
    for (int i = 0; i < numLoop; i++) {
        str = DFSUtilClient.bytes2String(bytes);
    }
    end = Time.monotonicNow();
    System.out.println(str);
    System.out.println("Elapsed time: " + (end - start));

    start = Time.monotonicNow();
    for (int i = 0; i < numLoop; i++) {
        str = new String(bytes, StandardCharsets.UTF_8);
    }
    end = Time.monotonicNow();
    System.out.println(str);
    System.out.println("Elapsed time: " + (end - start));
}