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

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

Introduction

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

Prototype

public static byte[] string2Bytes(String str) 

Source Link

Document

Converts a string to a byte array using UTF8 encoding.

Usage

From source file:TestDFSUtilClient.java

License:Apache License

@Test
public void testString2Bytes() {
    final long numLoop = 100000000;
    final String str = "testString2Bytes";
    byte[] b = null;
    long start = Time.monotonicNow();
    for (int i = 0; i < numLoop; i++) {
        b = DFSUtilClient.string2Bytes(str);
    }/*from   ww  w.  j av a  2s  . c om*/
    long end = Time.monotonicNow();
    System.out.println(new String(b, StandardCharsets.UTF_8));
    System.out.println("Elapsed time: " + (end - start));

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

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

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