public class Utils extends Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static String |
byteArrayToHexString(byte[] bytes) |
static byte[] |
copyRange(byte[] orig,
int from,
int to)
Copies from original byte array to a new byte array.
|
static byte[] |
copyWithLength(byte[] orig,
int length)
Copies the original byte array content to a new byte array.
|
static Socket |
createSocket(Options options,
String host)
Create socket accordingly to options.
|
static byte[] |
encryptPassword(String password,
byte[] seed,
String passwordCharacterEncoding)
Encrypts a password.
|
static String |
escapeString(String value,
boolean noBackslashEscapes)
Escape String.
|
static TimeZone |
getTimeZone(String id)
Get timezone from Id.
|
static String |
hexdump(byte[]... bytes)
Hexdump.
|
static String |
hexdump(int maxQuerySizeToLog,
int offset,
int length,
byte[]... byteArr)
Hexdump.
|
static String |
intToHexString(int value)
Convert int value to hexadecimal String.
|
static boolean |
isIPv4(String ip) |
static boolean |
isIPv6(String ip) |
static String |
nativeSql(String sql,
Protocol protocol)
Escape sql String.
|
static String |
parseSessionVariables(String sessionVariable)
Parse the option "sessionVariable" to ensure having no injection. semi-column not in string
will be replaced by comma.
|
static Protocol |
retrieveProxy(UrlParser urlParser,
GlobalStateInfo globalInfo)
Retrieve protocol corresponding to the failover options. if no failover option, protocol will
not be proxied. if a failover option is precised, protocol will be proxied so that any
connection error will be handle directly.
|
static Socket |
standardSocket(Options options,
String host)
Use standard socket implementation.
|
static int |
transactionFromString(String txIsolation)
Traduce a String value of transaction isolation to corresponding java value.
|
static boolean |
validateFileName(String sql,
ParameterHolder[] parameters,
String fileName)
Validate that file name correspond to send query.
|
public static Socket standardSocket(Options options, String host) throws IOException
options
- url optionshost
- host to connectIOException
- in case of error establishing socket.public static String escapeString(String value, boolean noBackslashEscapes)
value
- value to escapenoBackslashEscapes
- must backslash be escapedpublic static byte[] encryptPassword(String password, byte[] seed, String passwordCharacterEncoding) throws NoSuchAlgorithmException, UnsupportedEncodingException
protocol for authentication is like this: 1. Server sends a random array of bytes (the seed) 2. client makes a sha1 digest of the password 3. client hashes the output of 2 4. client digests the seed 5. client updates the digest with the output from 3 6. an xor of the output of 5 and 2 is sent to server 7. server does the same thing and verifies that the scrambled passwords match
password
- the password to encryptseed
- the seed to usepasswordCharacterEncoding
- password character encodingNoSuchAlgorithmException
- if SHA1 is not available on the platform we are usingUnsupportedEncodingException
- if passwordCharacterEncoding is not a valid charset namepublic static byte[] copyWithLength(byte[] orig, int length)
orig
- the original byte arraylength
- how big the resulting byte array will bepublic static byte[] copyRange(byte[] orig, int from, int to)
orig
- the original byte arrayfrom
- index of first byte in original byte array which will be copiedto
- index of last byte in original byte array which will be copied. This can be outside
of the original byte arraypublic static String nativeSql(String sql, Protocol protocol) throws SQLException
sql
- initial sqlprotocol
- protocolSQLException
- if escape sequence is incorrect.public static Protocol retrieveProxy(UrlParser urlParser, GlobalStateInfo globalInfo) throws SQLException
urlParser
- urlParser corresponding to connection url string.globalInfo
- global variable informationSQLException
- if any error occur during connectionpublic static TimeZone getTimeZone(String id) throws SQLException
id
- timezone idSQLException
- if no timezone is found for this Idpublic static Socket createSocket(Options options, String host) throws IOException
options
- Url optionshost
- hostName ( mandatory only for named pipe)IOException
- if connection error occurpublic static String hexdump(byte[]... bytes)
bytes
- byte arrayspublic static String hexdump(int maxQuerySizeToLog, int offset, int length, byte[]... byteArr)
String output example :
+--------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------------------------------------------------+------------------+
| 11 00 00 02 00 00 00 02 40 00 00 00 08 01 06 05 | ........@....... |
| 74 65 73 74 6A | testj |
+--------------------------------------------------+------------------+
maxQuerySizeToLog
- max log sizeoffset
- offset of last byte arraylength
- length of last byte arraybyteArr
- byte arrays. if many, only the last may have offset and size limitation others
will be displayed completely.public static String byteArrayToHexString(byte[] bytes)
public static String intToHexString(int value)
value
- value to transformpublic static String parseSessionVariables(String sessionVariable)
sessionVariable
- option valuepublic static boolean isIPv4(String ip)
public static boolean isIPv6(String ip)
public static int transactionFromString(String txIsolation) throws SQLException
txIsolation
- String valueSQLException
- if String value doesn't correspond
to @@tx_isolation/@@transaction_isolation possible valuepublic static boolean validateFileName(String sql, ParameterHolder[] parameters, String fileName)
sql
- sql commandparameters
- sql parameterfileName
- server file nameCopyright © 2020 mariadb.com. All rights reserved.