de.bb.util
Class Misc

java.lang.Object
  extended by de.bb.util.Misc

public class Misc
extends java.lang.Object

Provides some useful functions to deal with byte arrays.


Constructor Summary
Misc()
           
 
Method Summary
static java.lang.String bytes2Hex(byte[] b)
          Convert a byte array into a hex string.
static void dump(java.io.OutputStream out, byte[] b)
          helper fx to dump to stdout.
static void dump(java.io.PrintWriter ps, java.lang.String s, byte[] bb, int offset, int len)
          Dump a byte array as hex values.
static void dump(java.lang.String title, java.io.OutputStream out, byte[] b)
          helper fx to dump to stdout.
static void dump(java.lang.String title, java.io.OutputStream out, byte[] b, int len)
          helper fx to dump to stdout.
static void dump(java.lang.String title, java.io.OutputStream out, byte[] b, int offset, int len)
          helper fx to dump to stdout.
static boolean equals(byte[] a, byte[] b)
          Compares one byte array with another byte array.
static boolean equals(byte[] a, int aOff, byte[] b, int bOff, int len)
          Compares one segment of a byte array with a segment of a 2nd byte array.
static byte[] hex2Bytes(java.lang.String s)
          Interpret the String as hex values and convert it to a byte array.
static java.lang.String replaceAll(java.lang.String string, char c, char d)
          Helper method to replace all occurencies of a character to a different character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Misc

public Misc()
Method Detail

equals

public static final boolean equals(byte[] a,
                                   int aOff,
                                   byte[] b,
                                   int bOff,
                                   int len)
Compares one segment of a byte array with a segment of a 2nd byte array.

Parameters:
a - first byte array
aOff - offset into first byte array
b - second byte array
bOff - offset into second byte array
len - length of the compared segments
Returns:
true if the segments are equal, otherwise false

equals

public static final boolean equals(byte[] a,
                                   byte[] b)
Compares one byte array with another byte array.

Parameters:
a - first byte array
b - second byte array
Returns:
true if the byte arrays are equal, otherwise false

hex2Bytes

public static byte[] hex2Bytes(java.lang.String s)
Interpret the String as hex values and convert it to a byte array.
"abcd" -> { (byte)0xab, (byte)0xcd }

Parameters:
s - the string
Returns:
a new allocated byte array containing the bytes

bytes2Hex

public static java.lang.String bytes2Hex(byte[] b)
Convert a byte array into a hex string.
{ (byte)0xab, (byte)0xcd } -> "abcd"

Parameters:
b - the byte array
Returns:
a new allocated string the bytes in hex

replaceAll

public static java.lang.String replaceAll(java.lang.String string,
                                          char c,
                                          char d)
Helper method to replace all occurencies of a character to a different character.

Parameters:
string - a string - not null
c - the character to be replaced
d - the replacement
Returns:
the string

dump

public static final void dump(java.io.PrintWriter ps,
                              java.lang.String s,
                              byte[] bb,
                              int offset,
                              int len)
Dump a byte array as hex values.

Parameters:
ps - the used PrintWriter.
s - a headline for each dumped block.
bb - the byte array to display
offset - offset into that array
len - the count of the dumped bytes.

dump

public static void dump(java.io.OutputStream out,
                        byte[] b)
helper fx to dump to stdout.

Parameters:
out - - some outputStream
b - - the bytes to dump

dump

public static void dump(java.lang.String title,
                        java.io.OutputStream out,
                        byte[] b)
helper fx to dump to stdout.

Parameters:
title - title for the dump message
out - - some outputStream
b - - the bytes to dump

dump

public static void dump(java.lang.String title,
                        java.io.OutputStream out,
                        byte[] b,
                        int len)
helper fx to dump to stdout.

Parameters:
title - title for the dump message
out - - some outputStream
b - - the bytes to dump
len - the length to dump

dump

public static void dump(java.lang.String title,
                        java.io.OutputStream out,
                        byte[] b,
                        int offset,
                        int len)
helper fx to dump to stdout.

Parameters:
title - title for the dump message
out - - some outputStream
b - - the bytes to dump
offset - offset into the data
len - the length to dump