Class StringConverter
java.lang.Object
org.hsqldb.lib.StringConverter
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.
- Since:
- 1.7.2
- Author:
- Thomas Mueller (Hypersonic SQL Group), Fred Toussi (fredt@users dot sourceforge.net)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteArrayToBitString(byte[] bytes, int bitCount) Converts a byte array into a bit stringstatic StringbyteArrayToHexString(byte[] b) Converts a byte array into a hexadecimal stringstatic StringbyteArrayToSQLBitString(byte[] bytes, int bitCount) Converts a byte array into an SQL binary stringstatic StringbyteArrayToSQLHexString(byte[] b) Converts a byte array into an SQL hexadecimal stringstatic StringbyteArrayToString(byte[] b, String charset) static intgetUTFSize(String s) static byte[]Converts a hexadecimal string into a byte arraystatic StringinputStreamToString(InputStream is, String encoding) Using an output stream, returns a String from an InputStream.static StringreadUTF(byte[] bytearr, int offset, int length) static StringreadUTF(byte[] bytearr, int offset, int length, char[] buf) static org.hsqldb.map.BitMapCompacts a bit string into a BitMapstatic voidConverts the string to an HTML representation in the ASCII character set and appends it to a byte array output stream.static voidstringToUnicodeBytes(HsqlByteArrayOutputStream b, String s, boolean doubleSingleQuotes) Hsqldb specific encoding used only for log files.static Stringstatic intstringToUTFBytes(String str, HsqlByteArrayOutputStream out) Writes a string to the specified DataOutput using UTF-8 encoding in a machine-independent manner.static byte[]Returns a byte[] representation in UUID form from a UUID string.static voidtoJSONString(String s, StringBuilder sb) static StringtoQuotedString(String s, char quoteChar, boolean extraQuote) Returns the quoted version of the string using the quotechar argument.static StringtoStringUUID(byte[] b) Returns a string representation in UUID form from a binary string.static Stringstatic StringHsqldb specific decoding used only for log files.static intwriteHexBytes(byte[] o, int from, byte[] b) Converts a byte array into hexadecimal characters which are written as ASCII to the given output stream.static intwriteUUIDHexBytes(byte[] o, int from, byte[] b)
-
Constructor Details
-
StringConverter
public StringConverter()
-
-
Method Details
-
hexStringToByteArray
Converts a hexadecimal string into a byte array- Parameters:
s- hexadecimal string- Returns:
- byte array for the hex string
- Throws:
IOException- on error
-
sqlBitStringToBitMap
Compacts a bit string into a BitMap- Parameters:
s- bit string- Returns:
- BitMap for the bit string
- Throws:
IOException- on error
-
byteArrayToHexString
Converts a byte array into a hexadecimal string- Parameters:
b- byte array- Returns:
- hex string
-
byteArrayToSQLHexString
Converts a byte array into an SQL hexadecimal string- Parameters:
b- byte array- Returns:
- hex string
-
byteArrayToBitString
Converts a byte array into a bit string- Parameters:
bytes- byte arraybitCount- number of bits- Returns:
- hex string
-
byteArrayToSQLBitString
Converts a byte array into an SQL binary string- Parameters:
bytes- byte arraybitCount- number of bits- Returns:
- hex string
-
writeHexBytes
public static int writeHexBytes(byte[] o, int from, byte[] b) Converts a byte array into hexadecimal characters which are written as ASCII to the given output stream.- Parameters:
o- output arrayfrom- offset into output arrayb- input array- Returns:
- written count
-
byteArrayToString
-
stringToUnicodeBytes
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- output stream to wite tos- Java stringdoubleSingleQuotes- boolean
-
unicodeStringToString
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- encoded ASCII string in byte array- Returns:
- Java string
-
readUTF
- Throws:
IOException
-
readUTF
- Throws:
IOException
-
stringToUTFBytes
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.
-
getUTFSize
-
inputStreamToString
Using an output stream, returns a String from an InputStream.- Parameters:
is- InputStream to read fromencoding- character encoding of the string- Returns:
- a Java string
- Throws:
IOException- on error
-
toQuotedString
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- Java stringquoteChar- character used for quotingextraQuote- true if quoteChar itself should be repeated- Returns:
- String
-
stringToHtmlBytes
Converts the string to an HTML representation in the ASCII character set and appends it to a byte array output stream.- Parameters:
b- the output byte array output streams- the input string
-
toStringUUID
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- the byte array- Returns:
- UUID string form
-
writeUUIDHexBytes
public static int writeUUIDHexBytes(byte[] o, int from, byte[] b) -
toBinaryUUID
Returns a byte[] representation in UUID form from a UUID string.- Parameters:
s- the UUID string- Returns:
- byte array
-
stringToUnicodeEscaped
-
unicodeEscapedToString
- Throws:
IOException
-
toJSONString
-