Package org.owasp.esapi.util
Class ByteConversionUtil
- java.lang.Object
-
- org.owasp.esapi.util.ByteConversionUtil
-
public class ByteConversionUtil extends java.lang.ObjectConversion 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 inttoInt(byte[] input)Converts a given byte array to anint.static longtoLong(byte[] input)Converts a given byte array to along.static shorttoShort(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- Anshortto convert to a byte array.- Returns:
- A byte array representation of an
shortin 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- Anintto convert to a byte array.- Returns:
- A byte array representation of an
intin 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- Thelongto convert to abytearray.- 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
shortvalue 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
intvalue 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
longvalue represented by the input array
-
-