Skip to content
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

Replace String/byte[] with (N)IO streams #838

Merged
merged 40 commits into from Sep 27, 2023
Merged

Replace String/byte[] with (N)IO streams #838

merged 40 commits into from Sep 27, 2023

Conversation

lhazlewood
Copy link
Contributor

@lhazlewood lhazlewood commented Sep 18, 2023

Closes #837

Replaced raw String and byte[] usages with CharSequence, InputStream/OutputStream and CharBuffer/ByteBuffer concepts where possible to eliminate unnecessary creation of intermediate byte arrays and/or temporary Strings.

Created new Writer/Reader concepts with backing implementations and tests, and deprecated the respective Serializer/Deserializer concepts.

Each Serializer/Deserializer implementation now subclasses/extends their respective parent Writer/Reader implementation out of convenience.  Serializer/Deserializer are not (currently) subinterfaces of Writer/Reader to avoid forcing new implementation requirements on existing implementations.
@lhazlewood lhazlewood changed the title Closes #837 Serializer/Deserializer replaced by Writer/Reader concepts Sep 18, 2023
@lhazlewood lhazlewood changed the title Serializer/Deserializer replaced by Writer/Reader concepts Serializer/Deserializer replaced by Writer/Reader Sep 18, 2023
…s to return CharSequences instead of Strings to avoid creating new Strings on the heap

- Changed internal Base64 implementation to work with a CharSequence instead of a raw char[] to reduce need to create new arrays on the heap
- Changed Base64Decoder generics signature from Decoder<String,byte[]> to Decoder<CharSequence,byte[]>
- Decoders.BASE64 and Decoders.BASE64URL now reflect Decoder<CharSequence,byte[]>
- Changed Strings#utf8 implementation to accept a CharSequence instead of a String
- Added new Strings#wrap to wrap a CharSequence into a CharBuffer if necessary
- Replaced not-yet-released JwtBuilder#serializer method with JwtBuilder#jsonWriter
- Replaced not-yet-released JwtParserBuilder#deserializer method with JwtParserBuilder#jsonReader
- Moved JwtDeserializer from io.jsonwebtoken.impl to io.jsonwebtoken.impl.io package, and updated its implementation to work with the new io.jsonwebtoken.io.Writer concept
- Updated GsonSerializer, GsonDeserializer, JacksonSerializer, JacksonDeserializer, and OrgJsonSerializer and OrgJsonDeserializer implementations to use JDK 7+ 'try with resources' try block instead of try/finally
…throwing MalformedJwtException. Added two subclasses, JwkDeserializer and JwkSetDeserializer that throws JWK and JWK Set-specific exceptions.

- Changed ParserBuilder#deserializer method name to ParserBuilder#jsonReader
…lize except for deprecated implementations. All other usages now use Writer/Reader concepts

- Added Jwks#json and Jwks#UNSAFE_JSON for assistance in serializing JWKs to JSON (test cases, README examples, etc)
…of just byte arrays

- Copied over necessary (Apache-licensed) code from Apache commons-codec to obtain Base64OutputStream and Base64InputStream capability for efficient encoding during compact JWT creation.  Hopefully this is temporary and we can strip out most if not all of this and modify our existing Base64.java class for simpler support since we have many less use cases than what commons-codec supports.
…ent(InputStream), JwtBuilder#content(InputStream, String contentType), JwtBuilder#content(String, String contentType)

- Added CountingInputStream as a way to check and assert that b64/unencoded payload InputStreams cannot be empty.
- 100% code coverage checkpoint
  - New JwtParser parseContentJws(String,InputStream) methods still need JavaDoc.
  - Still need to make AeadAlgorithm InputStream-based
  - New JwtParser parseContentJws(String,InputStream) methods are JavaDoc'd
  - Decompression is streaming when payload is consumable

Note: Still need to make AeadAlgorithm InputStream-based
@lhazlewood lhazlewood changed the title Serializer/Deserializer replaced by Writer/Reader Replace String/byte[] with (N)IO streams Sep 25, 2023
…encode/decode/compress/decompress for better readability and to make clearer the intent of the method. Also to avoid name/text/search collisions with 'wrap' references.
…(ideally didn't want to expose this implementation detail to the API).
@lhazlewood lhazlewood merged commit b687ca5 into master Sep 27, 2023
24 checks passed
@lhazlewood lhazlewood deleted the iostreams branch September 27, 2023 23:31
@lhazlewood lhazlewood added this to the 0.12.0 milestone Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace String/byte[] with (N)IO streams
1 participant