org.mbari.siam.utils
Class ByteUtility

java.lang.Object
  extended by org.mbari.siam.utils.ByteUtility

public final class ByteUtility
extends java.lang.Object

Utility Methods for byte arrays/strings


Constructor Summary
ByteUtility()
           
 
Method Summary
static boolean byteArrayEquals(byte[] firstArray, byte[] secondArray)
          Compare two byte arrays assumed to be the same length (or the secondArray longer firstArray) returns true if all characters match, false otherwise
static boolean byteArrayEquals(byte[] firstArray, byte[] secondArray, int len)
          Compare first len characters of two byte arrays returns true if all characters match, false otherwise
static int byteArrayEquals(byte[] firstArray, int firstOffset, byte[] secondArray, int secondOffset, int len)
          Compare two byte arrays returns 0 if all characters match, -1 if first mismatch < ,1 if first mismatch >
static java.lang.String bytesToHexString(byte[] b)
          return a hex ASCII String representation of the bytes in the byte array
static int bytesToInt(byte[] bytes)
          Convert a byte[] to an int assumming the bytes are in network byte order
static int bytesToInt(byte[] bytes, int offset)
          Convert a byte[] to an int assumming the bytes are in network byte order
static long bytesToLong(byte[] bytes)
          Convert a byte[] to a long assumming the bytes are in network byte order
static long bytesToLong(byte[] bytes, int offset)
          Convert a byte[] to a long assumming the bytes are in network byte order
static boolean checkByteArrayLen(byte[] buf, int len)
           
static boolean checkByteArrayOffset(byte[] buf, int offset)
           
static boolean checkByteArrayRange(byte[] buf, int len, int offset)
           
static byte[] concatByteArrays(byte[] firstBuf, byte[] secondBuf)
          Append 'buf' to 'target' Starts at index 0 Results in buffer size buf.length+target.length
static byte[] concatByteArrays(byte[] firstBuf, int firstLen, byte[] secondBuf, int secondLen)
          Append 'buf' to 'target' Starts at index 0 Results in buffer size bufLen+ targetLength
static byte[] concatByteArrays(byte[] firstBuf, int firstOffset, int firstLen, byte[] secondBuf, int secondOffset, int secondLen)
          Append 'buf' to 'target' Starts at index iBuf of buf, iTarget of target Results in buffer size bufLen+ targetLength
static void fillByteArray(byte[] array, char fillChar)
          Fill byte array with a character
static void fillByteSubArray(byte[] array, int fromIndex, int toIndex, char fillChar)
          Fill part of byte array with a character
static byte[] getByteSubArray(byte[] b, int offset, int len)
          Returns byte array containing the bytes from b[offset] to b[offset+len]
static byte[] intToBytes(int value)
          Convert an int to a byte[] in network byte order
static byte[] longToBytes(long value)
          Convert a long to a byte[] in network byte order
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteUtility

public ByteUtility()
Method Detail

checkByteArrayLen

public static boolean checkByteArrayLen(byte[] buf,
                                        int len)

checkByteArrayOffset

public static boolean checkByteArrayOffset(byte[] buf,
                                           int offset)

checkByteArrayRange

public static boolean checkByteArrayRange(byte[] buf,
                                          int len,
                                          int offset)

byteArrayEquals

public static boolean byteArrayEquals(byte[] firstArray,
                                      byte[] secondArray)
                               throws java.lang.ArrayIndexOutOfBoundsException
Compare two byte arrays assumed to be the same length (or the secondArray longer firstArray) returns true if all characters match, false otherwise

Throws:
java.lang.ArrayIndexOutOfBoundsException

byteArrayEquals

public static boolean byteArrayEquals(byte[] firstArray,
                                      byte[] secondArray,
                                      int len)
                               throws java.lang.ArrayIndexOutOfBoundsException
Compare first len characters of two byte arrays returns true if all characters match, false otherwise

Throws:
java.lang.ArrayIndexOutOfBoundsException

byteArrayEquals

public static int byteArrayEquals(byte[] firstArray,
                                  int firstOffset,
                                  byte[] secondArray,
                                  int secondOffset,
                                  int len)
                           throws java.lang.ArrayIndexOutOfBoundsException
Compare two byte arrays returns 0 if all characters match, -1 if first mismatch < ,1 if first mismatch >

Throws:
java.lang.ArrayIndexOutOfBoundsException

fillByteArray

public static void fillByteArray(byte[] array,
                                 char fillChar)
Fill byte array with a character


fillByteSubArray

public static void fillByteSubArray(byte[] array,
                                    int fromIndex,
                                    int toIndex,
                                    char fillChar)
Fill part of byte array with a character


getByteSubArray

public static byte[] getByteSubArray(byte[] b,
                                     int offset,
                                     int len)
                              throws java.lang.ArrayIndexOutOfBoundsException
Returns byte array containing the bytes from b[offset] to b[offset+len]

Throws:
java.lang.ArrayIndexOutOfBoundsException

concatByteArrays

public static byte[] concatByteArrays(byte[] firstBuf,
                                      byte[] secondBuf)
                               throws java.lang.ArrayIndexOutOfBoundsException
Append 'buf' to 'target' Starts at index 0 Results in buffer size buf.length+target.length

Throws:
java.lang.ArrayIndexOutOfBoundsException

concatByteArrays

public static byte[] concatByteArrays(byte[] firstBuf,
                                      int firstLen,
                                      byte[] secondBuf,
                                      int secondLen)
                               throws java.lang.ArrayIndexOutOfBoundsException
Append 'buf' to 'target' Starts at index 0 Results in buffer size bufLen+ targetLength

Throws:
java.lang.ArrayIndexOutOfBoundsException

concatByteArrays

public static byte[] concatByteArrays(byte[] firstBuf,
                                      int firstOffset,
                                      int firstLen,
                                      byte[] secondBuf,
                                      int secondOffset,
                                      int secondLen)
                               throws java.lang.ArrayIndexOutOfBoundsException
Append 'buf' to 'target' Starts at index iBuf of buf, iTarget of target Results in buffer size bufLen+ targetLength

Throws:
java.lang.ArrayIndexOutOfBoundsException

intToBytes

public static byte[] intToBytes(int value)
Convert an int to a byte[] in network byte order


longToBytes

public static byte[] longToBytes(long value)
Convert a long to a byte[] in network byte order


bytesToInt

public static int bytesToInt(byte[] bytes)
                      throws java.lang.ArrayIndexOutOfBoundsException
Convert a byte[] to an int assumming the bytes are in network byte order

Throws:
java.lang.ArrayIndexOutOfBoundsException

bytesToLong

public static long bytesToLong(byte[] bytes)
                        throws java.lang.ArrayIndexOutOfBoundsException
Convert a byte[] to a long assumming the bytes are in network byte order

Throws:
java.lang.ArrayIndexOutOfBoundsException

bytesToInt

public static int bytesToInt(byte[] bytes,
                             int offset)
                      throws java.lang.ArrayIndexOutOfBoundsException
Convert a byte[] to an int assumming the bytes are in network byte order

Throws:
java.lang.ArrayIndexOutOfBoundsException

bytesToLong

public static long bytesToLong(byte[] bytes,
                               int offset)
                        throws java.lang.ArrayIndexOutOfBoundsException
Convert a byte[] to a long assumming the bytes are in network byte order

Throws:
java.lang.ArrayIndexOutOfBoundsException

bytesToHexString

public static java.lang.String bytesToHexString(byte[] b)
return a hex ASCII String representation of the bytes in the byte array



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.