public class Utils extends Object
| Constructor and Description |
|---|
Utils() |
| Modifier and Type | Method and Description |
|---|---|
static byte |
byteArrayToByte(byte[] b) |
static int |
byteArrayToInt(byte[] b)
convert a byte array to an int
sums negative numbers since Integer.MIN_VALUE < -Integer.MAX_VALUE
|
static long |
byteArrayToLong(byte[] b) |
static short |
byteArrayToShort(byte[] b) |
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 int |
countChars(String str,
char chr)
Counts the number of occurrences of a character in a string.
|
static List<String> |
createQueryParts(String query) |
static byte[] |
encryptPassword(String password,
byte[] seed)
encrypts a password
protocol for authentication is like this: 1.
|
static boolean |
isJava5()
Returns if it is a Java version up to Java 5.
|
static boolean |
needsEscaping(byte b)
returns true if the byte b needs to be escaped
|
static int |
packTime(long milliseconds)
packs the time portion of a millisecond time stamp into an int
format:
|
static String |
sqlEscapeString(String str)
escapes the given string, new string length is at most twice the length of str
|
static String |
stripQuery(String query) |
static long |
unpackTime(int packedTime)
unpacks an integer packed by packTime
|
public static boolean needsEscaping(byte b)
b - the byte to checkpublic static String sqlEscapeString(String str)
str - the string to escapepublic static int countChars(String str, char chr)
str - the string to checkchr - the character to countpublic static byte[] encryptPassword(String password, byte[] seed) throws NoSuchAlgorithmException
password - the password to encryptseed - the seed to useNoSuchAlgorithmException - if SHA1 is not available on the platform we are usingpublic static int packTime(long milliseconds)
The part of the day, stored in a 4 byte integer as follows: | 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | | mS | mS | mS | mS | mS | mS | mS | mS | | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | | mS | mS | mS | mS | mS | mS | mS | SS | | 15 | 14 | 13 | 12 | 11 | 10 | 09 | 08 | | SS | SS | SS | SS | SS | MM | MM | MM | | 07 | 06 | 05 | 04 | 03 | 02 | 01 | 00 | | MM | MM | MM | HH | HH | HH | HH | HH |
milliseconds - the milliseconds to packpublic static long unpackTime(int packedTime)
packedTime - the packed timepackTime(long)public 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 boolean isJava5()
public static short byteArrayToShort(byte[] b)
public static byte byteArrayToByte(byte[] b)
public static int byteArrayToInt(byte[] b)
b - public static long byteArrayToLong(byte[] b)
Copyright © 2016. All rights reserved.