refactor: use Files.readString() in PemManagersProvider#3143
Merged
Conversation
pjfanning
reviewed
Jun 23, 2026
| private[ssl] def loadPrivateKey(filename: String): PrivateKey = blocking { | ||
| val bytes = Files.readAllBytes(new File(filename).toPath) | ||
| val pemData = new String(bytes, StandardCharsets.UTF_8) | ||
| val pemData = Files.readString(new File(filename).toPath) |
Member
There was a problem hiding this comment.
can you pass StandardCharsets.UTF_8 param here just to make the code explicit? I agree this is the default for this API but it is easier to understand with the explicit param
Motivation: PemManagersProvider.loadPrivateKey reads a PEM file with Files.readAllBytes() and immediately converts to String via new String(bytes, StandardCharsets.UTF_8). Modification: Replace with Files.readString() (JDK 11) which reads a file directly into a String using UTF-8 by default. Remove the unused StandardCharsets import. Result: Eliminates intermediate byte[] allocation and explicit charset conversion. One line instead of two. Tests: sbt "remote/compile" — passed References: Refs #3136
Motivation: While UTF-8 is the default charset for Files.readString, making it explicit improves code readability and intent clarity. Modification: Pass StandardCharsets.UTF_8 as the second argument to Files.readString. Result: Code is more explicit about the expected encoding. References: Refs #3143
3782db5 to
8dabf23
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
PemManagersProvider.loadPrivateKeyreads a PEM file withFiles.readAllBytes()and immediately converts toStringvianew String(bytes, StandardCharsets.UTF_8).Modification
Replace with
Files.readString()(JDK 11) which reads a file directly into aStringusing UTF-8 by default. Remove the unusedStandardCharsetsimport.Result
Eliminates intermediate
byte[]allocation and explicit charset conversion. One line instead of two.Tests
sbt "remote/compile"— passedReferences
Refs #3136