Class BytesUtil
java.lang.Object
org.apache.hadoop.mapred.nativetask.util.BytesUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 doubletoDouble(byte[] bytes) static doubletoDouble(byte[] bytes, int offset) static floattoFloat(byte[] bytes) Presumes float encoded as IEEE 754 floating-point "single format"static floattoFloat(byte[] bytes, int offset) Presumes float encoded as IEEE 754 floating-point "single format"static inttoInt(byte[] bytes, int offset) Convert a big-endian integer from a byte array to a primitive value.static longtoLong(byte[] bytes, int offset) Converts a big-endian byte array to a long value.static StringtoStringBinary(byte[] b) Write a printable representation of a byte array.static StringtoStringBinary(byte[] b, int off, int len) Write a printable representation of a byte array.
-
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 bytesoffset- 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 fromoffset- 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 convertoffset- 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 arrayoffset- offset where double is- Returns:
- Return double made from passed bytes.
-
toStringBinary
Write a printable representation of a byte array.- Parameters:
b- byte array- Returns:
- the printable presentation
- See Also:
-
toStringBinary
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 outoff- offset to start atlen- 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:
bencoded 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 []
-