javax.baja.nre.util
Class ByteArrayUtil

java.lang.Object
  extended byjavax.baja.nre.util.ByteArrayUtil

public class ByteArrayUtil
extends java.lang.Object

Byte array utilities.


Constructor Summary
ByteArrayUtil()
           
 
Method Summary
static byte[] clone(byte[] a)
          Create a copy of the specified byte array.
static void copy(byte[] source, byte[] target)
          Copy the contents of the source byte array into the target byte array.
static boolean equals(byte[] a1, byte[] a2)
          Return true if the two specified byte arrays have equal lengths and contents.
static void hexDump(byte[] b)
          Dump a byte array to standard out.
static void hexDump(byte[] b, int offset, int length)
          Dump a slice of a byte array to standard out.
static void hexDump(java.io.PrintWriter out, byte[] b, int offset, int length)
          Dump a byte array to the given print writer.
static void hexDump(java.lang.String linePrefix, byte[] b)
           
static void hexDump(java.lang.String linePrefix, byte[] b, int offset, int length)
           
static void hexDump(java.lang.String linePrefix, java.io.PrintWriter out, byte[] b, int offset, int length)
           
static byte[] hexStringToBytes(java.lang.String hex)
          Convert a hex string into the equivalent byte array.
static void memset(byte[] buf, byte value)
           
static int readInt(byte[] buf, int offset)
          Read a 4 byte integer from the byte array at the given offset using network byte ordering.
static long readLong(byte[] buf, int offset)
          Read a 8 byte long from the byte array at the given offset using network byte ordering.
static short readShort(byte[] buf, int offset)
          Read an signed short from the byte array at the given offset using network byte ordering.
static int readUnsignedByte(byte[] buf, int offset)
          Read an unsigned byte from the byte array at the given offset.
static int readUnsignedShort(byte[] buf, int offset)
          Read an unsigned short from the byte array at the given offset using network byte ordering.
static java.lang.String toHexString(byte[] b)
          Convenience for toHexString(b, 0, b.length).
static java.lang.String toHexString(byte[] b, int off, int len)
          Return the byte array as a hex string.
static java.lang.String toHexString(byte[] b, int off, int len, java.lang.String delimiter)
           
static java.lang.String toHexString(byte[] b, java.lang.String delimiter)
           
static int writeByte(byte[] buf, int offset, int value)
          Write the specified byte into the byte array at the give offset.
static int writeInt(byte[] buf, int offset, int value)
          Write the 4 bytes at the specified offset with the given integer value.
static int writeLong(byte[] buf, int offset, long value)
          Write the 8 bytes at the specified offset with the given long value.
static int writeShort(byte[] buf, int offset, int value)
          Write the 2 bytes at specified offset with the given short value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayUtil

public ByteArrayUtil()
Method Detail

clone

public static byte[] clone(byte[] a)
Create a copy of the specified byte array.


copy

public static void copy(byte[] source,
                        byte[] target)
Copy the contents of the source byte array into the target byte array.

Throws:
ArrayIndexOutOfBounds - if the target array is not as big or bigger than the source array.

equals

public static boolean equals(byte[] a1,
                             byte[] a2)
Return true if the two specified byte arrays have equal lengths and contents.


memset

public static void memset(byte[] buf,
                          byte value)

readUnsignedByte

public static int readUnsignedByte(byte[] buf,
                                   int offset)
Read an unsigned byte from the byte array at the given offset.


readShort

public static short readShort(byte[] buf,
                              int offset)
Read an signed short from the byte array at the given offset using network byte ordering.


readUnsignedShort

public static int readUnsignedShort(byte[] buf,
                                    int offset)
Read an unsigned short from the byte array at the given offset using network byte ordering.


readInt

public static int readInt(byte[] buf,
                          int offset)
Read a 4 byte integer from the byte array at the given offset using network byte ordering.


readLong

public static long readLong(byte[] buf,
                            int offset)
Read a 8 byte long from the byte array at the given offset using network byte ordering.


writeByte

public static int writeByte(byte[] buf,
                            int offset,
                            int value)
Write the specified byte into the byte array at the give offset.

Returns:
offset + 1

writeShort

public static int writeShort(byte[] buf,
                             int offset,
                             int value)
Write the 2 bytes at specified offset with the given short value.

Returns:
offset + 2

writeInt

public static int writeInt(byte[] buf,
                           int offset,
                           int value)
Write the 4 bytes at the specified offset with the given integer value.

Returns:
offset + 4

writeLong

public static int writeLong(byte[] buf,
                            int offset,
                            long value)
Write the 8 bytes at the specified offset with the given long value.

Returns:
offset + 8

toHexString

public static java.lang.String toHexString(byte[] b)
Convenience for toHexString(b, 0, b.length).


toHexString

public static java.lang.String toHexString(byte[] b,
                                           java.lang.String delimiter)

toHexString

public static java.lang.String toHexString(byte[] b,
                                           int off,
                                           int len)
Return the byte array as a hex string.


toHexString

public static java.lang.String toHexString(byte[] b,
                                           int off,
                                           int len,
                                           java.lang.String delimiter)

hexStringToBytes

public static byte[] hexStringToBytes(java.lang.String hex)
Convert a hex string into the equivalent byte array.


hexDump

public static void hexDump(byte[] b)
Dump a byte array to standard out.


hexDump

public static void hexDump(java.lang.String linePrefix,
                           byte[] b)

hexDump

public static void hexDump(byte[] b,
                           int offset,
                           int length)
Dump a slice of a byte array to standard out.


hexDump

public static void hexDump(java.lang.String linePrefix,
                           byte[] b,
                           int offset,
                           int length)

hexDump

public static void hexDump(java.io.PrintWriter out,
                           byte[] b,
                           int offset,
                           int length)
Dump a byte array to the given print writer.


hexDump

public static void hexDump(java.lang.String linePrefix,
                           java.io.PrintWriter out,
                           byte[] b,
                           int offset,
                           int length)