public class Utils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.nio.charset.Charset |
utf8Charset
Keep a local copy of the UTF-8 Charset so we can avoid synchronization overhead from looking up
the Charset by name as String.getBytes(String) requires.
|
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
private static void |
doAppendEscapedIdentifier(java.lang.Appendable sbuf,
java.lang.String value)
Common part for appendEscapedIdentifier.
|
private static void |
doAppendEscapedLiteral(java.lang.Appendable sbuf,
java.lang.String value,
boolean standardConformingStrings)
Common part for
escapeLiteral(StringBuilder, String, boolean) . |
static byte[] |
encodeUTF8(java.lang.String str)
Encode a string as UTF-8.
|
static java.lang.StringBuilder |
escapeIdentifier(java.lang.StringBuilder sbuf,
java.lang.String value)
Escape the given identifier
value and append it to the string builder sbuf . |
static java.lang.StringBuilder |
escapeLiteral(java.lang.StringBuilder sbuf,
java.lang.String value,
boolean standardConformingStrings)
Escape the given literal
value and append it to the string builder sbuf . |
static int |
parseServerVersionStr(java.lang.String serverVersion)
Deprecated.
use specific
Version instance |
static java.lang.String |
toHexString(byte[] data)
Turn a bytearray into a printable form, representing each byte in hex.
|
private static final java.nio.charset.Charset utf8Charset
public static java.lang.String toHexString(byte[] data)
data
- the bytearray to stringizedata
public static byte[] encodeUTF8(java.lang.String str)
str
- the string to encodestr
public static java.lang.StringBuilder escapeLiteral(java.lang.StringBuilder sbuf, java.lang.String value, boolean standardConformingStrings) throws java.sql.SQLException
value
and append it to the string builder sbuf
. If
sbuf
is null
, a new StringBuilder will be returned. The argument
standardConformingStrings
defines whether the backend expects standard-conforming
string literals or allows backslash escape sequences.sbuf
- the string builder to append to; or null
value
- the string valuestandardConformingStrings
- if standard conforming strings should be usedjava.sql.SQLException
- if the string contains a \0
characterprivate static void doAppendEscapedLiteral(java.lang.Appendable sbuf, java.lang.String value, boolean standardConformingStrings) throws java.sql.SQLException
escapeLiteral(StringBuilder, String, boolean)
.sbuf
- Either StringBuffer or StringBuilder as we do not expect any IOException to be
thrownvalue
- value to appendstandardConformingStrings
- if standard conforming strings should be usedjava.sql.SQLException
public static java.lang.StringBuilder escapeIdentifier(java.lang.StringBuilder sbuf, java.lang.String value) throws java.sql.SQLException
value
and append it to the string builder sbuf
.
If sbuf
is null
, a new StringBuilder will be returned. This method is
different from appendEscapedLiteral in that it includes the quoting required for the identifier
while escapeLiteral(StringBuilder, String, boolean)
does not.sbuf
- the string builder to append to; or null
value
- the string valuejava.sql.SQLException
- if the string contains a \0
characterprivate static void doAppendEscapedIdentifier(java.lang.Appendable sbuf, java.lang.String value) throws java.sql.SQLException
sbuf
- Either StringBuffer or StringBuilder as we do not expect any IOException to be
thrown.value
- value to appendjava.sql.SQLException
@Deprecated public static int parseServerVersionStr(java.lang.String serverVersion) throws java.lang.NumberFormatException
Version
instanceAttempt to parse the server version string into an XXYYZZ form version number.
Returns 0 if the version could not be parsed.
Returns minor version 0 if the minor version could not be determined, e.g. devel or beta releases.
If a single major part like 90400 is passed, it's assumed to be a pre-parsed version and returned verbatim. (Anything equal to or greater than 10000 is presumed to be this form).
The yy or zz version parts may be larger than 99. A NumberFormatException is thrown if a version part is out of range.
serverVersion
- server vertion in a XXYYZZ formjava.lang.NumberFormatException