org.mulgara.util
Class Strings

java.lang.Object
  extended by org.mulgara.util.Strings

public class Strings
extends Object

String utilities.


Constructor Summary
Strings()
           
 
Method Summary
static String indent(int indent)
          Returns a string containing an indentation.
static byte[] parseHexToBytes(String hex)
          Converts a string of hexadecimal characters into a byte array.
static QName parseQName(URI u)
          Converts a URI into a QName, based entirely on parsing.
static int startOfName(String s)
          Determines the start of a name in a URI that can be turned into a QName.
static String toHexString(byte[] data)
          Converts a byte array to a string with each byte being represented by a pair of hexadecimal characters.
static byte[] toUtf8Bytes(String str)
          Converts a string to a byte array with UTF8.
static String xmlEscape(String s)
          Search for disallowed XML characters in a string, and replace them with their escape codes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

toUtf8Bytes

public static final byte[] toUtf8Bytes(String str)
Converts a string to a byte array with UTF8. Any problems are emitted as an InternalError instead of an Exception.

Parameters:
str - The string to convert.
Returns:
A byte array representing the string.
Throws:
InternalError - If UTF-8 encoding fails.

parseHexToBytes

public static final byte[] parseHexToBytes(String hex)
Converts a string of hexadecimal characters into a byte array. This is the inverse operation to toHexString(byte[])

Parameters:
hex - The string of hex characters. These must appear in pairs that form bytes.
Returns:
An array of bytes containing the data from the hex string.
Throws:
IllegalArgumentException - If the string has an odd number of characters, or any characters are not valid hexadecimal characters.

toHexString

public static final String toHexString(byte[] data)
Converts a byte array to a string with each byte being represented by a pair of hexadecimal characters. This is the inverse operation of parseHexToBytes(java.lang.String).

Parameters:
data - The data to convert.
Returns:
A string representing the hexadecimal value of the byte array.

parseQName

public static QName parseQName(URI u)
Converts a URI into a QName, based entirely on parsing.

Parameters:
u - The URI to parse.
Returns:
A QName containing the URI as a namespace/localpart combination, or the entire uri as a localpart if it could not be parsed.

startOfName

public static int startOfName(String s)
Determines the start of a name in a URI that can be turned into a QName.

Parameters:
s - The string to search.
Returns:
The index of the first character in the name.

indent

public static String indent(int indent)
Returns a string containing an indentation.

Parameters:
indent - The number of indentations to use.
Returns:
A String containing the appropriate indentation.

xmlEscape

public static String xmlEscape(String s)
Search for disallowed XML characters in a string, and replace them with their escape codes.

Parameters:
s - The string to escape.
Returns:
A new version of the input string, with XML escaping done.


Copyright © 2011. All Rights Reserved.