com.flat502.rox.utils
Class Utils

java.lang.Object
  extended by com.flat502.rox.utils.Utils

public class Utils
extends java.lang.Object

This class provides various static utility routines used by the rest of this library.


Constructor Summary
Utils()
           
 
Method Summary
static java.lang.Object coerce(java.lang.Object value, java.lang.Class targetType)
           
static java.lang.Object convert(java.lang.Object value, java.lang.Class targetType)
           
static java.security.cert.X509Certificate convert(javax.security.cert.X509Certificate cert)
           
static javax.security.cert.X509Certificate convert(java.security.cert.X509Certificate cert)
           
static java.lang.Object convertToArray(java.lang.Class targetType, java.lang.Object value)
           
static boolean[] convertToBooleanArray(java.util.List list)
           
static double[] convertToDoubleArray(java.util.List list)
           
static float[] convertToFloatArray(java.util.List list)
           
static int[] convertToIntArray(java.util.List list)
           
static long[] convertToLongArray(java.util.List list)
           
static void dbgPrintln(java.lang.String msg)
          A very simple utility routine to aid debugging.
static java.nio.charset.Charset extractContentCharset(java.lang.String contentType)
          Parses the value of an HTTP Content-Type header and returns the specified character set.
static java.lang.String extractContentType(java.lang.String contentType)
          Parses the value of an HTTP Content-Type header and returns the Internet Media Type type and sub-type separated by a forwards-slash.
static float getJavaRuntimeVersion()
           
static java.lang.String join(java.lang.String delim, java.util.Iterator iter)
           
static java.lang.String join(java.lang.String delim, java.lang.Object[] values)
           
static void main(java.lang.String[] args)
           
static java.io.Reader newXmlReader(java.io.InputStream in, java.nio.charset.Charset hint)
          Converts an InputStream containing XML into a Reader using the encoding specified in the XML header.
static java.lang.String normalizeHttpHeaderName(java.lang.String name)
          Normalizes an HTTP header name.
static java.lang.String normalizeURIPath(java.lang.String uri)
           
static
<T> T[]
resize(T[] src, int newsize)
           
static java.lang.String[] splitAt(java.lang.String input, java.lang.String marker)
           
static java.lang.Object toArray(java.lang.Class targetType, java.lang.Object value)
           
static boolean[] toBooleanArray(java.util.List list)
           
static double[] toDoubleArray(java.util.List list)
           
static float[] toFloatArray(java.util.List list)
           
static java.lang.String toHexDump(byte[] data)
           
static java.lang.String toHexDump(byte[] data, int offset, int length)
           
static int[] toIntArray(java.util.List list)
           
static long[] toLongArray(java.util.List list)
           
static java.lang.String toString(boolean[] list)
           
static java.lang.String toString(boolean[][] list)
           
static java.lang.String toString(int[] list)
           
static java.lang.String toString(java.lang.Object[] list)
           
static java.lang.String toString(java.security.Principal p)
           
static java.lang.String toString(java.nio.channels.SelectionKey key)
           
static java.lang.String toString(java.net.ServerSocket socket)
           
static java.lang.String toString(java.net.Socket socket)
           
static java.lang.String toString(javax.net.ssl.SSLSession session)
           
 
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

extractContentCharset

public static java.nio.charset.Charset extractContentCharset(java.lang.String contentType)
Parses the value of an HTTP Content-Type header and returns the specified character set.

If no character set is specified then ISO-8859-1 is returned as per section 3.7.1 of RFC 2616.

Parameters:
contentType - The value of the Content-Type header.
Returns:
The character set specified by the value or ISO-8859-1 if none was found.

extractContentType

public static java.lang.String extractContentType(java.lang.String contentType)
Parses the value of an HTTP Content-Type header and returns the Internet Media Type type and sub-type separated by a forwards-slash.

Any additional parameters (such as character set information) is discarded.

An example of a return value would be text/xml.

Parameters:
contentType - The value of the Content-Type header.
Returns:
The content type.
Throws:
java.lang.IllegalArgumentException - if the value is malformed.

normalizeURIPath

public static java.lang.String normalizeURIPath(java.lang.String uri)

newXmlReader

public static java.io.Reader newXmlReader(java.io.InputStream in,
                                          java.nio.charset.Charset hint)
                                   throws java.lang.Exception
