RFR 8251989: Hex formatter and parser utility

Peter Levart peter.levart at gmail.com
Thu Aug 27 17:21:53 UTC 2020

Hi Roger,

About methods in Hex.Formatter that append to StringBuilder, like the 
following one:

     public StringBuilder format​(StringBuilder sb, byte[] bytes)

...I was thinking that such method could have more utility if it was 
specified as:

     public <A extends Appendable> A format(A appendable, byte[] bytes)

For example, you could also format directly to PrintStream, Writer, 
CharBuffer or any custom implementation. The only grief is that 
Appendable methods are specified to throw IOException, but 
Hex.Formatter.format(Appendable ... methods could be specified to wrap 
such exception with UncheckedIOException. For usage with StringBuilder 
this would not change anything as it never throws IOException.

What do you think?

Regards, Peter

On 8/27/20 3:34 AM, Roger Riggs wrote:
> Please review updates to the formatting and parsing API based on the 
> last round of comments.
> There are many changes, so it may be useful to read it as a fresh draft.
>  - Rename classes: Encoder -> Formatter; Decoder -> Parser
>  - Rename methods: encode -> format; decode -> parse, etc.
>  - Rename factory methods to match
>  - Added a factory method and re-arrange arguments to make it more 
> convenient
>    to create uppercase formatters based on the existing uses.
>  - The implementation has been updated based on the suggestions and 
> API changes
> The webrev for applying the API to the security classes will be 
> updated when the API settles down.
> JavaDoc:
> http://cr.openjdk.java.net/~rriggs/hex-formatter/java.base/java/util/Hex.html 
> Webrev:
>   http://cr.openjdk.java.net/~rriggs/webrev-hex-formatter-8251989/
> CSR:
> https://bugs.openjdk.java.net/browse/JDK-8251991
> p.s.
> The previous (encoder/decoder) javadoc has been renamed to:
>    http://cr.openjdk.java.net/~rriggs/hex-encoder-javadoc/

More information about the core-libs-dev mailing list