ch.claudio.iax2
Class Util

java.lang.Object
  extended by ch.claudio.iax2.Util

public final class Util
extends java.lang.Object

Version:
$Id: Util.java 148 2006-09-14 20:52:32Z claudio $
Author:
Claudio Nieder

Copyright (C) 2006 Claudio Nieder <private@claudio.ch>, CH-8610 Uster

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


Constructor Summary
Util()
           
 
Method Summary
static java.lang.String getString(byte[] buffer, int offset, int length)
          Read the requested number of byte from the buffer and return it interpreted an utf-8 encoded string.
static int getUnsigned16(byte[] buffer, int offset)
          Read two byte from the buffer and return it interpreted as a big endian unsigned value.
static long getUnsigned32(byte[] buffer, int offset)
          Read four byte from the buffer and return it interpreted as a big endian unsigned value.
static int getUnsigned8(byte[] buffer, int offset)
          Read a byte from the buffer and return its unsigned value.
static void main(java.lang.String[] args)
          Print license.
static java.lang.String md5(java.lang.String text)
          Compute an md5 checksum interpreting the text as utf-8 encoded.
static int putString(byte[] buffer, int offset, java.lang.String value)
          Put a string into the buffer using utf-8 encoding.
static void putUnsigned16(byte[] buffer, int offset, int word)
          Put an unsinged value within the range 0..65536 into a byte array in big endian manner.
static void putUnsigned32(byte[] buffer, int offset, long word)
          Put an unsinged value within the range 0..4294967296 into a byte array in big endian matter.
static void putUnsigned8(byte[] buffer, int offset, int word)
          Put an unsinged value within the range 0..255 into a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

md5

public static final java.lang.String md5(java.lang.String text)
Compute an md5 checksum interpreting the text as utf-8 encoded.

Parameters:
text - String for which md5 sum is to be computed
Returns:
String with md5 sum as hex string

putUnsigned8

public static final void putUnsigned8(byte[] buffer,
                                      int offset,
                                      int word)
Put an unsinged value within the range 0..255 into a byte array.

Parameters:
buffer - byte array
offset - where to put the value
word - value to store

putUnsigned16

public static final void putUnsigned16(byte[] buffer,
                                       int offset,
                                       int word)
Put an unsinged value within the range 0..65536 into a byte array in big endian manner.

Parameters:
buffer - byte array
offset - start position to which the value is written
word - value to store

putUnsigned32

public static final void putUnsigned32(byte[] buffer,
                                       int offset,
                                       long word)
Put an unsinged value within the range 0..4294967296 into a byte array in big endian matter.

Parameters:
buffer - byte array
offset - where to put the value
word - value to store

getUnsigned8

public static final int getUnsigned8(byte[] buffer,
                                     int offset)
Read a byte from the buffer and return its unsigned value.

Parameters:
buffer - byte array
offset - where to read the value
Returns:
value

getUnsigned16

public static final int getUnsigned16(byte[] buffer,
                                      int offset)
Read two byte from the buffer and return it interpreted as a big endian unsigned value.

Parameters:
buffer - byte array
offset - where to read the value
Returns:
value

getUnsigned32

public static final long getUnsigned32(byte[] buffer,
                                       int offset)
Read four byte from the buffer and return it interpreted as a big endian unsigned value.

Parameters:
buffer - byte array
offset - where to read the value
Returns:
value

getString

public static final java.lang.String getString(byte[] buffer,
                                               int offset,
                                               int length)
Read the requested number of byte from the buffer and return it interpreted an utf-8 encoded string.

Note: This method terminates the JVM (System.exit(1)) if utf-8 encoding is not supported.

Parameters:
buffer - byte array
offset - where to read the value
length - number of byte to read
Returns:
value

putString

public static final int putString(byte[] buffer,
                                  int offset,
                                  java.lang.String value)
Put a string into the buffer using utf-8 encoding. The string is preceeded by one byte containing its length.

Note: This method terminates the JVM (System.exit(1)) if utf-8 encoding is not supported.

Parameters:
buffer - byte array
offset - where to read the value
value - String to insert
Returns:
legth of encoded string plus 1.

main

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

Parameters:
args - ignored