org.dicom4j.core.utils
Class ByteArray

java.lang.Object
  extended by org.dicom4j.core.utils.ByteArray

public class ByteArray
extends Object

Various static methods helpful for manipulating arrays of bytes and extracting values from them.

Author:
dclunie

Method Summary
static int bigEndianToUnsignedInt(byte[] b)
           Extract an unsigned big endian integer from an entire byte array.
static int bigEndianToUnsignedInt(byte[] b, int offset, int length)
           Extract an unsigned big endian integer from a byte array.
static byte[] concatenate(byte[] src1, byte[] src2)
           Concatenate the entire contents of two byte arrays into a new byte array.
static byte[] concatenate(byte[] src1, int offset1, int length1, byte[] src2, int offset2, int length2)
           Concatenate portions of two byte arrays into a new byte array.
static byte[] extractBytes(byte[] src, int offset, int length)
           Extract a portion of a byte array into a new byte array.
static void main(String[] arg)
           Testing.
static void swapEndianness(byte[] src, int byteCount, int wordLength)
           Swap the byte order (endianness) of fixed length words within a byte array.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bigEndianToUnsignedInt

public static final int bigEndianToUnsignedInt(byte[] b)

Extract an unsigned big endian integer from an entire byte array.

Parameters:
b - the byte array which is the big endian encoded integer
Returns:
the unsigned integer value

bigEndianToUnsignedInt

public static final int bigEndianToUnsignedInt(byte[] b,
                                               int offset,
                                               int length)

Extract an unsigned big endian integer from a byte array.

Parameters:
b - the byte array containing the big endian encoded integer
offset - the offset of the start of the integer in the byte array
length - the number of bytes that the integer occupies in the byte array
Returns:
the unsigned integer value

concatenate

public static final byte[] concatenate(byte[] src1,
                                       byte[] src2)

Concatenate the entire contents of two byte arrays into a new byte array.

Parameters:
src1 - the first byte array
src2 - the second byte array
Returns:
a new byte array containing the bytes extracted from the first array followed by the bytes extracted from the second array

concatenate

public static final byte[] concatenate(byte[] src1,
                                       int offset1,
                                       int length1,
                                       byte[] src2,
                                       int offset2,
                                       int length2)

Concatenate portions of two byte arrays into a new byte array.

Parameters:
src1 - the first byte array
offset1 - the offset of the bytes to be extracted from the first byte array
length1 - the number of bytes to be extracted from the first byte array
src2 - the second byte array
offset2 - the offset of the bytes to be extracted from the second byte array
length2 - the number of bytes to be extracted from the second byte array
Returns:
a new byte array containing the bytes extracted from the first array followed by the bytes extracted from the second array

extractBytes

public static final byte[] extractBytes(byte[] src,
                                        int offset,
                                        int length)

Extract a portion of a byte array into a new byte array.

Parameters:
src - the source byte array
offset - the offset of the bytes to be extracted
length - the number of bytes to be extracted
Returns:
a new byte array containing the extracted bytes

main

public static void main(String[] arg)

Testing.

Parameters:
arg - ignored

swapEndianness

public static final void swapEndianness(byte[] src,
                                        int byteCount,
                                        int wordLength)

Swap the byte order (endianness) of fixed length words within a byte array.

Parameters:
src - the byte array (swapped in place)
byteCount - the number of bytes in the array to swap
wordLength - the length in bytes of each word


Copyright © 2009 dicom4j. All Rights Reserved.