RFR: 8251989: Hex formatting and parsing utility
Weijun Wang
weijun at openjdk.java.net
Fri Oct 2 19:16:38 UTC 2020
On Fri, 2 Oct 2020 15:18:04 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
> java.util.HexFormat utility:
>
> - Format and parse hexadecimal strings, with parameters for delimiter, prefix, suffix and upper/lowercase
> - Static factories and builder methods to create HexFormat copies with modified parameters.
> - Consistent naming of methods for conversion of byte arrays to formatted strings and back: formatHex and parseHex
> - Consistent naming of methods for conversion of primitive types: toHexDigits... and fromHexDigits...
> - Prefix and suffixes now apply to each formatted value, not the string as a whole
> - Using java.util.Appendable as a target for buffered conversions so output to Writers and PrintStreams
> like System.out are supported in addition to StringBuilder. (IOExceptions are converted to unchecked exceptions)
> - Immutable and thread safe, a "value-based" class
>
> See the [HexFormat
> javadoc](http://cr.openjdk.java.net/~rriggs/8251989-hex-formatter/java.base/java/util/HexFormat.html) for details.
> Review comments and suggestions welcome.
The class name already has `Hex` inside, and methods names still contain it. Also, I found it unexpected that
`fromHexDigits` returns an integer. Can we use `encode`, `decode`, `decodeInt`, `decodeLong` etc?
src/java.base/share/classes/java/util/HexFormat.java line 213:
> 211: * @param delimiter the {@code delimiter}, non-null, may be empty
> 212: * @return a copy of this {@code HexFormat} with the {@code delimiter}
> 213: */
Is this very useful now that we already have `ofDelimeter(String)`?
src/java.base/share/classes/java/util/HexFormat.java line 290:
> 288: * @return returns {@code true} if the hexadecimal digits will be uppercase,
> 289: * otherwise {@code false}
> 290: */
Can someone choose their own `digits`? If not, how about "=="?
-------------
PR: https://git.openjdk.java.net/jdk/pull/482
More information about the core-libs-dev
mailing list