|
@@ -22,7 +22,7 @@ |
|
|
* Turn a bytearray into a printable form, representing each byte in hex. |
|
|
* |
|
|
* @param data the bytearray to stringize |
|
|
* @return a hex-encoded printable representation of <code>data</code> |
|
|
* @return a hex-encoded printable representation of {@code data} |
|
|
*/ |
|
|
public static String toHexString(byte[] data) { |
|
|
StringBuilder sb = new StringBuilder(data.length * 2); |
|
@@ -43,7 +43,7 @@ public static String toHexString(byte[] data) { |
|
|
* Encode a string as UTF-8. |
|
|
* |
|
|
* @param str the string to encode |
|
|
* @return the UTF-8 representation of <code>str</code> |
|
|
* @return the UTF-8 representation of {@code str} |
|
|
*/ |
|
|
public static byte[] encodeUTF8(String str) { |
|
|
// See org.postgresql.benchmark.encoding.UTF8Encoding#string_getBytes |
|
@@ -53,28 +53,6 @@ public static String toHexString(byte[] data) { |
|
|
return str.getBytes(utf8Charset); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Escape the given literal <tt>value</tt> and append it to the string buffer <tt>sbuf</tt>. If |
|
|
* <tt>sbuf</tt> is <tt>null</tt>, a new StringBuffer will be returned. The argument |
|
|
* <tt>standardConformingStrings</tt> defines whether the backend expects standard-conforming |
|
|
* string literals or allows backslash escape sequences. |
|
|
* |
|
|
* @param sbuf the string buffer to append to; or <tt>null</tt> |
|
|
* @param value the string value |
|
|
* @param standardConformingStrings if standard conforming strings should be used |
|
|
* @return the sbuf argument; or a new string buffer for sbuf == null |
|
|
* @throws SQLException if the string contains a <tt>\0</tt> character |
|
|
* @deprecated use {@link #escapeLiteral(StringBuilder, String, boolean)} instead |
|
|
*/ |
|
|
public static StringBuffer appendEscapedLiteral(StringBuffer sbuf, String value, |
|
|
boolean standardConformingStrings) throws SQLException { |
|
|
if (sbuf == null) { |
|
|
sbuf = new StringBuffer(value.length() * 11 / 10); // Add 10% for escaping. |
|
|
} |
|
|
doAppendEscapedLiteral(sbuf, value, standardConformingStrings); |
|
|
return sbuf; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Escape the given literal <tt>value</tt> and append it to the string builder <tt>sbuf</tt>. If |
|
|
* <tt>sbuf</tt> is <tt>null</tt>, a new StringBuilder will be returned. The argument |
|
@@ -97,8 +75,7 @@ public static StringBuilder escapeLiteral(StringBuilder sbuf, String value, |
|
|
} |
|
|
|
|
|
/** |
|
|
* Common part for {@link #appendEscapedLiteral(StringBuffer, String, boolean)} and |
|
|
* {@link #escapeLiteral(StringBuilder, String, boolean)} |
|
|
* Common part for {@link #escapeLiteral(StringBuilder, String, boolean)} |
|
|
* |
|
|
* @param sbuf Either StringBuffer or StringBuilder as we do not expect any IOException to be |
|
|
* thrown |
|
@@ -145,27 +122,6 @@ private static void doAppendEscapedLiteral(Appendable sbuf, String value, |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Escape the given identifier <tt>value</tt> and append it to the string buffer <tt>sbuf</tt>. If |
|
|
* <tt>sbuf</tt> is <tt>null</tt>, a new StringBuffer will be returned. This method is different |
|
|
* from appendEscapedLiteral in that it includes the quoting required for the identifier while |
|
|
* appendEscapedLiteral does not. |
|
|
* |
|
|
* @param sbuf the string buffer to append to; or <tt>null</tt> |
|
|
* @param value the string value |
|
|
* @return the sbuf argument; or a new string buffer for sbuf == null |
|
|
* @throws SQLException if the string contains a <tt>\0</tt> character |
|
|
* @deprecated use {@link #escapeIdentifier(StringBuilder, String)} instead |
|
|
*/ |
|
|
public static StringBuffer appendEscapedIdentifier(StringBuffer sbuf, String value) |
|
|
throws SQLException { |
|
|
if (sbuf == null) { |
|
|
sbuf = new StringBuffer(2 + value.length() * 11 / 10); // Add 10% for escaping. |
|
|
} |
|
|
doAppendEscapedIdentifier(sbuf, value); |
|
|
return sbuf; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Escape the given identifier <tt>value</tt> and append it to the string builder <tt>sbuf</tt>. |
|
|
* If <tt>sbuf</tt> is <tt>null</tt>, a new StringBuilder will be returned. This method is |
|
|