Package dev.oak3.sbs4j.util
Class ByteUtils
- java.lang.Object
-
- dev.oak3.sbs4j.util.ByteUtils
-
public final class ByteUtils extends java.lang.Object
Utilities class for Byte related operations- Since:
- 0.1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ByteUtils.HexCase
Hex string code case selector
-
Constructor Summary
Constructors Constructor Description ByteUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
encodeHexString(byte[] byteArray)
Encodes a byte array to an hex string in lower case as defaultstatic java.lang.String
encodeHexString(byte[] byteArray, ByteUtils.HexCase hexCase)
Encodes a byte array to an hex stringstatic byte[]
parseHexString(java.lang.String hexString)
Parses a hex string to byte arraystatic void
reverse(byte[] bytes)
Reverses a byte array, used to change endianstatic void
reverse(byte[] bytes, int from, int to)
Reverses a byte array, used to change endian
-
-
-
Method Detail
-
reverse
public static void reverse(byte[] bytes)
Reverses a byte array, used to change endian- Parameters:
bytes
- array of bytes to reverse
-
reverse
public static void reverse(byte[] bytes, int from, int to)
Reverses a byte array, used to change endian- Parameters:
bytes
- array of bytes to reversefrom
- first byte position to swapto
- last byte position to swap
-
parseHexString
public static byte[] parseHexString(java.lang.String hexString) throws java.lang.IllegalArgumentException
Parses a hex string to byte array- Parameters:
hexString
- the hex string to parse- Returns:
- the encoded byte array
- Throws:
java.lang.IllegalArgumentException
- thrown if hexString is invalid
-
encodeHexString
public static java.lang.String encodeHexString(byte[] byteArray)
Encodes a byte array to an hex string in lower case as default- Parameters:
byteArray
- the byte array to encode- Returns:
- the encoded hex string
-
encodeHexString
public static java.lang.String encodeHexString(byte[] byteArray, ByteUtils.HexCase hexCase)
Encodes a byte array to an hex string- Parameters:
byteArray
- the byte array to encodehexCase
- upper or lower hex code case to use- Returns:
- the encoded hex string
-
-