This is an automated email from the ASF dual-hosted git repository.
He-Pin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko.git
The following commit(s) were added to refs/heads/main by this push:
new 22d44aa429 refactor: use Files.readString() in PemManagersProvider
(#3143)
22d44aa429 is described below
commit 22d44aa429a46661d3497893c7f99f2da1d5f3f8
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Tue Jun 23 19:33:24 2026 +0800
refactor: use Files.readString() in PemManagersProvider (#3143)
* refactor: use Files.readString() in PemManagersProvider
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
* refactor: add explicit StandardCharsets.UTF_8 to Files.readString
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
---
.../org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git
a/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala
b/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala
index 09c0db8fb6..28247b6720 100644
---
a/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala
+++
b/remote/src/main/scala/org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala
@@ -74,8 +74,7 @@ private[ssl] object PemManagersProvider {
*/
@InternalApi
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,
StandardCharsets.UTF_8)
DERPrivateKeyLoader.load(PEMDecoder.decode(pemData))
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]