This is an automated email from the ASF dual-hosted git repository.

He-Pin pushed a commit to branch refactor/files-readstring
in repository https://gitbox.apache.org/repos/asf/pekko.git

commit 3782db595305da8effdf152c7519e1c7e0c6228e
Author: 虎鸣 <[email protected]>
AuthorDate: Tue Jun 23 11:13:09 2026 +0800

    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
---
 .../org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala  | 4 +---
 1 file changed, 1 insertion(+), 3 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..c62aa94a51 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
@@ -14,7 +14,6 @@
 package org.apache.pekko.remote.artery.tcp.ssl
 
 import java.io.File
-import java.nio.charset.StandardCharsets
 import java.nio.file.Files
 import java.security.{ KeyStore, PrivateKey }
 import java.security.cert.{ Certificate, CertificateFactory, X509Certificate }
@@ -74,8 +73,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)
     DERPrivateKeyLoader.load(PEMDecoder.decode(pemData))
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to