Skip to content

Commit 1c33aaf

Browse files
committed
Remove unused method, and replace hex parsing with HexFormat
1 parent bb4b1fd commit 1c33aaf

File tree

1 file changed

+8
-57
lines changed

1 file changed

+8
-57
lines changed
Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,30 @@
11
package org.firebirdsql.decimal.util;
22

3+
import java.util.HexFormat;
4+
35
/**
46
* Helper methods for byte arrays.
57
*
6-
* @author <a href="mailto:mrotteveel@users.sourceforge.net">Mark Rotteveel</a>
7-
* @since 3.0
8+
* @author Mark Rotteveel
89
*/
910
public final class ByteArrayHelper {
1011

11-
//@formatter:off
12-
private static final char[] BYTE_2_HEX=(
13-
"000102030405060708090A0B0C0D0E0F"+
14-
"101112131415161718191A1B1C1D1E1F"+
15-
"202122232425262728292A2B2C2D2E2F"+
16-
"303132333435363738393A3B3C3D3E3F"+
17-
"404142434445464748494A4B4C4D4E4F"+
18-
"505152535455565758595A5B5C5D5E5F"+
19-
"606162636465666768696A6B6C6D6E6F"+
20-
"707172737475767778797A7B7C7D7E7F"+
21-
"808182838485868788898A8B8C8D8E8F"+
22-
"909192939495969798999A9B9C9D9E9F"+
23-
"A0A1A2A3A4A5A6A7A8A9AAABACADAEAF"+
24-
"B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF"+
25-
"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF"+
26-
"D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF"+
27-
"E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF"+
28-
"F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF").toCharArray();
29-
//@formatter:on
30-
3112
private ByteArrayHelper() {
3213
// no instances
3314
}
3415

35-
/**
36-
* Converts the provided byte array to a hexadecimal string
37-
* <p>
38-
* Adapted from http://stackoverflow.com/a/21429909/466862 by <a href="http://stackoverflow.com/users/1182868/higginse">higginse</a>
39-
* </p>
40-
*
41-
* @param bytes byte array (not {@code null}
42-
* @return String with the content of the byte array in hexadecimal.
43-
*/
44-
public static String toHexString(byte[] bytes) {
45-
final int length = bytes.length;
46-
final char[] chars = new char[length << 1];
47-
final char[] byte2Hex = BYTE_2_HEX;
48-
int index = 0;
49-
int offset = 0;
50-
while (offset < length) {
51-
int hexIndex = (bytes[offset++] & 0xFF) << 1;
52-
chars[index++] = byte2Hex[hexIndex++];
53-
chars[index++] = byte2Hex[hexIndex];
54-
}
55-
return new String(chars);
56-
}
57-
5816
/**
5917
* Converts a hexadecimal string to a byte array.
60-
* <p>
61-
* Adapted from https://stackoverflow.com/a/140861/466862 by <a href="https://stackoverflow.com/users/3093/dave-l">Dave L.</a>
62-
* </p>
6318
*
64-
* @param hexString Hexadecimal string
65-
* @return byte array
19+
* @param hexString
20+
* Hexadecimal string or {@code null}
21+
* @return byte array, or {@code null} if {@code hexString} is {@code null}
6622
*/
6723
public static byte[] hexToBytes(String hexString) {
6824
if (hexString == null) {
6925
return null;
7026
}
71-
int len = hexString.length();
72-
byte[] data = new byte[len / 2];
73-
for (int i = 0; i < len; i += 2) {
74-
data[i / 2] = (byte) ((Character.digit(hexString.charAt(i), 16) << 4)
75-
+ Character.digit(hexString.charAt(i+1), 16));
76-
}
77-
return data;
27+
return HexFormat.of().parseHex(hexString);
7828
}
29+
7930
}

0 commit comments

Comments
 (0)