com.buck.commons.algorithms
Class BinaryData

java.lang.Object
  extended by com.buck.commons.algorithms.BinaryData

public final class BinaryData
extends Object

Utilities to convert primitive data types to and from byte arrays.

Author:
Robert J. Buck

Field Summary
static int sizeOfByte
          The size of a byte.
static int sizeOfInt
          The size of an int.
static int sizeOfLong
          The size of a long.
static int sizeOfShort
          The size of a short.
 
Constructor Summary
BinaryData()
           
 
Method Summary
static byte loadByteAtOffset(byte[] array, int offset)
          Load a byte primitive type located at the indicated offset in the byte array.
static byte loadByteAtOffsetUnsafe(byte[] array, int offset)
          Load a short primitive type located at the indicated offset in the byte array.
static int loadIntAtOffset(byte[] array, int offset)
          Load a long primitive type located at the indicated offset in the byte array.
static int loadIntAtOffsetUnsafe(byte[] array, int offset)
          Load a long primitive type located at the indicated offset in the byte array.
static long loadLongAtOffset(byte[] array, int offset)
          Load a long primitive type located at the indicated offset in the byte array.
static long loadLongAtOffsetUnsafe(byte[] array, int offset)
          Load a long primitive type located at the indicated offset in the byte array.
static short loadShortAtOffset(byte[] array, int offset)
          Load a short primitive type located at the indicated offset in the byte array.
static short loadShortAtOffsetUnsafe(byte[] array, int offset)
          Load a short primitive type located at the indicated offset in the byte array.
static void storeByteAtOffset(byte[] array, int offset, byte value)
          Store a byte primitive type at the indicated offset in the byte array.
static void storeByteAtOffsetUnsafe(byte[] array, int offset, byte value)
          Store a byte primitive type at the indicated offset in the byte array.
static void storeIntAtOffset(byte[] array, int offset, int value)
          Store a int primitive type at the indicated offset in the byte array.
static void storeIntAtOffsetUnsafe(byte[] array, int offset, int value)
          Store a long primitive type at the indicated offset in the byte array.
static void storeLongAtOffset(byte[] array, int offset, long value)
          Store a long primitive type at the indicated offset in the byte array.
static void storeLongAtOffsetUnsafe(byte[] array, int offset, long value)
          Store a long primitive type at the indicated offset in the byte array.
static void storeShortAtOffset(byte[] array, int offset, short value)
          Store a short primitive type at the indicated offset in the byte array.
static void storeShortAtOffsetUnsafe(byte[] array, int offset, short value)
          Store a short primitive type at the indicated offset in the byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sizeOfByte

public static final int sizeOfByte
The size of a byte.


sizeOfShort

public static final int sizeOfShort
The size of a short.


sizeOfInt

public static final int sizeOfInt
The size of an int.


sizeOfLong

public static final int sizeOfLong
The size of a long.

Constructor Detail

BinaryData

public BinaryData()
Method Detail

storeByteAtOffset

public static void storeByteAtOffset(byte[] array,
                                     int offset,
                                     byte value)
                              throws IndexOutOfBoundsException
Store a byte primitive type at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to store the byte into
offset - the offset at which to store the byte
value - the byte data to store at array[offset]
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a byte.

storeByteAtOffsetUnsafe

public static void storeByteAtOffsetUnsafe(byte[] array,
                                           int offset,
                                           byte value)
Store a byte primitive type at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to store the byte into
offset - the offset at which to store the byte
value - the byte data to store at array[offset]

loadByteAtOffset

public static byte loadByteAtOffset(byte[] array,
                                    int offset)
                             throws IndexOutOfBoundsException
Load a byte primitive type located at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to load the byte from
offset - the offset from which to load the byte
Returns:
the byte data loaded from the array at offset
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a byte.

loadByteAtOffsetUnsafe

public static byte loadByteAtOffsetUnsafe(byte[] array,
                                          int offset)
Load a short primitive type located at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to load the byte from
offset - the offset from which to load the byte
Returns:
the byte data loaded from the array at offset

storeShortAtOffset

public static void storeShortAtOffset(byte[] array,
                                      int offset,
                                      short value)
                               throws IndexOutOfBoundsException
Store a short primitive type at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to store the short into
offset - the offset at which to store the short
value - the short data to store at array[offset]
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a short.

storeShortAtOffsetUnsafe

public static void storeShortAtOffsetUnsafe(byte[] array,
                                            int offset,
                                            short value)
Store a short primitive type at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to store the short into
offset - the offset at which to store the short
value - the short data to store at array[offset]

loadShortAtOffset

public static short loadShortAtOffset(byte[] array,
                                      int offset)
                               throws IndexOutOfBoundsException
Load a short primitive type located at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to load the short from
offset - the offset from which to load the short
Returns:
the short data loaded from the array at offset
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a short.

loadShortAtOffsetUnsafe

public static short loadShortAtOffsetUnsafe(byte[] array,
                                            int offset)
Load a short primitive type located at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to load the short from
offset - the offset from which to load the short
Returns:
the short data loaded from the array at offset

storeIntAtOffset

public static void storeIntAtOffset(byte[] array,
                                    int offset,
                                    int value)
                             throws IndexOutOfBoundsException
Store a int primitive type at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to store the long into
offset - the offset at which to store the long
value - the int data to store at array[offset]
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a long.

storeIntAtOffsetUnsafe

public static void storeIntAtOffsetUnsafe(byte[] array,
                                          int offset,
                                          int value)
Store a long primitive type at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to store the long into
offset - the offset at which to store the long
value - the long data to store at array[offset]

loadIntAtOffset

public static int loadIntAtOffset(byte[] array,
                                  int offset)
                           throws IndexOutOfBoundsException
Load a long primitive type located at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to load the long from
offset - the offset from which to load the long
Returns:
the long data loaded from the array at offset
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a long.

loadIntAtOffsetUnsafe

public static int loadIntAtOffsetUnsafe(byte[] array,
                                        int offset)
Load a long primitive type located at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to load the long from
offset - the offset from which to load the long
Returns:
the long data loaded from the array at offset

storeLongAtOffset

public static void storeLongAtOffset(byte[] array,
                                     int offset,
                                     long value)
                              throws IndexOutOfBoundsException
Store a long primitive type at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to store the long into
offset - the offset at which to store the long
value - the long data to store at array[offset]
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a long.

storeLongAtOffsetUnsafe

public static void storeLongAtOffsetUnsafe(byte[] array,
                                           int offset,
                                           long value)
Store a long primitive type at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to store the long into
offset - the offset at which to store the long
value - the long data to store at array[offset]

loadLongAtOffset

public static long loadLongAtOffset(byte[] array,
                                    int offset)
                             throws IndexOutOfBoundsException
Load a long primitive type located at the indicated offset in the byte array. Perform full range checks and throw an exception if the caller specifies an illegal offset.

Parameters:
array - the byte array to load the long from
offset - the offset from which to load the long
Returns:
the long data loaded from the array at offset
Throws:
IndexOutOfBoundsException - if the offset is less than zero or greater than the array length minus the sizeof a long.

loadLongAtOffsetUnsafe

public static long loadLongAtOffsetUnsafe(byte[] array,
                                          int offset)
Load a long primitive type located at the indicated offset in the byte array. This method does no range checks, and therefore is considered unsafe; callers must perform range checks themselves.

Parameters:
array - the byte array to load the long from
offset - the offset from which to load the long
Returns:
the long data loaded from the array at offset


Copyright © 2013. All Rights Reserved.