MjSip Stack
v1.6

org.zoolu.tools
Class Mangle

java.lang.Object
  |
  +--org.zoolu.tools.Mangle

public class Mangle
extends java.lang.Object

Mangle collects some static methods for mangling binary-data structures


Constructor Summary
Mangle()
           
 
Method Summary
static byte[] addressToBytes(java.lang.String addr)
          Transforms a dotted four-decimals string into a four-bytes array
static java.lang.String bytesToAddress(byte[] b)
          Transforms a four-bytes array into a dotted four-decimals string
static java.lang.String bytesToHexString(byte[] b)
          Transforms a byte array into a string of hex values
static java.lang.String bytesToHexString(byte[] b, int len)
          Transforms the first len bytes of an array into a string of hex values
static long bytesToInt(byte[] b)
          Transforms a 4-bytes array into a 32-bit int
static long bytesToWord(byte[] b)
          Transforms a 4-bytes array into a 32-bit word (with the more significative byte at left)
static long bytesToWord(byte[] b, int offset)
          Transforms a 4-bytes array into a 32-bit word (with the more significative byte at left)
static byte[] clone(byte[] b)
          Returns a copy of an array of bytes b
static boolean compare(byte[] a, byte[] b)
          Compares two arrays of bytes
static void copyBytes(byte[] src, byte[] dst, int offset)
          Copies all bytes of array src into array dst with offset offset
static void copyBytes(byte[] src, byte[] dst, int offset, int len)
          Copies the first len bytes of array src into array dst with offset offset
static void copyFourBytes(byte[] src, byte[] dst, int offset)
          Copies a the first 4 bytes of array src into array dst with offset index
static void copyTwoBytes(byte[] src, byte[] dst, int offset)
          Copies the first 2 bytes of array src into array dst with offset offset
static byte[] fourBytes(byte[] b, int offset)
          Returns a 4-byte array from array b with offset offset
static byte[] getBytes(byte[] b, int offset, int len)
          Returns a len-byte array from array b with offset offset
static byte[] hexStringToBytes(java.lang.String str)
          Transforms a string of hex values into an array of bytes.
static byte[] hexStringToBytes(java.lang.String str, int len)
          Transforms a string of hex values into an array of bytes of max length len.
static byte[] initBytes(byte[] b, int value)
          Initalizes a byte array with value value
static byte[] intToBytes(long n)
          Transforms a 32-bit int into a 4-bytes array
static void main(java.lang.String[] args)
           
static byte[] twoBytes(byte[] b, int offset)
          Returns a 2-byte array from array b with offset offset
static short uByte(byte b)
          Gets the unsigned representatin of a byte (into a short)
static long uWord(int n)
          Gets the unsigned representatin of a 32-bit word (into a long)
static byte[] wordToBytes(long n)
          Transforms a 32-bit word (with the more significative byte at left) into a 4-bytes array
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Mangle

public Mangle()
Method Detail

compare

public static boolean compare(byte[] a,
                              byte[] b)
Compares two arrays of bytes

initBytes

public static byte[] initBytes(byte[] b,
                               int value)
Initalizes a byte array with value value

uByte

public static short uByte(byte b)
Gets the unsigned representatin of a byte (into a short)

uWord

public static long uWord(int n)
Gets the unsigned representatin of a 32-bit word (into a long)

clone

public static byte[] clone(byte[] b)
Returns a copy of an array of bytes b

getBytes

public static byte[] getBytes(byte[] b,
                              int offset,
                              int len)
Returns a len-byte array from array b with offset offset

twoBytes

public static byte[] twoBytes(byte[] b,
                              int offset)
Returns a 2-byte array from array b with offset offset

fourBytes

public static byte[] fourBytes(byte[] b,
                               int offset)
Returns a 4-byte array from array b with offset offset

copyBytes

public static void copyBytes(byte[] src,
                             byte[] dst,
                             int offset)
Copies all bytes of array src into array dst with offset offset

copyBytes

public static void copyBytes(byte[] src,
                             byte[] dst,
                             int offset,
                             int len)
Copies the first len bytes of array src into array dst with offset offset

copyTwoBytes

public static void copyTwoBytes(byte[] src,
                                byte[] dst,
                                int offset)
Copies the first 2 bytes of array src into array dst with offset offset

copyFourBytes

public static void copyFourBytes(byte[] src,
                                 byte[] dst,
                                 int offset)
Copies a the first 4 bytes of array src into array dst with offset index

bytesToHexString

public static java.lang.String bytesToHexString(byte[] b,
                                                int len)
Transforms the first len bytes of an array into a string of hex values

bytesToHexString

public static java.lang.String bytesToHexString(byte[] b)
Transforms a byte array into a string of hex values

hexStringToBytes

public static byte[] hexStringToBytes(java.lang.String str,
                                      int len)
Transforms a string of hex values into an array of bytes of max length len. The string may include ':' chars. If len is set to -1, all string is converted.

hexStringToBytes

public static byte[] hexStringToBytes(java.lang.String str)
Transforms a string of hex values into an array of bytes. The string may include ':' chars.

bytesToAddress

public static java.lang.String bytesToAddress(byte[] b)
Transforms a four-bytes array into a dotted four-decimals string

addressToBytes

public static byte[] addressToBytes(java.lang.String addr)
Transforms a dotted four-decimals string into a four-bytes array

bytesToInt

public static long bytesToInt(byte[] b)
Transforms a 4-bytes array into a 32-bit int

intToBytes

public static byte[] intToBytes(long n)
Transforms a 32-bit int into a 4-bytes array

bytesToWord

public static long bytesToWord(byte[] b,
                               int offset)
Transforms a 4-bytes array into a 32-bit word (with the more significative byte at left)

bytesToWord

public static long bytesToWord(byte[] b)
Transforms a 4-bytes array into a 32-bit word (with the more significative byte at left)

wordToBytes

public static byte[] wordToBytes(long n)
Transforms a 32-bit word (with the more significative byte at left) into a 4-bytes array

main

public static void main(java.lang.String[] args)

MjSip Stack
v1.6