org.hsqldb.lib
Class StringConverter

java.lang.Object
  extended byorg.hsqldb.lib.StringConverter

public class StringConverter
extends Object

Collection of static methods for converting strings between different formats and to and from byte arrays

Version:
1.7.2

Constructor Summary
StringConverter()
           
 
Method Summary
static String asciiToUnicode(byte[] s, int offset, int length)
          Hsqldb specific decoding used only for log files.
static String asciiToUnicode(String s)
           
static String byteToHex(byte[] b)
          Converts a byte array into a hexadecimal string
static String byteToString(byte[] b, String charset)
           
static int getUTFSize(String s)
           
static String hexStringToUnicode(String s)
          Converts a hex string into a byte array then converts the byte array into a Unicode string.
static byte[] hexToByte(String s)
          Compacts a hexadecimal string into a byte array
static String inputStreamToString(InputStream x)
          Using a Reader and a Writer, returns a String from an InputStream
static String readUTF(byte[] bytearr, int offset, int length)
           
static String toQuotedString(String s, char quoteChar, boolean extraQuote)
          Returns the quoted version of the string using the quotechar argument.
static int unicodeToAscii(OutputStream b, String s, boolean doubleSingleQuotes)
          Hsqldb specific encoding used only for log files.
static String unicodeToHexString(String s)
          Converts a Unicode string into UTF8 then convert into a hex string
static int writeUTF(String str, OutputStream out)
          Writes a string to the specified DataOutput using UTF-8 encoding in a machine-independent manner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringConverter

public StringConverter()
Method Detail

hexToByte

public static byte[] hexToByte(String s)
                        throws IOException
Compacts a hexadecimal string into a byte array

Parameters:
s - hexadecimal string
Returns:
byte array for the hex string
Throws:
IOException

byteToHex

public static String byteToHex(byte[] b)
Converts a byte array into a hexadecimal string

Parameters:
b - byte array
Returns:
hex string

byteToString

public static String byteToString(byte[] b,
                                  String charset)

unicodeToHexString

public static String unicodeToHexString(String s)
Converts a Unicode string into UTF8 then convert into a hex string

Parameters:
s - normal Unicode string
Returns:
hex string representation of UTF8 encoding of the input

hexStringToUnicode

public static String hexStringToUnicode(String s)
                                 throws IOException
Converts a hex string into a byte array then converts the byte array into a Unicode string.

Parameters:
s -
Returns:
Throws:
IOException

unicodeToAscii

public static int unicodeToAscii(OutputStream b,
                                 String s,
                                 boolean doubleSingleQuotes)
                          throws IOException
Hsqldb specific encoding used only for log files. The SQL statements that need to be written to the log file (input) are Java Unicode strings. input is converted into a 7bit escaped ASCII string (output)with the following transformations. All characters outside the 0x20-7f range are converted to a escape sequence and added to output. If a backslash character is immdediately followed by 'u', the backslash character is converted to escape sequence and added to output. All the remaining characters in input are added to output without conversion. The escape sequence is backslash, letter u, xxxx, where xxxx is the hex representation of the character code. (fredt@users)

Parameters:
b - output stream to wite to
s - Java Unicode string
Returns:
number of bytes written out
Throws:
IOException

asciiToUnicode

public static String asciiToUnicode(byte[] s,
                                    int offset,
                                    int length)
Hsqldb specific decoding used only for log files. This method converts the 7 bit escaped ASCII strings in a log file back into Java Unicode strings. See unicodeToAccii() above,

Parameters:
s - encoded ASCII string in byte array
offset - position of first byte
length - number of bytes to use
Returns:
Java Unicode string

asciiToUnicode

public static String asciiToUnicode(String s)

readUTF

public static String readUTF(byte[] bytearr,
                             int offset,
                             int length)
                      throws IOException
Throws:
IOException

writeUTF

public static int writeUTF(String str,
                           OutputStream out)
                    throws IOException
Writes a string to the specified DataOutput using UTF-8 encoding in a machine-independent manner.

Parameters:
str - a string to be written.
out - destination to write to
Returns:
The number of bytes written out.
Throws:
IOException - if an I/O error occurs.

getUTFSize

public static int getUTFSize(String s)

inputStreamToString

public static String inputStreamToString(InputStream x)
                                  throws IOException
Using a Reader and a Writer, returns a String from an InputStream

Throws:
IOException

toQuotedString

public static String toQuotedString(String s,
                                    char quoteChar,
                                    boolean extraQuote)
Returns the quoted version of the string using the quotechar argument. doublequote argument indicates whether each instance of quotechar inside the string is doubled.

null string argument returns null. If the caller needs the literal "NULL" it should created it itself

The reverse conversion is handled in Tokenizer.java



Copyright © 2001 - 2004 HSQL Development Group. All Rights Reserved.