org.apache.java.lang
Class Bytes

java.lang.Object
  |
  +--org.apache.java.lang.Bytes

public class Bytes
extends java.lang.Object

Static methods for managing byte arrays (all methods follow Big Endian order where most significant bits are in front).

Version:
$Revision: 1.7 $ $Date: 1999/04/26 00:33:55 $

Field Summary
private static char[] hexDigits
           
 
Constructor Summary
Bytes()
           
 
Method Summary
static byte[] append(byte[] a, byte[] b)
          Appends two bytes array into one.
static byte[] append(byte[] a, byte[] b, byte[] c)
          Appends three bytes array into one.
static boolean areEqual(byte[] a, byte[] b)
          Compares two byte arrays for equality.
static byte[] copy(byte[] b, int pos)
          Gets the end of the byte array given.
static byte[] copy(byte[] b, int pos, int length)
          Gets a sub-set of the byte array given.
static void merge(byte[] src, byte[] dest)
          Merges a bytes array into another.
static void merge(byte[] src, byte[] dest, int pos)
          Merges a bytes array into another starting from the given position.
static void merge(byte[] src, byte[] dest, int pos, int length)
          Merges a bytes array into another starting from the given position.
static void merge(byte[] src, byte[] dest, int srcpos, int destpos, int length)
          Merges a bytes array into another starting from the given positions.
static byte[] toBytes(int n)
          Returns a 4-byte array built from an int.
static byte[] toBytes(int n, byte[] b)
          Build a 4-byte array from an int.
static byte[] toBytes(long n)
          Returns a 8-byte array built from a long.
static byte[] toBytes(long n, byte[] b)
          Build a 8-byte array from a long.
static int toInt(byte[] b)
          Build an int from first 4 bytes of the array.
static long toLong(byte[] b)
          Build a long from first 8 bytes of the array.
static java.lang.String toString(byte[] b)
          Returns a string of hexadecimal digits from a byte array..
static java.lang.String toString(byte[] b, int offset, int length)
          Returns a string of hexadecimal digits from a byte array, starting at offset and continuing for length bytes.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

hexDigits

private static final char[] hexDigits
Constructor Detail

Bytes

public Bytes()
Method Detail

toInt

public static int toInt(byte[] b)
Build an int from first 4 bytes of the array.
Parameters:
b - the byte array to convert.

toLong

public static long toLong(byte[] b)
Build a long from first 8 bytes of the array.
Parameters:
b - the byte array to convert.

toBytes

public static byte[] toBytes(int n)
Returns a 4-byte array built from an int.
Parameters:
n - the number to convert.

toBytes

public static byte[] toBytes(int n,
                             byte[] b)
Build a 4-byte array from an int. No check is performed on the array length.
Parameters:
n - the number to convert.
b - the array to fill.

toBytes

public static byte[] toBytes(long n)
Returns a 8-byte array built from a long.
Parameters:
n - the number to convert.

toBytes

public static byte[] toBytes(long n,
                             byte[] b)
Build a 8-byte array from a long. No check is performed on the array length.
Parameters:
n - the number to convert.
b - the array to fill.

areEqual

public static boolean areEqual(byte[] a,
                               byte[] b)
Compares two byte arrays for equality.
Returns:
true if the arrays have identical contents

append

public static byte[] append(byte[] a,
                            byte[] b)
Appends two bytes array into one.

append

public static byte[] append(byte[] a,
                            byte[] b,
                            byte[] c)
Appends three bytes array into one.

copy

public static byte[] copy(byte[] b,
                          int pos)
Gets the end of the byte array given.
Parameters:
b - byte array
pos - the position from which to start
Returns:
a byte array consisting of the portion of b between pos and the end of b.

copy

public static byte[] copy(byte[] b,
                          int pos,
                          int length)
Gets a sub-set of the byte array given.
Parameters:
b - byte array
pos - the position from which to start
length - the number of bytes to copy from the original byte array to the new one.
Returns:
a byte array consisting of the portion of b starting at pos and continuing for length bytes, or until the end of b is reached, which ever occurs first.

merge

public static void merge(byte[] src,
                         byte[] dest,
                         int srcpos,
                         int destpos,
                         int length)
Merges a bytes array into another starting from the given positions.

merge

public static void merge(byte[] src,
                         byte[] dest,
                         int pos)
Merges a bytes array into another starting from the given position.

merge

public static void merge(byte[] src,
                         byte[] dest)
Merges a bytes array into another.

merge

public static void merge(byte[] src,
                         byte[] dest,
                         int pos,
                         int length)
Merges a bytes array into another starting from the given position.

toString

public static java.lang.String toString(byte[] b,
                                        int offset,
                                        int length)
Returns a string of hexadecimal digits from a byte array, starting at offset and continuing for length bytes.

toString

public static java.lang.String toString(byte[] b)
Returns a string of hexadecimal digits from a byte array..