Converts an InputStream containing XML into a Reader using the encoding specified in the XML header.

The encoding is determined as specified by appendix F of version 1.0 of the XML specification.

Parameters:
in - The input stream the XML document should be read from.
hint - An optional hint (may be null) if the caller has an idea of what the encoding may be.
Returns:
A Reader instance backed by the given InputStream using the encoding specified by the XML document within the stream.
Throws:
java.lang.Exception - if the underlying encoding cannot be determined, or if an error occurs while constructing a reader to return.

dbgPrintln

public static void dbgPrintln(java.lang.String msg)
A very simple utility routine to aid debugging.

The message is printed to stdout, prefixed with the name of the calling thread and the interval in milliseconds since this class was loaded. This is handy for simple "println" style debugging when relative timing is a factor.

Parameters:
msg - The message to display.

normalizeHttpHeaderName

public static java.lang.String normalizeHttpHeaderName(java.lang.String name)
Normalizes an HTTP header name.

Normalization produces the logical equivalent of the following algorithm.

The name is split into words using the '-' character. Each word is then normalized by converting the first character to uppercase and all remaining characters to lowercase. The resulting words are joined again using the '-' character. The result is returned.

Parameters:
name - The header name.
Returns:
The normalized header name.

join

public static java.lang.String join(java.lang.String delim,
                                    java.lang.Object[] values)

join

public static java.lang.String join(java.lang.String delim,
                                    java.util.Iterator iter)

toArray

public static java.lang.Object toArray(java.lang.Class targetType,
                                       java.lang.Object value)

toIntArray

public static int[] toIntArray(java.util.List list)

toLongArray

public static long[] toLongArray(java.util.List list)

toBooleanArray

public static boolean[] toBooleanArray(java.util.List list)

toFloatArray

public static float[] toFloatArray(java.util.List list)

toDoubleArray

public static double[] toDoubleArray(java.util.List list)

coerce

public static java.lang.Object coerce(java.lang.Object value,
                                      java.lang.Class targetType)

convert

public static java.lang.Object convert(java.lang.Object value,
                                       java.lang.Class targetType)

convertToArray

public static java.lang.Object convertToArray(java.lang.Class targetType,
                                              java.lang.Object value)

convertToIntArray

public static int[] convertToIntArray(java.util.List list)

convertToLongArray

public static long[] convertToLongArray(java.util.List list)

convertToBooleanArray

public static boolean[] convertToBooleanArray(java.util.List list)

convertToFloatArray

public static float[] convertToFloatArray(java.util.List list)

convertToDoubleArray

public static double[] convertToDoubleArray(java.util.List list)

toHexDump

public static java.lang.String toHexDump(byte[] data)

toHexDump

public static java.lang.String toHexDump(byte[] data,
                                         int offset,
                                         int length)

toString

public static java.lang.String toString(int[] list)

toString

public static java.lang.String toString(boolean[] list)

toString

public static java.lang.String toString(boolean[][] list)

toString

public static java.lang.String toString(java.lang.Object[] list)

toString

public static java.lang.String toString(java.net.Socket socket)

toString

public static java.lang.String toString(java.net.ServerSocket socket)

toString

public static java.lang.String toString(java.nio.channels.SelectionKey key)

toString

public static java.lang.String toString(javax.net.ssl.SSLSession session)

toString

public static java.lang.String toString(java.security.Principal p)

getJavaRuntimeVersion

public static float getJavaRuntimeVersion()

resize

public static <T> T[] resize(T[] src,
                             int newsize)

convert

public static java.security.cert.X509Certificate convert(javax.security.cert.X509Certificate cert)
                                                  throws javax.security.cert.CertificateEncodingException,
                                                         java.security.cert.CertificateException
Throws:
javax.security.cert.CertificateEncodingException
java.security.cert.CertificateException

convert

public static javax.security.cert.X509Certificate convert(java.security.cert.X509Certificate cert)
                                                   throws java.security.cert.CertificateEncodingException,
                                                          javax.security.cert.CertificateException
Throws:
java.security.cert.CertificateEncodingException
javax.security.cert.CertificateException

splitAt

public static java.lang.String[] splitAt(java.lang.String input,
                                         java.lang.String marker)

main

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