intarsys runtime library

de.intarsys.tools.collection
Class ByteArrayTools

java.lang.Object
  extended by de.intarsys.tools.collection.ByteArrayTools

public class ByteArrayTools
extends Object


Constructor Summary
ByteArrayTools()
           
 
Method Summary
static byte[] concat(byte[] array1, byte[] array2)
           
static byte[] copy(byte[] bytes)
          Make a copy of bytes.
static byte[] copy(byte[] bytes, int offset, int length)
          Copy length bytes from bytes starting at from.
static byte[] createBytes(int length, byte val)
          A byte array with the defined length, filled with val.
static byte[] createRandomBytes(int length)
          A random byte sequence of length length.
static boolean equals(byte[] array1, int offset1, byte[] array2, int offset2, int length)
          Checks two arrays or sections thereof for equality.
static int indexOf(byte[] source, int sourceOffset, int sourceLen, byte[] pattern, int patternOffset, int patternLen, int fromIndex)
          Search index of pattern in source.
static boolean startsWith(byte[] bytes, byte[] pattern)
          true if bytes starts with the byte sequence defined in pattern.
static void toBigEndianArray(byte[] bytes, int offset, int value, int size)
           
static byte[] toBigEndianArray(int value, int size)
           
static int toBigEndianInteger(byte[] buffer, int offset, int size)
           
static void toLittleEndianArray(byte[] bytes, int offset, int value, int size)
           
static void toLittleEndianArray(byte[] bytes, int offset, long value, int size)
           
static byte[] toLittleEndianArray(int value, int size)
           
static byte[] toLittleEndianArray(long value, int size)
           
static int toLittleEndianInteger(byte[] buffer, int offset, int size)
           
static long toLittleEndianLong(byte[] buffer, int offset, int size)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayTools

public ByteArrayTools()
Method Detail

concat

public static byte[] concat(byte[] array1,
                            byte[] array2)

copy

public static byte[] copy(byte[] bytes)
Make a copy of bytes.

Parameters:
bytes - byte[] to be copied
Returns:
A copy of bytes

copy

public static byte[] copy(byte[] bytes,
                          int offset,
                          int length)
Copy length bytes from bytes starting at from.

Parameters:
bytes - byte[] to be copied
offset - starting position to copy from
length - number of bytes
Returns:
A copy of bytes

createBytes

public static byte[] createBytes(int length,
                                 byte val)
A byte array with the defined length, filled with val.

Parameters:
length -
val -
Returns:
A byte array with the defined length, filled with val.

createRandomBytes

public static byte[] createRandomBytes(int length)
A random byte sequence of length length.

Parameters:
length -
Returns:
A random byte sequence of length length.

equals

public static boolean equals(byte[] array1,
                             int offset1,
                             byte[] array2,
                             int offset2,
                             int length)
Checks two arrays or sections thereof for equality. If an array is null or it's section is shorter than the compared length, false is returned.

Parameters:
array1 -
offset1 -
array2 -
offset2 -
length - must have a value greater than 0. A value of 0 always returns false.
Returns:
true, if the compared array sections match

indexOf

public static int indexOf(byte[] source,
                          int sourceOffset,
                          int sourceLen,
                          byte[] pattern,
                          int patternOffset,
                          int patternLen,
                          int fromIndex)
Search index of pattern in source. Algorithm from java.lang.String

Parameters:
source -
sourceOffset -
sourceLen -
pattern -
patternOffset -
patternLen -
fromIndex -
Returns:
The index of the first occurrence of pattern or -1.

startsWith

public static boolean startsWith(byte[] bytes,
                                 byte[] pattern)
true if bytes starts with the byte sequence defined in pattern.

Parameters:
bytes -
pattern -
Returns:
true if bytes starts with the byte sequence defined in pattern.

toBigEndianArray

public static void toBigEndianArray(byte[] bytes,
                                    int offset,
                                    int value,
                                    int size)

toBigEndianArray

public static byte[] toBigEndianArray(int value,
                                      int size)

toBigEndianInteger

public static int toBigEndianInteger(byte[] buffer,
                                     int offset,
                                     int size)

toLittleEndianArray

public static void toLittleEndianArray(byte[] bytes,
                                       int offset,
                                       int value,
                                       int size)

toLittleEndianArray

public static void toLittleEndianArray(byte[] bytes,
                                       int offset,
                                       long value,
                                       int size)

toLittleEndianArray

public static byte[] toLittleEndianArray(int value,
                                         int size)

toLittleEndianArray

public static byte[] toLittleEndianArray(long value,
                                         int size)

toLittleEndianInteger

public static int toLittleEndianInteger(byte[] buffer,
                                        int offset,
                                        int size)

toLittleEndianLong

public static long toLittleEndianLong(byte[] buffer,
                                      int offset,
                                      int size)

intarsys runtime library

Copyright © 2012 intarsys consulting GmbH. All Rights Reserved.