com.mindbright.util
Class Util

java.lang.Object
  extended by com.mindbright.util.Util

public final class Util
extends java.lang.Object

Miscellaneous utility functions


Constructor Summary
Util()
           
 
Method Summary
static byte[] byteArrayFromHexString(java.lang.String in)
          Convert an hex-string to byte array "0001a0" -> {0x00, 0x01, 0xa0}
static java.lang.String getHost(java.lang.String address)
          Extracts the host part of an address string.
static int getPort(java.lang.String address, int def)
          Extracts the host part of an address string.
static java.lang.Object[] parseForwardSpec(java.lang.String spec, java.lang.Object local)
          Parses a port forward spec of the following format: /plugin/local_host:local_port:remote_host:remote_port Where /plugin/ and local_host: are optional.
 
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

getHost

public static java.lang.String getHost(java.lang.String address)
Extracts the host part of an address string. The address string is expected to be in the format: host:port where the ":port" part is optional. The host part is either a name or an IPv4 address. The host may also be an IPv6 literal address enclosed in brackets ([]).

Parameters:
address - the string to extract data from
Returns:
the host name

getPort

public static int getPort(java.lang.String address,
                          int def)
Extracts the host part of an address string. The address string is expected to be in the format: host:port where the ":port" part is optional. The host part is either a name or an IPv4 address. The host may also be an IPv6 literal address enclosed in brackets ([]).

Parameters:
address - the string to extract data from
def - default port number to return if the address does not contain any port definition.
Returns:
the port name

parseForwardSpec

public static java.lang.Object[] parseForwardSpec(java.lang.String spec,
                                                  java.lang.Object local)
                                           throws java.lang.IllegalArgumentException
Parses a port forward spec of the following format: /plugin/local_host:local_port:remote_host:remote_port Where /plugin/ and local_host: are optional.

local_host and remote_host may be names or literal IPv4 addreses. They can also be literal IPv6 addresses enclosed in ([]).

Parameters:
spec - the port forward spec
local - defaukt local listenber address
Returns:
an array of five objects
Throws:
java.lang.IllegalArgumentException

byteArrayFromHexString

public static byte[] byteArrayFromHexString(java.lang.String in)
Convert an hex-string to byte array "0001a0" -> {0x00, 0x01, 0xa0}

Parameters:
hex - a hexadecimal string
Returns:
a byte array