8251989: Unified Hex formatting and parsing utility

Brian Goetz brian.goetz at oracle.com
Mon Sep 28 17:48:22 UTC 2020


Minor nit:

     Appendable foo(Appendable bar)

should be

     <A extend Appendable> A foo(A bar)

That way, if you say

     hex.formatHex(aStringBuilder, bytes)
        .foo()

where foo() is a method on StringBuilder but not on Appendable, it will 
still work as expected.

On 9/28/2020 11:32 AM, Roger Riggs wrote:
> After some reflection on the comments, suggestions, and other advice 
> offered
> the Hex format API has undergone a significant rewrite.
>
> The improvements include:
>
>  - Merged format and parse classes into a single class HexFormat that 
> holds parameters and has methods for all conversions
>  - Simplified static factories and added 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)
>
> The HexFormat javadoc is at:
> http://cr.openjdk.java.net/~rriggs/8251989-hex-formatter/java.base/java/util/HexFormat.html 
>
>
> Thanks to all that commented and made suggestions on core-libs-dev and 
> privately.
>
> Please review and comment.  When the API has settled, I'll turn it 
> into a PR and CSR.
>
> Thanks, Roger
>
>
>
>
>



More information about the core-libs-dev mailing list