mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8251989: Hex formatting and parsing utility
Reviewed-by: tvaleev, chegar, naoto, darcy
This commit is contained in:
parent
efd61c6f53
commit
aa9c136d67
14 changed files with 1921 additions and 167 deletions
|
@ -264,10 +264,18 @@ public final class Integer extends Number
|
|||
* <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 16).
|
||||
* @see java.util.HexFormat
|
||||
* @see #parseUnsignedInt(String, int)
|
||||
* @see #toUnsignedString(int, int)
|
||||
* @since 1.0.2
|
||||
|
|
|
@ -299,11 +299,19 @@ public final class Long extends Number
|
|||
* <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 16).
|
||||
* @see java.util.HexFormat
|
||||
* @see #parseUnsignedLong(String, int)
|
||||
* @see #toUnsignedString(long, int)
|
||||
* @since 1.0.2
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.Collection;
|
|||
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,9 +476,10 @@ final class Resolver {
|
|||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -485,15 +487,6 @@ final class Resolver {
|
|||
}
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue