Class BytesUtil

java.lang.Object
org.apache.hadoop.mapred.nativetask.util.BytesUtil

@Private public class BytesUtil extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    toBytes(boolean b)
    Convert a boolean to a byte array.
    static byte[]
    toBytes(double d)
    Serialize a double as the IEEE 754 double format output.
    static byte[]
    toBytes(float f)
     
    static double
    toDouble(byte[] bytes)
     
    static double
    toDouble(byte[] bytes, int offset)
     
    static float
    toFloat(byte[] bytes)
    Presumes float encoded as IEEE 754 floating-point "single format"
    static float
    toFloat(byte[] bytes, int offset)
    Presumes float encoded as IEEE 754 floating-point "single format"
    static int
    toInt(byte[] bytes, int offset)
    Convert a big-endian integer from a byte array to a primitive value.
    static long
    toLong(byte[] bytes, int offset)
    Converts a big-endian byte array to a long value.
    static String
    toStringBinary(byte[] b)
    Write a printable representation of a byte array.
    static String
    toStringBinary(byte[] b, int off, int len)
    Write a printable representation of a byte array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • BytesUtil

      public BytesUtil()
  • Method Details

    • toLong

      public static long toLong(byte[] bytes, int offset)
      Converts a big-endian byte array to a long value.
      Parameters:
      bytes - array of bytes
      offset - offset into array
    • toInt

      public static int toInt(byte[] bytes, int offset)
      Convert a big-endian integer from a byte array to a primitive value.
      Parameters:
      bytes - the array to parse from
      offset - the offset in the array
    • toFloat

      public static float toFloat(byte[] bytes)
      Presumes float encoded as IEEE 754 floating-point "single format"
      Parameters:
      bytes - byte array
      Returns:
      Float made from passed byte array.
    • toFloat

      public static float toFloat(byte[] bytes, int offset)
      Presumes float encoded as IEEE 754 floating-point "single format"
      Parameters:
      bytes - array to convert
      offset - offset into array
      Returns:
      Float made from passed byte array.
    • toDouble

      public static double toDouble(byte[] bytes)
      Parameters:
      bytes - byte array
      Returns:
      Return double made from passed bytes.
    • toDouble

      public static double toDouble(byte[] bytes, int offset)
      Parameters:
      bytes - byte array
      offset - offset where double is
      Returns:
      Return double made from passed bytes.
    • toStringBinary

      public static String toStringBinary(byte[] b)
      Write a printable representation of a byte array.
      Parameters:
      b - byte array
      Returns:
      the printable presentation
      See Also:
    • toStringBinary

      public static String toStringBinary(byte[] b, int off, int len)
      Write a printable representation of a byte array. Non-printable characters are hex escaped in the format \\x%02X, eg: \x00 \x05 etc
      Parameters:
      b - array to write out
      off - offset to start at
      len - length to write
      Returns:
      string output
    • toBytes

      public static byte[] toBytes(boolean b)
      Convert a boolean to a byte array. True becomes -1 and false becomes 0.
      Parameters:
      b - value
      Returns:
      b encoded in a byte array.
    • toBytes

      public static byte[] toBytes(float f)
      Parameters:
      f - float value
      Returns:
      the float represented as byte []
    • toBytes

      public static byte[] toBytes(double d)
      Serialize a double as the IEEE 754 double format output. The resultant array will be 8 bytes long.
      Parameters:
      d - value
      Returns:
      the double represented as byte []