RFR: 8251989: Hex formatting and parsing utility [v2]

Daniel Fuchs dfuchs at openjdk.java.net
Wed Oct 14 10:07:16 UTC 2020


On Tue, 13 Oct 2020 19:51:30 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.
>
> Roger Riggs has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Various code review comments, rename UpperCase and LowerCase methods to match Character, remove unnecessary Class name
>   qualifications, etc.

src/java.net.http/share/classes/jdk/internal/net/http/common/Utils.java line 1116:

> 1114:         }
> 1115:
> 1116:         HexFormat format = HexFormat.of().withUpperCase();

Should/can this be a static final field in the class?

src/java.base/share/classes/java/util/HexFormat.java line 41:

> 39:  * formatting markup such as prefixes, suffixes, and delimiters.
> 40:  * <p>
> 41:  * There are two {@code HexFormat}ters with preset parameters {@link #of()} and

Just a nit comment: stylistically, mixing fixed fonts and variable length fonts in a single word does not always
display well. Alternative include using plain words, and use {@linkplain } to link to the class/method described (e.g.
`{@linkplain HexFormat hexadecimal formatters}`), or reword (e.g. `There are two factories returning instances of
{@code HexFormat} with ...`)...

src/java.base/share/classes/java/util/HexFormat.java line 538:

> 536:      * A {@code delimiter} appears after each formatted value, except the last.
> 537:      * The {@code delimiter}s, {@code prefix}es, and {@code suffix}es strings must be present;
> 538:      * they may be empty strings.

I'd rather use @linkplain than @code here, or just plain words with no formatting, to avoid mixing different types of
fonts in a single word.

-------------

PR: https://git.openjdk.java.net/jdk/pull/482


More information about the core-libs-dev mailing list