Package org.owasp.esapi.util
Class ByteConversionUtil
- java.lang.Object
-
- org.owasp.esapi.util.ByteConversionUtil
-
public class ByteConversionUtil extends java.lang.Object
Conversion to/from byte arrays to/from short, int, long. The assumption is that they byte arrays are in network byte order (i.e., big-endian ordered).- Author:
- kevin.w.wall@gmail.com
- See Also:
CipherTextSerializer
-
-
Constructor Summary
Constructors Constructor Description ByteConversionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
fromInt(int input)
Returns a byte array containing 4 network byte-ordered bytes representing the givenint
.static byte[]
fromLong(long input)
Returns a byte array containing 8 network byte-ordered bytes representing the givenlong
.static byte[]
fromShort(short input)
Returns a byte array containing 2 network byte ordered bytes representing the givenshort
.static int
toInt(byte[] input)
Converts a given byte array to anint
.static long
toLong(byte[] input)
Converts a given byte array to along
.static short
toShort(byte[] input)
Converts a given byte array to anshort
.
-
-
-
Method Detail
-
fromShort
public static byte[] fromShort(short input)
Returns a byte array containing 2 network byte ordered bytes representing the givenshort
.- Parameters:
input
- Anshort
to convert to a byte array.- Returns:
- A byte array representation of an
short
in network byte order (i.e., big-endian order).
-
fromInt
public static byte[] fromInt(int input)
Returns a byte array containing 4 network byte-ordered bytes representing the givenint
.- Parameters:
input
- Anint
to convert to a byte array.- Returns:
- A byte array representation of an
int
in network byte order (i.e., big-endian order).
-
fromLong
public static byte[] fromLong(long input)
Returns a byte array containing 8 network byte-ordered bytes representing the givenlong
.- Parameters:
input
- Thelong
to convert to abyte
array.- Returns:
- A byte array representation of a
long
.
-
toShort
public static short toShort(byte[] input)
Converts a given byte array to anshort
. Bytes are expected in network byte order.- Parameters:
input
- A network byte-ordered representation of anshort
, so exactly 2 bytes are expected.- Returns:
- The
short
value represented by the input array.
-
toInt
public static int toInt(byte[] input)
Converts a given byte array to anint
. Bytes are expected in network byte order.- Parameters:
input
- A network byte-ordered representation of anint
. Must be exactly 4 bytes.- Returns:
- The
int
value represented by the input array.
-
toLong
public static long toLong(byte[] input)
Converts a given byte array to along
. Bytes are expected in network byte- Parameters:
input
- A network byte-ordered representation of along
. Must be exactly 8 bytes.- Returns:
- The
long
value represented by the input array
-
-