AXL Software

com.theorem.radserver3.radutil
Class Util

Object
  extended byUtil

public final class Util
extends Object

RADIUS utilities class.


Constructor Summary
Util()
           
 
Method Summary
static boolean cmp(byte[] a, byte[] b)
          Compare two byte arrays.
static boolean cmp(byte[] a, int startA, byte[] b, int startB, int length)
          Compare two byte arrays over a region.
static String dump(byte[] buf, int start, int length)
          Display a block of bytes sixteen bytes per row.
static String dumpStack(Throwable t)
          Return the stack trace as a string.
static String getTimeString(long millis)
          Turn a time in milliseconds into a more pleasant display of hours, minutes, and seconds as appropriate.
static byte[] hexToArray(String hexString)
          Return an array of bytes from a hex string.
static boolean sleep(long duration)
          Sleep for some time period.
static String[] splitUserName(String name, char prefix, char realm)
          Split the User-Name into prefix, name, and realm.
static String toASCII(byte[] b)
          Convert a byte array to a string using ASCII encoding.
static byte[] toASCII(String s)
          Convert a string to bytes encoded using ASCII, the TACACS+ protocol standard encoding.
static byte[] toBytes(long n, int length)
          Converts a long to an array of bytes.
static String toHexString(byte[] buf)
          Convert a byte buffer to a hex string.
static String toHexString(byte[] buf, int start, int length)
          Convert a byte buffer to a hex string.
static String toUTF8(byte[] b)
          Convert a byte array to a string using UTF8 encoding.
static byte[] toUTF8(char[] c)
          Convert a char array to a UTF8 byte array.
static byte[] toUTF8(String s)
          Convert a string to bytes encoded using UTF8, the RADIUS protocol standard encoding.
static char[] toUTF8Chars(byte[] b)
          Convert a byte array to a UTF8 char array.
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

cmp

public static boolean cmp(byte[] a,
                          byte[] b)
Compare two byte arrays.

Parameters:
a - array a
b - array b
Returns:
true if they're the same.

cmp

public static boolean cmp(byte[] a,
                          int startA,
                          byte[] b,
                          int startB,
                          int length)
Compare two byte arrays over a region.

Parameters:
a - Array A.
startA - The start position for comparing A.
b - Array B.
startB - The start position for comparing B.
length - Length of region.
Returns:
true if the comparison succeeded.

dump

public static String dump(byte[] buf,
                          int start,
                          int length)
Display a block of bytes sixteen bytes per row.

Parameters:
buf - Buffer to display.
start - Start position in buffer.
length - Length of data to dump.
Returns:
String representing the buffer.
Since:
3.41 (Axl Server)

dumpStack

public static String dumpStack(Throwable t)
Return the stack trace as a string.

Parameters:
t - Exception to trace.
Since:
3.36

getTimeString

public static String getTimeString(long millis)
Turn a time in milliseconds into a more pleasant display of hours, minutes, and seconds as appropriate.

Parameters:
millis - Milliseconds of elapsed time.
Returns:
String representing more readable time.

hexToArray

public static byte[] hexToArray(String hexString)
                         throws IllegalArgumentException
Return an array of bytes from a hex string.

Parameters:
hexString - Hex string to convert.
Returns:
Byte array.
Throws:
IllegalArgumentException - if there's a problem parsing the hex string.

sleep

public static boolean sleep(long duration)
Sleep for some time period.

Parameters:
duration - Sleep period in milliseconds.
Returns:
true if this sleep was interrupted.

splitUserName

public static String[] splitUserName(String name,
                                     char prefix,
                                     char realm)
Split the User-Name into prefix, name, and realm. Multiple consecutive prefix characters will be stripped.

For example 'prefix/name@realm' would be returned as ["prefix"] ["name"] ["realm"] as would 'prefix//name@realm'. 'name@realm' would be returned as [""] ["name"] ["realm"].

Parameters:
name - User-Name value.
prefix - Prefix character. If this character is sequentially repeated (like 'prefix//name') all the prefix characters will be stripped.
realm - realm character. This is usually a '@'.
Returns:
Array of three strings containing the prefix, name, and realm respectively. Any values not present are set to empty strings.

toASCII

public static String toASCII(byte[] b)
Convert a byte array to a string using ASCII encoding. This should not be used for conversion of RADIUS strings. Please use toUTF8().

In the event that US-ASCII is unavailable (highly unlikely) the encoding will be the platform's default encoding.

Parameters:
b - Byte array to convert.
Returns:
String.

toASCII

public static byte[] toASCII(String s)
Convert a string to bytes encoded using ASCII, the TACACS+ protocol standard encoding. This should not be used for conversion of RADIUS strings. Please use toUTF8().

In the event that US-ASCII is unavailable (highly unlikely) the encoding will be the platform's default encoding.

Parameters:
s - String to convert to a ASCII byte array.
Returns:
ASCII byte array.

toBytes

public static final byte[] toBytes(long n,
                                   int length)
Converts a long to an array of bytes.

Parameters:
n - value.
length - resulting length in bytes. Allowable byte lengths are 2, 3, 4, and 8.
Returns:
Byte array or null if length is incorrect.

toHexString

public static String toHexString(byte[] buf)
Convert a byte buffer to a hex string.

Parameters:
buf - Byte array.
Returns:
Hexadecimal representation.

toHexString

public static String toHexString(byte[] buf,
                                 int start,
                                 int length)
Convert a byte buffer to a hex string.

Parameters:
buf - Byte array.
start - Start position in array.
length - Number of bytes to display.
Returns:
Hexadecimal representation.

toUTF8

public static String toUTF8(byte[] b)
Convert a byte array to a string using UTF8 encoding.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
b - Byte array to convert.
Returns:
String.

toUTF8

public static byte[] toUTF8(char[] c)
Convert a char array to a UTF8 byte array.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
c - Char array to convert.
Returns:
the UTF8 byte array.

toUTF8

public static byte[] toUTF8(String s)
Convert a string to bytes encoded using UTF8, the RADIUS protocol standard encoding.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
s - String to convert to a UTF8 byte array.
Returns:
UTF8 byte array.

toUTF8Chars

public static char[] toUTF8Chars(byte[] b)
Convert a byte array to a UTF8 char array.

In the event that UTF8 is unavailable (highly unlikely) the encoding will be US-ASCII.

Parameters:
b - Byte array to convert.
Returns:
char array.

AXL Software

Submit a bug report or feature request

Copyright 1998-2010 AXL Software PO Box 97, Viola, Delaware 19979, U.S.A. All Rights Reserved.