org.yajul.util
Class Bytes

java.lang.Object
  extended by org.yajul.util.Bytes

public class Bytes
extends java.lang.Object

Yet another class that turns Java primatives into arrays of bytes, and back. User: josh Date: Jan 11, 2004 Time: 10:18:58 PM


Field Summary
static byte[] HEX_BYTES_LOWER
          Lowercase hex characters as bytes.
static byte[] HEX_BYTES_UPPER
          Uppercase hex characters as bytes.
static char[] HEX_CHARS_LOWER
          Lowercase hex characters.
static char[] HEX_CHARS_UPPER
          Uppercase hex characters.
static java.lang.String HEX_LOWER
           
static java.lang.String HEX_UPPER
           
static int MASK
          Lower nybble mask.
static int VALUE_LOWERCASE_A
           
static int VALUE_UPPERCASE_A
           
 
Constructor Summary
Bytes()
           
 
Method Summary
static void hexBytes(byte[] hexBytes, byte[] inBytes, byte[] out, int length)
          Converts the byte into a two element array of hex characters.
static void hexBytes(byte[] hexBytes, int inByte, byte[] out)
          Converts the byte into a two element array of hex characters.
static byte[] parseHex(java.lang.String hexString)
          Parses a hex string into an array of bytes.
static byte[] toBytes(int n, byte[] b)
          Builds a 4-byte array from an int, MSB first.
static byte[] toBytes(long n, byte[] b)
          Builds a 8-byte array from an int, MSB first.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALUE_UPPERCASE_A

public static final int VALUE_UPPERCASE_A
See Also:
Constant Field Values

VALUE_LOWERCASE_A

public static final int VALUE_LOWERCASE_A
See Also:
Constant Field Values

HEX_LOWER

public static final java.lang.String HEX_LOWER
See Also:
Constant Field Values

HEX_UPPER

public static final java.lang.String HEX_UPPER
See Also:
Constant Field Values

HEX_CHARS_LOWER

public static final char[] HEX_CHARS_LOWER
Lowercase hex characters.


HEX_CHARS_UPPER

public static final char[] HEX_CHARS_UPPER
Uppercase hex characters.


HEX_BYTES_LOWER

public static final byte[] HEX_BYTES_LOWER
Lowercase hex characters as bytes.


HEX_BYTES_UPPER

public static final byte[] HEX_BYTES_UPPER
Uppercase hex characters as bytes.


MASK

public static final int MASK
Lower nybble mask.

See Also:
Constant Field Values
Constructor Detail

Bytes

public Bytes()
Method Detail

toBytes

public static byte[] toBytes(int n,
                             byte[] b)
Builds a 4-byte array from an int, MSB first.

Parameters:
n - The number to convert.
b - The output array.
Returns:
The output array (b).

toBytes

public static byte[] toBytes(long n,
                             byte[] b)
Builds a 8-byte array from an int, MSB first.

Parameters:
n - The number to convert.
b - The output array.
Returns:
The output array (b).

hexBytes

public static void hexBytes(byte[] hexBytes,
                            byte[] inBytes,
                            byte[] out,
                            int length)
Converts the byte into a two element array of hex characters.

Parameters:
hexBytes - The hex encoding set to use (e.g. HEX_BYTES_LOWER / HEX_BYTES_UPPER).
inBytes - The input byte array.
length - The number of bytes to convert to hex.
out - The output array of hex bytes. The length of this array must be >= 2 * length.

hexBytes

public static void hexBytes(byte[] hexBytes,
                            int inByte,
                            byte[] out)
Converts the byte into a two element array of hex characters.

Parameters:
hexBytes - The hex character set to use (e.g. HEX_BYTES_LOWER / HEX_BYTES_UPPER).
inByte - The input byte.
out - The output array of characters. Length must be >= 2.

parseHex

public static byte[] parseHex(java.lang.String hexString)
Parses a hex string into an array of bytes.

Parameters:
hexString - the hex string
Returns:
an array of bytes, parsed from the hex string


Copyright © 2008. All Rights Reserved.