ch.bind.philib.lang
Class ArrayUtil

java.lang.Object
  extended by ch.bind.philib.lang.ArrayUtil

public abstract class ArrayUtil
extends Object

Various functions for dealing with arrays which are not present in the standard Arrays class.

Since:
2009-06-10
Author:
Philipp Meinen

Field Summary
static byte[] EMPTY_BYTE_ARRAY
           
 
Constructor Summary
protected ArrayUtil()
           
 
Method Summary
static byte[] append(byte[] a, byte[] b, int capacity)
          append the content of two byte arrays up to a certain capacity limit
static byte[] concat(byte[] a, byte[] b)
          concatenate the content of two byte arrays.
static boolean contains(byte[] data, byte[] search)
           
static byte[] extractBack(byte[] data, int len)
           
static byte[] extractFront(byte[] data, int len)
           
static int find(byte[] data, byte[] search)
           
static int find(byte[] data, byte[] search, int dataOffset)
           
static String formatShortHex(byte[] data)
           
static String formatShortHex(byte[] data, int off, int len)
           
static String formatShortHex(ByteBuffer data)
           
static String formatShortHex(ByteBuffer data, int len)
           
static void memsetZero(byte[] buf)
           
static void memsetZero(ByteBuffer buf)
          Overwrites the buffer's content with zeros.
static
<T> void
pickRandom(T[] source, T[] destination)
          Fills the destination array with randomly picked values from the source array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_BYTE_ARRAY

public static final byte[] EMPTY_BYTE_ARRAY
Constructor Detail

ArrayUtil

protected ArrayUtil()
Method Detail

pickRandom

public static <T> void pickRandom(T[] source,
                                  T[] destination)
Fills the destination array with randomly picked values from the source array. No value will be picked twice.

Parameters:
source - The array from which random values must be picked. The content of this array will not be altered.
destination - The array which must be filled with random values. Previous values within this array will be overwritten.
Throws:
NullPointerException - If either of the two parameters is null.
IllegalArgumentException - If the source-array is smaller then the destination -array.

concat

public static byte[] concat(byte[] a,
                            byte[] b)
concatenate the content of two byte arrays.

Parameters:
a - the first byte array (may be null)
b - the second byte array (may be null)
Returns:
a new byte array with the combined length of a and b, containing a copy of their content.

append

public static byte[] append(byte[] a,
                            byte[] b,
                            int capacity)
append the content of two byte arrays up to a certain capacity limit

Parameters:
a - the first byte array (may be null)
b - the second byte array (may be null)
Returns:
a new byte array with the combined length of a and b, containing a copy of their content. if the combined length exceeds capacity the returned array a will have a.length == capacity.

extractBack

public static byte[] extractBack(byte[] data,
                                 int len)

extractFront

public static byte[] extractFront(byte[] data,
                                  int len)

contains

public static boolean contains(byte[] data,
                               byte[] search)

find

public static int find(byte[] data,
                       byte[] search)

find

public static int find(byte[] data,
                       byte[] search,
                       int dataOffset)

formatShortHex

public static String formatShortHex(byte[] data)

formatShortHex

public static String formatShortHex(byte[] data,
                                    int off,
                                    int len)

formatShortHex

public static String formatShortHex(ByteBuffer data,
                                    int len)

formatShortHex

public static String formatShortHex(ByteBuffer data)

memsetZero

public static void memsetZero(ByteBuffer buf)
Overwrites the buffer's content with zeros. The buffer is cleared.

Parameters:
buf -

memsetZero

public static void memsetZero(byte[] buf)


Copyright © 2013. All Rights Reserved.