org.aselect.system.utils
Class Utils

java.lang.Object
  extended by org.aselect.system.utils.Utils

public class Utils
extends java.lang.Object

Static class that implements generic, widely used utility methods.

Description:
The Utils class implements convenient static methods used widely by A-Select components.

Concurrency issues:
None.

Author:
Alfa & Ariss

Constructor Summary
Utils()
           
 
Method Summary
static java.util.Hashtable convertCGIMessage(java.lang.String xMessage)
          Converts a CGI-based String to a hashtable.
static int fromDigit(char ch)
          Returns an int from 0 to 15 corresponding to the specified hex digit.
static java.lang.String hashtable2CGIMessage(java.util.Hashtable htInput)
          Convert Hashtable to CGI message string.
static boolean matchWildcardMask(java.lang.String s, java.lang.String sMask)
          Compare a string against another string that may contain wildcards.
static java.lang.String prefixString(java.lang.String xPrefix, java.lang.String xString, int xEndlength)
          Prefixes a String with another String until a specified length is reached.
static java.lang.String replaceString(java.lang.String xSrc, java.lang.String xString, java.lang.String xReplaceString)
          Replaces all occurences of a string in a source string.
static byte[] stringToHex(java.lang.String xHexString)
          Returns a byte array corresponding to a hexadecimal String.
static java.lang.String toHexString(byte[] xBytes)
          Outputs a hex-string respresentation of a byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

fromDigit

public static int fromDigit(char ch)
Returns an int from 0 to 15 corresponding to the specified hex digit.

Description:
For input 'A' this method returns 10 etc. Input is case-insensitive .

Concurrency issues:
None.

Preconditions:
Only hexadecimal characters [0..f] or [0..F] are processed.

Postconditions:
None.

Parameters:
ch - Input hexadecimal character.
Returns:
int representing ch.
Throws:
java.lang.IllegalArgumentException - on non-hexadecimal characters.

toHexString

public static java.lang.String toHexString(byte[] xBytes)
Outputs a hex-string respresentation of a byte array.

Description:
This method returns the hexadecimal String representation of a byte array.

Example:
For input [0x13, 0x2f, 0x98, 0x76], this method returns a String object containing "132F9876".

Concurrency issues:
None.

Preconditions:
None.

Postconditions:
None.

Parameters:
xBytes - Source byte array.
Returns:
a String object respresenting xBytes in hexadecimal format.

stringToHex

public static byte[] stringToHex(java.lang.String xHexString)
Returns a byte array corresponding to a hexadecimal String.

Description:
Example:
For input "132F9876", this method returns an array containing [0x13, 0x2f, 0x98, 0x76].

Concurrency issues:
None.

Preconditions:
The xHexString must be a hexadecimal String.

Postconditions:
None.

Parameters:
xHexString - String containing a hexadecimal string.
Returns:
a byte array containing the converted hexadecimal values.
Throws:
java.lang.IllegalArgumentException - on non-hexadecimal characters.

prefixString

public static java.lang.String prefixString(java.lang.String xPrefix,
                                            java.lang.String xString,
                                            int xEndlength)
Prefixes a String with another String until a specified length is reached.

Description:
Example:

String xVar = "873";
xVar = prefixString("0", xVar, 5);
System.out.println(xVar);

This will print

00873

Concurrency issues:
None.

Preconditions:
xPrefix may not be null.

Postconditions:
None.

Parameters:
xPrefix - character to prefix xString with.
xString - input String.
xEndlength - length of desired output String.
Returns:
String containing the output String.

replaceString

public static java.lang.String replaceString(java.lang.String xSrc,
                                             java.lang.String xString,
                                             java.lang.String xReplaceString)
Replaces all occurences of a string in a source string.

Description:
Trivial.

Concurrency issues:
None.

Preconditions:
None.

Postconditions:
None.

Parameters:
xSrc - The source string.
xString - The string that is to be replaced.
xReplaceString - The string that replaces xString.
Returns:
A String containing all occurences of xString replaced by xReplaceString.

convertCGIMessage

public static java.util.Hashtable convertCGIMessage(java.lang.String xMessage)
Converts a CGI-based String to a hashtable.

Description:
This methods converts a CGI-based String containing key=value&key=value to a hashtable containing the keys and corresponding values.

Concurrency issues:
None.

Preconditions:
CGI-based input String (xMessage).

Postconditions:
All keys in the returned hashtable are converted to lowercase.

Parameters:
xMessage - CGI-based input String.
Returns:
Hashtable containg the keys and corresponding values.

hashtable2CGIMessage

public static java.lang.String hashtable2CGIMessage(java.util.Hashtable htInput)
                                             throws java.io.UnsupportedEncodingException
Convert Hashtable to CGI message string.

Description:
Creates a CGI syntax message from the key/value pairs in the input Hashtable.

Concurrency issues:
The used Hashtableobjects are synchronized.

Preconditions:
htInput should be a Hashtable containing valid parameters.

Postconditions:
The return String contains the parameters in CGI syntax.

Parameters:
htInput - The Hashtable to be converted.
Returns:
CGI message containg all parameters in htInput.
Throws:
java.io.UnsupportedEncodingException - If URL encoding fails.

matchWildcardMask

public static boolean matchWildcardMask(java.lang.String s,
                                        java.lang.String sMask)
Compare a string against another string that may contain wildcards.

Description:
Compares string s against sMask, where sMask may contain wildcards (* and ?).

Concurrency issues:
None

Parameters:
s - The string to compare against sMask.
sMask - The mask to compare against. May contain wildcards.
Returns:
true if they match, false otherwise


Copyright © 2008 SURFnet BV. All Rights Reserved.