net.clackrouter.jpcap
Class ArrayHelper

java.lang.Object
  extended by net.clackrouter.jpcap.ArrayHelper

public class ArrayHelper
extends java.lang.Object

Utility functions for populating and manipulating arrays. Class unchanged but incorporated into clack codebase.


Constructor Summary
ArrayHelper()
           
 
Method Summary
static int extractInteger(byte[] bytes, int pos, int cnt)
          Extract an integer from a byte array.
static long extractLong(byte[] bytes, int pos, int cnt)
          Extract a long from a byte array.
static void fillBytes(byte[] byteArray, long value, int cnt, int index)
           
static void fillBytesLittleEndian(byte[] byteArray, long value, int cnt, int index)
           
static void insertLong(byte[] bytes, long value, int pos, int cnt)
          Insert data contained in a long integer into an array.
static byte[] join(byte[] a, byte[] b)
          Join two arrays.
static byte[] toBytes(long value, int cnt)
          Convert a long integer into an array of bytes.
static byte[] toBytesLittleEndian(long value, int cnt)
          Convert a long integer into an array of bytes, little endian format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayHelper

public ArrayHelper()
Method Detail

join

public static byte[] join(byte[] a,
                          byte[] b)
Join two arrays.


extractLong

public static long extractLong(byte[] bytes,
                               int pos,
                               int cnt)
Extract a long from a byte array.

Parameters:
bytes - an array.
pos - the starting position where the integer is stored.
cnt - the number of bytes which contain the integer.
Returns:
the long, or 0 if the index/length to use would cause an ArrayOutOfBoundsException

extractInteger

public static int extractInteger(byte[] bytes,
                                 int pos,
                                 int cnt)
Extract an integer from a byte array.

Parameters:
bytes - an array.
pos - the starting position where the integer is stored.
cnt - the number of bytes which contain the integer.
Returns:
the integer, or 0 if the index/length to use would cause an ArrayOutOfBoundsException

insertLong

public static void insertLong(byte[] bytes,
                              long value,
                              int pos,
                              int cnt)
Insert data contained in a long integer into an array.

Parameters:
bytes - an array.
value - the long to insert into the array.
pos - the starting position into which the long is inserted.
cnt - the number of bytes to insert.

toBytes

public static byte[] toBytes(long value,
                             int cnt)
Convert a long integer into an array of bytes.

Parameters:
value - the long to convert.
cnt - the number of bytes to convert.

toBytesLittleEndian

public static byte[] toBytesLittleEndian(long value,
                                         int cnt)
Convert a long integer into an array of bytes, little endian format. (i.e. this does the same thing as toBytes() but returns an array in reverse order from the array returned in toBytes().

Parameters:
value - the long to convert.
cnt - the number of bytes to convert.

fillBytes

public static void fillBytes(byte[] byteArray,
                             long value,
                             int cnt,
                             int index)

fillBytesLittleEndian

public static void fillBytesLittleEndian(byte[] byteArray,
                                         long value,
                                         int cnt,
                                         int index)