Module org.hsqldb

Class StringConverter

java.lang.Object
org.hsqldb.lib.StringConverter

public class StringConverter extends Object
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 Details

    • StringConverter

      public StringConverter()
  • Method Details

    • hexStringToByteArray

      public static byte[] hexStringToByteArray(String s) throws IOException
      Converts a hexadecimal string into a byte array
      Parameters:
      s - hexadecimal string
      Returns:
      byte array for the hex string
      Throws:
      IOException - on error
    • sqlBitStringToBitMap

      public static org.hsqldb.map.BitMap sqlBitStringToBitMap(String s) throws IOException
      Compacts a bit string into a BitMap
      Parameters:
      s - bit string
      Returns:
      BitMap for the bit string
      Throws:
      IOException - on error
    • byteArrayToHexString

      public static String byteArrayToHexString(byte[] b)
      Converts a byte array into a hexadecimal string
      Parameters:
      b - byte array
      Returns:
      hex string
    • byteArrayToSQLHexString

      public static String byteArrayToSQLHexString(byte[] b)
      Converts a byte array into an SQL hexadecimal string
      Parameters:
      b - byte array
      Returns:
      hex string
    • byteArrayToBitString

      public static String byteArrayToBitString(byte[] bytes, int bitCount)
      Converts a byte array into a bit string
      Parameters:
      bytes - byte array
      bitCount - number of bits
      Returns:
      hex string
    • byteArrayToSQLBitString

      public static String byteArrayToSQLBitString(byte[] bytes, int bitCount)
      Converts a byte array into an SQL binary string
      Parameters:
      bytes - byte array
      bitCount - 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 array
      from - offset into output array
      b - input array
      Returns:
      written count
    • byteArrayToString

      public static String byteArrayToString(byte[] b, String charset)
    • 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 a 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 to
      s - Java string
      doubleSingleQuotes - boolean
    • unicodeStringToString

      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 - encoded ASCII string in byte array
      Returns:
      Java string
    • readUTF

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

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

      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 - a string to be written.
      out - destination to write to
      Returns:
      The number of bytes written out.
    • getUTFSize

      public static int getUTFSize(String s)
    • inputStreamToString

      public static String inputStreamToString(InputStream is, String encoding) throws IOException
      Using an output stream, returns a String from an InputStream.
      Parameters:
      is - InputStream to read from
      encoding - character encoding of the string
      Returns:
      a Java string
      Throws:
      IOException - on error
    • 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

      Parameters:
      s - Java string
      quoteChar - character used for quoting
      extraQuote - true if quoteChar itself should be repeated
      Returns:
      String
    • stringToHtmlBytes

      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 - the output byte array output stream
      s - the input string
    • toStringUUID

      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 - the byte array
      Returns:
      UUID string form
    • writeUUIDHexBytes

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

      public static byte[] toBinaryUUID(String s)
      Returns a byte[] representation in UUID form from a UUID string.
      Parameters:
      s - the UUID string
      Returns:
      byte array
    • stringToUnicodeEscaped

      public static String stringToUnicodeEscaped(String s)
    • unicodeEscapedToString

      public static String unicodeEscapedToString(String s) throws IOException
      Throws:
      IOException
    • toJSONString

      public static void toJSONString(String s, StringBuilder sb)