Package org.atlanmod.commons.primitive
Class Bytes
- java.lang.Object
-
- org.atlanmod.commons.primitive.Bytes
-
@ParametersAreNonnullByDefault public final class Bytes extends Object
Static utility methods related tobytearrays.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<Byte>asList(byte... bytes)static byte[]toArray(List<Byte> list)static booleantoBoolean(byte[] bytes)Decodes abytearray to aboolean.static chartoChar(byte[] bytes)Decodes abytearray to achar.static doubletoDouble(byte[] bytes)Decodes abytearray to adouble.static floattoFloat(byte[] bytes)Decodes abytearray to afloat.static inttoInt(byte[] bytes)Decodes abytearray to anint.static longtoLong(byte[] bytes)Decodes abytearray to along.static shorttoShort(byte[] bytes)Decodes abytearray to ashort.static StringtoString(byte[] bytes)Decodes abytearray to aString.static StringtoStringBinary(byte[] bytes)Decodes abytearray to aStringthat contains each byte, in order, as a two-digit unsigned hexadecimal number in lower case.
-
-
-
Method Detail
-
toBoolean
public static boolean toBoolean(byte[] bytes)
Decodes abytearray to aboolean.- Parameters:
bytes- thebytearray to decode- Returns:
- a
boolean - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different from1
-
toShort
public static short toShort(byte[] bytes)
Decodes abytearray to ashort.- Parameters:
bytes- thebytearray to decode- Returns:
- a
short - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different fromShort.BYTES
-
toChar
public static char toChar(byte[] bytes)
Decodes abytearray to achar.- Parameters:
bytes- thebytearray to decode- Returns:
- a
char - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different fromCharacter.BYTES- See Also:
toShort(byte[])
-
toInt
public static int toInt(byte[] bytes)
Decodes abytearray to anint.- Parameters:
bytes- thebytearray to decode- Returns:
- an
int - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different fromInteger.BYTES
-
toLong
public static long toLong(byte[] bytes)
Decodes abytearray to along.- Parameters:
bytes- thebytearray to decode- Returns:
- a
long - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different fromLong.BYTES
-
toFloat
public static float toFloat(byte[] bytes)
Decodes abytearray to afloat.- Parameters:
bytes- thebytearray to decode- Returns:
- a
float - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different fromFloat.BYTES- See Also:
toInt(byte[]),Float.intBitsToFloat(int)
-
toDouble
public static double toDouble(byte[] bytes)
Decodes abytearray to adouble.- Parameters:
bytes- thebytearray to decode- Returns:
- a
double - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- if thebytes.lengthis different fromDouble.BYTES- See Also:
toLong(byte[]),Double.longBitsToDouble(long)
-
toString
@Nonnull public static String toString(byte[] bytes)
Decodes abytearray to aString.- Parameters:
bytes- thebytearray to decode- Returns:
- a
String - Throws:
NullPointerException- if thebytesisnullIllegalArgumentException- ifStandardCharsets.UTF_8is not a supported encoding
-
toStringBinary
@Nonnull public static String toStringBinary(byte[] bytes)
Decodes abytearray to aStringthat contains each byte, in order, as a two-digit unsigned hexadecimal number in lower case.- Parameters:
bytes- thebytearray to decode- Returns:
- a
String - Throws:
NullPointerException- if thebytesisnull- See Also:
Strings.toBytesBinary(String)
-
asList
@Nonnull public static List<Byte> asList(byte... bytes)
- Parameters:
bytes- thebytearray to convert- Returns:
- a
Listcontaining the same elements asbytes, in the same order, converted to wrapper objects.
-
-