RFR: 8251989: Hex formatting and parsing utility

Roger Riggs rriggs at openjdk.java.net
Tue Oct 13 17:21:17 UTC 2020


On Mon, 12 Oct 2020 23:05:44 GMT, Marcono1234 <github.com+11685886+Marcono1234 at openjdk.org> wrote:

> Also is it common practice to use `System.out` in JDK tests? In my opinion it often does not add much value once the
> unit test implementation has been completed because the output is not checked during tests automatically anyways and
> might only clutter the console output.

It has been useful to see the output generated and if there are failures there is additional information available.

> The tests are using `String.toUpperCase`, `toLowerCase` and `format` without `Locale` (therefore using the default
> one). Does the test setup guarantee a constant default locale or would be better to include a `Locale` to make sure the
> tests don't break for any unusual locale?

Good point, the ROOT locale should be used. Though for the cases of the hexadecimal characters, they are consistently
treated across all locales.

> Has it been also considered to add support for parsing from a `Reader` to an `OutputStream` and from `InputStream` to
> `Appendable` to support arbitrary length input and output?

That can be considered separately, the Jira issue 8254708 will track that enhancement.
A typical application reading input may need to handle a mix of input constructs with Hex being just one.
An application usually needs some kind of look ahead or push back to adjust to the contents of the stream
and that brings in a more complex grammar.

> Maybe it would also be good to mention for the method parsing and formatting `int`, `long`, ... in which byte order the
> output is created.

The big/little -endian terminology usually applies to binary representations. The natural reading order for numbers is
left to right but it can be more explicit.

> And would it be worth supporting a delimiter _period_ or _frequency_ to only apply the delimiter every nth byte? This
> would be useful when the user want to write hex chars in groups of 4 or 8.

It is a tradeoff in complexity.  The api focuses on the conversion of byte arrays to strings and back.
That behavior can be achieved naturally using the `toHexDigits` methods with the application handling the insertion of
delimiters.

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

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


More information about the core-libs-dev mailing list