-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Base16 (Hex) and Base64 encoding and decoding capabilities #25
Comments
Base64 encoding/decoding should be Basic. If the user wants to read a Base64 MIME encoded file, he or she can do it this way in Java 9 or later: byte[] decodedBytes = Base64.getMimeDecoder().wrap(/*InputStream*/).readAllBytes();
The procedure is analogous for encoding. |
Hex string need not be even length. As a consequence, different length strings may result in the same byte array. This library should be able to parse all valid hex strings. The simplest way to encode a byte array to an even length string: // byte[] array = ...
StringBuilder sb = new StringBuilder();
for (byte b : array) {
sb.append(String.format("%02X", b));
}
String result = sb.toString(); What to do with empty strings ( |
Base64 support will be dropped. It is easy enough for the user of this library to convert a Base64 string to a byte array (and vice versa) using the Java SE API version 8 or later. |
At the moment, we're wired to an external dependency
jakarta.xml.bind:jakarta.xml.bind-api
just so that we can useDatatypeConverter
. This dependency could be removed.Java 8 introduced
Base64
class and the hex encoding/decoding looks easy enough to implement.The library currently only parses Base64 and Base16 strings. We should add
default
methods toBytes
that would encode byte sequences to Base64 and Base16 strings.The text was updated successfully, but these errors were encountered: