Top Description Fields Constructors Methods
org.hsqldb.lib

public Class StringConverter

extends Object
Class Inheritance
Imports
java.io.IOException, .InputStream, .UTFDataFormatException, org.hsqldb.map.BitMap

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

Includes two methods based on Hypersonic code as indicated.

Authors
Thomas Mueller (Hypersonic SQL Group), Fred Toussi (fredt@users dot sourceforge.net)
Since
1.7.2
Version
2.7.3

Field Summary

Modifier and TypeField and Description
private static final byte[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
pack-priv static void
public static String

Returns:

hex string
byteArrayToBitString
(byte[]
byte array
bytes
,
int
number of bits
bitCount
)

Converts a byte array into a bit string

public static String

Returns:

hex string
byteArrayToHexString
(byte[]
byte array
b
)

Converts a byte array into a hexadecimal string

public static String

Returns:

hex string
byteArrayToSQLBitString
(byte[]
byte array
bytes
,
int
number of bits
bitCount
)

Converts a byte array into an SQL binary string

public static String

Returns:

hex string
byteArrayToSQLHexString
(byte[]
byte array
b
)

Converts a byte array into an SQL hexadecimal string

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

pack-priv static int

Returns:

int count
count
(final String
Java string
s
,
final char
character to count
c
)

Counts Character c in String s

private static int
getNibble(int value)

public static int
public static byte[]

Returns:

byte array for the hex string
hexStringToByteArray
(String
hexadecimal string
s
)

Converts a hexadecimal string into a byte array

public static String

Returns:

a Java string
inputStreamToString
(InputStream
InputStream to read from
is
,
String
character encoding of the string
encoding
)

Using an output stream, returns a String from an InputStream.

public static String
readUTF(byte[] bytearr, int offset, int length)

public static String
readUTF(byte[] bytearr, int offset, int length, char[] buf)

public static BitMap

Returns:

BitMap for the bit string
sqlBitStringToBitMap
(String
bit string
s
)

Compacts a bit string into a BitMap

public static void
stringToHtmlBytes(HsqlByteArrayOutputStream
the output byte array output stream
b
,
String
the input string
s
)

Converts the string to an HTML representation in the ASCII character set and appends it to a byte array output stream.

public static void
stringToUnicodeBytes(HsqlByteArrayOutputStream
output stream to wite to
b
,
String
Java string
s
,
boolean
boolean
doubleSingleQuotes
)

Hsqldb specific encoding used only for log files.

public static String
public static int

Returns:

The number of bytes written out.
stringToUTFBytes
(String
a string to be written.
str
,
HsqlByteArrayOutputStream
destination to write to
out
)

Writes a string to the specified DataOutput using UTF-8 encoding in a machine-independent manner.

public static byte[]

Returns:

byte array
toBinaryUUID
(String
the UUID string
s
)

Returns a byte[] representation in UUID form from a UUID string.

public static void
public static String

Returns:

String
toQuotedString
(String
Java string
s
,
char
character used for quoting
quoteChar
,
boolean
true if quoteChar itself should be repeated
extraQuote
)

Returns the quoted version of the string using the quotechar argument.

public static String

Returns:

UUID string form
toStringUUID
(byte[]
the byte array
b
)

Returns a string representation in UUID form from a binary string.

public static String
public static String

Returns:

Java string
unicodeStringToString
(String
encoded ASCII string in byte array
s
)

Hsqldb specific decoding used only for log files.

public static int

Returns:

written count
writeHexBytes
(byte[]
output array
o
,
final int
offset into output array
from
,
byte[]
input array
b
)

Converts a byte array into hexadecimal characters which are written as ASCII to the given output stream.

public static int
writeUUIDHexBytes(byte[] o, final int from, byte[] b)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEXBYTESback to summary
private static final byte[] HEXBYTES

Constructor Detail

StringConverterback to summary
public StringConverter()

Method Detail

appendHexback to summary
pack-priv static void appendHex(StringBuilder b, char c)
byteArrayToBitStringback to summary
public static String byteArrayToBitString(byte[] bytes, int bitCount)

Converts a byte array into a bit string

Parameters
bytes:byte[]

byte array

bitCount:int

number of bits

Returns:String

hex string

byteArrayToHexStringback to summary
public static String byteArrayToHexString(byte[] b)

Converts a byte array into a hexadecimal string

Parameters
b:byte[]

byte array

Returns:String

hex string

byteArrayToSQLBitStringback to summary
public static String byteArrayToSQLBitString(byte[] bytes, int bitCount)

Converts a byte array into an SQL binary string

Parameters
bytes:byte[]

byte array

bitCount:int

number of bits

Returns:String

hex string

byteArrayToSQLHexStringback to summary
public static String byteArrayToSQLHexString(byte[] b)

Converts a byte array into an SQL hexadecimal string

Parameters
b:byte[]

byte array

Returns:String

hex string

byteArrayToStringback to summary
public static String byteArrayToString(byte[] b, String charset)
countback to summary
pack-priv static int count(final String s, final char c)

Counts Character c in String s

Parameters
s:String

Java string

c:char

character to count

Returns:int

int count

getNibbleback to summary
private static int getNibble(int value)
getUTFSizeback to summary
public static int getUTFSize(String s)
hexStringToByteArrayback to summary
public static byte[] hexStringToByteArray(String s) throws IOException

Converts a hexadecimal string into a byte array

Parameters
s:String

hexadecimal string

Returns:byte[]

byte array for the hex string

Exceptions
IOException:
on error
inputStreamToStringback to summary
public static String inputStreamToString(InputStream is, String encoding) throws IOException

Using an output stream, returns a String from an InputStream.

Parameters
is:InputStream

InputStream to read from

encoding:String

character encoding of the string

Returns:String

a Java string

Exceptions
IOException:
on error
readUTFback to summary
public static String readUTF(byte[] bytearr, int offset, int length) throws IOException
readUTFback to summary
public static String readUTF(byte[] bytearr, int offset, int length, char[] buf) throws IOException
sqlBitStringToBitMapback to summary
public static BitMap sqlBitStringToBitMap(String s) throws IOException

Compacts a bit string into a BitMap

Parameters
s:String

bit string

Returns:BitMap

BitMap for the bit string

Exceptions
IOException:
on error
stringToHtmlBytesback to summary
public static void stringToHtmlBytes(HsqlByteArrayOutputStream b, String s)

Converts the string to an HTML representation in the ASCII character set and appends it to a byte array output stream.

Parameters
b:HsqlByteArrayOutputStream

the output byte array output stream

s:String

the input string

stringToUnicodeBytesback to summary
public static void stringToUnicodeBytes(HsqlByteArrayOutputStream b, String s, boolean doubleSingleQuotes)

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 an escape sequence and added to output. If a backslash character is immediately 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)

