Skip to content
Permalink
Browse files
8251989: Hex formatting and parsing utility
Reviewed-by: tvaleev, chegar, naoto, darcy
  • Loading branch information
Roger Riggs committed Dec 16, 2020
1 parent efd61c6 commit aa9c136d67a32cebcdf031f50d8d5cccdd354bed
@@ -264,10 +264,18 @@ public static String toUnsignedString(int i, int radix) {
* <blockquote>
* {@code Integer.toHexString(n).toUpperCase()}
* </blockquote>
* <p>
* @apiNote
* The {@link java.util.HexFormat} class provides formatting and parsing
* of byte arrays and primitives to return a string or adding to an {@link Appendable}.
* {@code HexFormat} formats and parses uppercase or lowercase hexadecimal characters,
* with leading zeros and for byte arrays includes for each byte
* a delimiter, prefix, and suffix.
*
* @param i an integer to be converted to a string.
* @return the string representation of the unsigned integer value
* represented by the argument in hexadecimal (base&nbsp;16).
* @see java.util.HexFormat
* @see #parseUnsignedInt(String, int)
* @see #toUnsignedString(int, int)
* @since 1.0.2
@@ -299,11 +299,19 @@ private static BigInteger toUnsignedBigInteger(long i) {
* <blockquote>
* {@code Long.toHexString(n).toUpperCase()}
* </blockquote>
* <p>
* @apiNote
* The {@link java.util.HexFormat} class provides formatting and parsing
* of byte arrays and primitives to return a string or adding to an {@link Appendable}.
* {@code HexFormat} formats and parses uppercase or lowercase hexadecimal characters,
* with leading zeros and for byte arrays includes for each byte
* a delimiter, prefix, and suffix.
*
* @param i a {@code long} to be converted to a string.
* @return the string representation of the unsigned {@code long}
* value represented by the argument in hexadecimal
* (base&nbsp;16).
* @see java.util.HexFormat
* @see #parseUnsignedLong(String, int)
* @see #toUnsignedString(long, int)
* @since 1.0.2
@@ -35,6 +35,7 @@
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HexFormat;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@@ -475,25 +476,17 @@ private void checkHashes() {
if (actualHash == null)
findFail("Unable to compute the hash of module %s", dn);
if (!Arrays.equals(recordedHash, actualHash)) {
HexFormat hex = HexFormat.of();
findFail("Hash of %s (%s) differs to expected hash (%s)" +
" recorded in %s", dn, toHexString(actualHash),
toHexString(recordedHash), descriptor.name());
" recorded in %s", dn, hex.formatHex(actualHash),
hex.formatHex(recordedHash), descriptor.name());
}
}
}

}
}

private static String toHexString(byte[] ba) {
StringBuilder sb = new StringBuilder(ba.length * 2);
for (byte b: ba) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
}


/**
* Computes the readability graph for the modules in the given Configuration.
*

1 comment on commit aa9c136

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on aa9c136 Dec 16, 2020

Please sign in to comment.