diff a/test/lib/jdk/test/lib/Utils.java b/test/lib/jdk/test/lib/Utils.java --- a/test/lib/jdk/test/lib/Utils.java +++ b/test/lib/jdk/test/lib/Utils.java @@ -42,10 +42,11 @@ import java.nio.channels.SocketChannel; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Hex; import java.util.Iterator; import java.util.Map; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -486,44 +487,31 @@ Path filePath = Paths.get(filename); if (!Files.exists(filePath)) return null; return new String(Files.readAllBytes(filePath)); } - private static final char[] hexArray = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - /** * Returns hex view of byte array * * @param bytes byte array to process * @return space separated hexadecimal string representation of bytes + * @deprecated replaced by {@link java.util.Hex#encoder(CharSequence)} (String) Hex.encoder(" ").encode + * (byte[], char)}. */ + @Deprecated public static String toHexString(byte[] bytes) { - char[] hexView = new char[bytes.length * 3 - 1]; - for (int i = 0; i < bytes.length - 1; i++) { - hexView[i * 3] = hexArray[(bytes[i] >> 4) & 0x0F]; - hexView[i * 3 + 1] = hexArray[bytes[i] & 0x0F]; - hexView[i * 3 + 2] = ' '; - } - hexView[hexView.length - 2] = hexArray[(bytes[bytes.length - 1] >> 4) & 0x0F]; - hexView[hexView.length - 1] = hexArray[bytes[bytes.length - 1] & 0x0F]; - return new String(hexView); + return Hex.encoder(" ", "", "", true).encode(bytes); } /** * Returns byte array of hex view * * @param hex hexadecimal string representation * @return byte array */ public static byte[] toByteArray(String hex) { - int length = hex.length(); - byte[] bytes = new byte[length / 2]; - for (int i = 0; i < length; i += 2) { - bytes[i / 2] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) - + Character.digit(hex.charAt(i + 1), 16)); - } - return bytes; + return Hex.decoder().decode(hex); } /** * Returns {@link java.util.Random} generator initialized with particular seed. * The seed could be provided via system property {@link Utils#SEED_PROPERTY_NAME}