Method based on Hypersonic Code

Parameters
b:HsqlByteArrayOutputStream

output stream to wite to

s:String

Java string

doubleSingleQuotes:boolean

boolean

stringToUnicodeEscapedback to summary
public static String stringToUnicodeEscaped(String s)
stringToUTFBytesback to summary
public static int stringToUTFBytes(String str, HsqlByteArrayOutputStream out)

Writes a string to the specified DataOutput using UTF-8 encoding in a machine-independent manner.

Parameters
str:String

a string to be written.

out:HsqlByteArrayOutputStream

destination to write to

Returns:int

The number of bytes written out.

toBinaryUUIDback to summary
public static byte[] toBinaryUUID(String s)

Returns a byte[] representation in UUID form from a UUID string.

Parameters
s:String

the UUID string

Returns:byte[]

byte array

toJSONStringback to summary
public static void toJSONString(String s, StringBuilder sb)
toQuotedStringback to summary
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 be created it itself

Parameters
s:String

Java string

quoteChar:char

character used for quoting

extraQuote:boolean

true if quoteChar itself should be repeated

Returns:String

String

toStringUUIDback to summary
public static String toStringUUID(byte[] b)

Returns a string representation in UUID form from a binary string. UUID string is composed of 8-4-4-4-12 hexadecimal characters.

Parameters
b:byte[]

the byte array

Returns:String

UUID string form

unicodeEscapedToStringback to summary
public static String unicodeEscapedToString(String s) throws IOException
unicodeStringToStringback to summary
public static String unicodeStringToString(String s)

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 stringToUnicodeBytes() above.

Method based on Hypersonic Code

Parameters
s:String

encoded ASCII string in byte array

Returns:String

Java string

writeHexBytesback to summary
public static int writeHexBytes(byte[] o, final int from, byte[] b)

Converts a byte array into hexadecimal characters which are written as ASCII to the given output stream.

Parameters
o:byte[]

output array

from:int

offset into output array

b:byte[]

input array

Returns:int

written count

writeUUIDHexBytesback to summary
public static int writeUUIDHexBytes(byte[] o, final int from, byte[] b)