Package com.inesm.KeyManager.utils
Class ByteUtils
java.lang.Object
com.inesm.KeyManager.utils.ByteUtils
Provides byte conversion methods.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]base642bytes(String msg) Converts a Base64 encoded string into a byte array.static Stringbytes2base64(byte[] bytes) Converts a byte array into a Base64 encoded string.static intbytes2int(byte[] i) Converts a byte array into an integer.static longbytes2long(byte[] bytes) Converts a byte array to a long.static Objectbytes2object(byte[] msgBytes) Converts a byte array into an object.static Stringbytes2string(byte[] bytes) Converts a byte array into a string.static byte[]int2bytes(int i) Converts an integer into a byte arraystatic byte[]long2bytes(long x) Converts a long to a byte array.static byte[]object2bytes(Object obj) Converts an object into a byte array.static byte[]string2bytes(String str) Converts a string into a byte array.
-
Field Details
-
ENCODING
Encoding used for string conversion
-
-
Constructor Details
-
ByteUtils
public ByteUtils()
-
-
Method Details
-
long2bytes
public static byte[] long2bytes(long x) Converts a long to a byte array.- Parameters:
x- the long value- Returns:
- the byte array representation of the long value received
-
bytes2long
public static long bytes2long(byte[] bytes) Converts a byte array to a long.- Parameters:
bytes- the byte array- Returns:
- the first long value contained in the byte array
-
object2bytes
Converts an object into a byte array.- Parameters:
obj- the object to be converted- Returns:
- the byte array representing the object
- Throws:
IOException- if an I/O occurs during the process
-
bytes2object
Converts a byte array into an object.- Parameters:
msgBytes- the byte array containing the object information- Returns:
- the object represented by the byte array
- Throws:
ClassNotFoundException- if no definition for the class can be foundIOException- if an I/O error occurs during the process
-
string2bytes
Converts a string into a byte array. Uses string encoding defined inENCODING.- Parameters:
str- the string- Returns:
- the byte array representing the string value
-
bytes2string
Converts a byte array into a string. Uses string encoding defined inENCODING- Parameters:
bytes- the byte array- Returns:
- the string with the value represented by the byte array
-
int2bytes
public static byte[] int2bytes(int i) Converts an integer into a byte array- Parameters:
i- the integer- Returns:
- the byte array representing the integer value
-
bytes2int
public static int bytes2int(byte[] i) Converts a byte array into an integer.- Parameters:
i- the byte array- Returns:
- the first integer contained within the byte array
-
bytes2base64
Converts a byte array into a Base64 encoded string.- Parameters:
bytes- the byte array- Returns:
- the string containing the value represented by the byte array
-
base642bytes
Converts a Base64 encoded string into a byte array.- Parameters:
msg- the Base64 encoded string- Returns:
- the byte array containing the value represented by the string
-