Skip to content

[Java] Charset encoding handling improvements. #887

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 8 commits into from
Jan 8, 2022

Conversation

vyazelenko
Copy link
Contributor

@vyazelenko vyazelenko commented Jan 4, 2022

This PR contains several improvements to how charset encoding is handled by the JavaGenerator:

  • Add support for case-insensitive aliases for standard charsets, e.g. lAtIN1 will be resolved to StandardCharsets.ISO_8859_1. This is similar to how Charset.forName(String) works.
  • Use StandardCharsets when generating static CharacterEncoding methods, e.g. java.nio.charset.StandardCharsets.ISO_8859_1.name() will be used instead of a string "latin1" (when characterEncoding=latin1).
  • Use canonical names for charsets. The standard charsets are canonical by definition since the constants are used. For non-standard charsets the canonical name is resolved at the code generation time, e.g. if characterEncoding=cp912 is specified the resolved name will be ISO-8859-2 and will be used everywhere the original name would have been used. If the charset does not exist at the code generation time then the raw value is used.
  • Use putStringWithoutLengthAscii for methods taking a CharSequence.
  • Always use a Charset instance when converting to/from String. This eliminates most of the try/catch blocks in the generated code.
  • Avoid creation of an empty byte[] when input string is null or empty.
  • Treat character encodings as case-sensitive.

@mjpt777 mjpt777 merged commit ff8d2c9 into aeron-io:master Jan 8, 2022
@vyazelenko vyazelenko deleted the charset-encoding branch January 8, 2022 16:43
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants