org.owasp.esapi.util
Class ByteConversionUtil

java.lang.Object
  extended by 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:
[email protected]
See Also:
CipherTextSerializer

Constructor Summary
ByteConversionUtil()
           
 
Method Summary
static byte[] fromInt(int input)
          Returns a byte array containing 4 network byte-ordered bytes representing the given int.
static byte[] fromLong(long input)
          Returns a byte array containing 8 network byte-ordered bytes representing the given long.
static byte[] fromShort(short input)
          Returns a byte array containing 2 network byte ordered bytes representing the given short.
static int toInt(byte[] input)
          Converts a given byte array to an int.
static long toLong(byte[] input)
          Converts a given byte array to a long.
static short toShort(byte[] input)
          Converts a given byte array to an short.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteConversionUtil

public ByteConversionUtil()
Method Detail

fromShort

public static byte[] fromShort(short input)
Returns a byte array containing 2 network byte ordered bytes representing the given short.

Parameters:
input - An short 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 given int.

Parameters:
input - An int 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 given long.

Parameters:
input - The long to convert to a byte array.
Returns:
A byte array representation of a long.

toShort

public static short toShort(byte[] input)
Converts a given byte array to an short. Bytes are expected in network byte order.

Parameters:
input - A network byte-ordered representation of an short.
Returns:
The short value represented by the input array.

toInt

public static int toInt(byte[] input)
Converts a given byte array to an int. Bytes are expected in network byte order.

Parameters:
input - A network byte-ordered representation of an int.
Returns:
The int value represented by the input array.

toLong

public static long toLong(byte[] input)
Converts a given byte array to a long. Bytes are expected in network byte

Parameters:
input - A network byte-ordered representation of a long.
Returns:
The long value represented by the input array


Copyright © 2011 The Open Web Application Security Project (OWASP). All Rights Reserved.