public class Utils extends Object
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
encodeUTF8(String str)
Encode a string as UTF-8.
|
static StringBuilder |
escapeIdentifier(StringBuilder sbuf,
String value)
Escape the given identifier
value and append it to the string builder sbuf. |
static StringBuilder |
escapeLiteral(StringBuilder sbuf,
String value,
boolean standardConformingStrings) |
static StringBuilder |
escapeLiteral(StringBuilder sbuf,
String value,
boolean standardConformingStrings,
boolean onlyQuotes)
Escape the given literal
value and append it to the string builder sbuf. |
static boolean |
isNullOrEmpty(String value) |
static JsonNode |
parseJson(String json)
Parses a JSON string into a JsonNode object.
|
static int |
parseServerVersionStr(String serverVersion)
Deprecated.
use specific
Version instance |
static String |
toHexString(byte[] data)
Turn a bytearray into a printable form, representing each byte in hex.
|
public static String toHexString(byte[] data)
data - the bytearray to stringizedatapublic static byte[] encodeUTF8(String str)
str - the string to encodestrpublic static StringBuilder escapeLiteral(StringBuilder sbuf, String value, boolean standardConformingStrings, boolean onlyQuotes) throws 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 nullvalue - the string valuestandardConformingStrings - if standard conforming strings should be usedonlyQuotes - only escape quote and not the backslash for database nameSQLException - if the string contains a \0 characterpublic static StringBuilder escapeLiteral(StringBuilder sbuf, String value, boolean standardConformingStrings) throws SQLException
SQLExceptionpublic static StringBuilder escapeIdentifier(StringBuilder sbuf, String value) throws 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 nullvalue - the string valueSQLException - if the string contains a \0 character@Deprecated public static int parseServerVersionStr(String serverVersion) throws 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 formNumberFormatExceptionpublic static boolean isNullOrEmpty(String value)
public static JsonNode parseJson(String json) throws JsonProcessingException
json - The JSON string to be parsed. Must be a valid JSON format.
Can represent an object, array, or primitive JSON value.JsonProcessingException - if the input string is not valid JSON,
or if there are any other problems parsing the JSON content.IllegalArgumentException - if the input string is null.com.fasterxml.jackson.databind.JsonNode,
Example usage:
String jsonString = "{\"name\":\"John\",\"age\":30}";
JsonNode node = JsonUtil.parseJson(jsonString);
String name = node.get("name").asText();
Copyright © 2025 Amazon.com Inc.. All rights reserved.