Class Utils
java.lang.Object
org.mariadb.jdbc.internal.util.Utils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteArrayToHexString(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 SocketcreateSocket(Options options, String host) Create socket accordingly to options.static byte[]encryptPassword(String password, byte[] seed, String passwordCharacterEncoding) Encrypts a password.static StringescapeString(String value, boolean noBackslashEscapes) Escape String.static TimeZonegetTimeZone(String id) Get timezone from Id.static Stringhexdump(byte[]... bytes) Hexdump.static Stringhexdump(int maxQuerySizeToLog, int offset, int length, byte[]... byteArr) Hexdump.static booleanstatic booleanstatic StringEscape sql String.static StringparseSessionVariables(String sessionVariable) Parse the option "sessionVariable" to ensure having no injection.static ProtocolretrieveProxy(UrlParser urlParser, GlobalStateInfo globalInfo) Retrieve protocol corresponding to the failover options.static SocketstandardSocket(Options options, String host) Use standard socket implementation.static inttransactionFromString(String txIsolation) Traduce a String value of transaction isolation to corresponding java value.static booleanvalidateFileName(String sql, ParameterHolder[] parameters, String fileName) Validate that file name correspond to send query.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
standardSocket
Use standard socket implementation.- Parameters:
options- url optionshost- host to connect- Returns:
- socket
- Throws:
IOException- in case of error establishing socket.
-
escapeString
-
encryptPassword
public static byte[] encryptPassword(String password, byte[] seed, String passwordCharacterEncoding) throws NoSuchAlgorithmException, UnsupportedEncodingException Encrypts a password.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
- Parameters:
password- the password to encryptseed- the seed to usepasswordCharacterEncoding- password character encoding- Returns:
- a scrambled password
- Throws:
NoSuchAlgorithmException- if SHA1 is not available on the platform we are usingUnsupportedEncodingException- if passwordCharacterEncoding is not a valid charset name
-
copyWithLength
public static byte[] copyWithLength(byte[] orig, int length) Copies the original byte array content to a new byte array. The resulting byte array is always "length" size. If length is smaller than the original byte array, the resulting byte array is truncated. If length is bigger than the original byte array, the resulting byte array is filled with zero bytes.- Parameters:
orig- the original byte arraylength- how big the resulting byte array will be- Returns:
- the copied byte array
-
copyRange
public static byte[] copyRange(byte[] orig, int from, int to) Copies from original byte array to a new byte array. The resulting byte array is always "to-from" size.- Parameters:
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 array- Returns:
- resulting array
-
nativeSql
Escape sql String.- Parameters:
sql- initial sqlprotocol- protocol- Returns:
- escaped sql string
- Throws:
SQLException- if escape sequence is incorrect.
-
retrieveProxy
public static Protocol retrieveProxy(UrlParser urlParser, GlobalStateInfo globalInfo) throws SQLException 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.- Parameters:
urlParser- urlParser corresponding to connection url string.globalInfo- global variable information- Returns:
- protocol
- Throws:
SQLException- if any error occur during connection
-
getTimeZone
Get timezone from Id. This differ from java implementation : by default, if timezone Id is unknown, java return GMT timezone. GMT will be return only if explicitly asked.- Parameters:
id- timezone id- Returns:
- timezone.
- Throws:
SQLException- if no timezone is found for this Id
-
createSocket
Create socket accordingly to options.- Parameters:
options- Url optionshost- hostName ( mandatory only for named pipe)- Returns:
- a nex socket
- Throws:
IOException- if connection error occur
-
hexdump
Hexdump.- Parameters:
bytes- byte arrays- Returns:
- String
-
hexdump
Hexdump. Multiple byte arrays will be combinedString 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 | +--------------------------------------------------+------------------+- Parameters:
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.- Returns:
- String
-
byteArrayToHexString
-
parseSessionVariables
-
isIPv4
-
isIPv6
-
transactionFromString
Traduce a String value of transaction isolation to corresponding java value.- Parameters:
txIsolation- String value- Returns:
- java corresponding value (Connection.TRANSACTION_READ_UNCOMMITTED, Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_REPEATABLE_READ or Connection.TRANSACTION_SERIALIZABLE)
- Throws:
SQLException- if String value doesn't correspond to @@tx_isolation/@@transaction_isolation possible value
-
validateFileName
Validate that file name correspond to send query.- Parameters:
sql- sql commandparameters- sql parameterfileName- server file name- Returns:
- true if correspond
-