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-grpc.git


The following commit(s) were added to refs/heads/main by this push:
     new 58e28a51 refactor: use Files.readString (Java 11+) (#755)
58e28a51 is described below

commit 58e28a512f88d7fbac3da74d6f25ee02d0e74175
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Fri Jun 26 21:55:43 2026 +0800

    refactor: use Files.readString (Java 11+) (#755)
    
    * refactor: use Files.readString (Java 11+)
    
    Motivation:
    Files.readString was introduced in Java 11 and provides a cleaner API
    for reading an entire file into a String, replacing the
    new String(Files.readAllBytes(path), charset) pattern.
    
    Modification:
    Replace new String(Files.readAllBytes(path), "UTF-8") with
    Files.readString(path, StandardCharsets.UTF_8) in two files.
    
    Result:
    More idiomatic Java 11+ code with identical behavior.
    
    Tests:
    Not run - behavior-preserving refactoring
    
    References:
    None - Java 11+ API migration
    
    * fix: apply javafmt formatting
---
 .../src/main/java/org/apache/pekko/grpc/benchmarks/Utils.java      | 3 ++-
 .../java/org/apache/pekko/grpc/interop/PekkoGrpcServerJava.java    | 7 ++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git 
a/benchmark-java/src/main/java/org/apache/pekko/grpc/benchmarks/Utils.java 
b/benchmark-java/src/main/java/org/apache/pekko/grpc/benchmarks/Utils.java
index 0c79a763..788d81a9 100644
--- a/benchmark-java/src/main/java/org/apache/pekko/grpc/benchmarks/Utils.java
+++ b/benchmark-java/src/main/java/org/apache/pekko/grpc/benchmarks/Utils.java
@@ -37,6 +37,7 @@ import java.io.*;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.SocketAddress;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.security.KeyFactory;
@@ -156,7 +157,7 @@ public final class Utils {
   }
 
   public static HttpsConnectionContext serverHttpContext() throws Exception {
-    String keyEncoded = new 
String(Files.readAllBytes(Paths.get(TestUtils.loadCert("server1.key").getAbsolutePath())),
 "UTF-8")
+    String keyEncoded = 
Files.readString(Paths.get(TestUtils.loadCert("server1.key").getAbsolutePath()),
 StandardCharsets.UTF_8)
         .replace("-----BEGIN PRIVATE KEY-----\n", "")
         .replace("-----END PRIVATE KEY-----\n", "")
         .replace("\n", "");
diff --git 
a/interop-tests/src/main/java/org/apache/pekko/grpc/interop/PekkoGrpcServerJava.java
 
b/interop-tests/src/main/java/org/apache/pekko/grpc/interop/PekkoGrpcServerJava.java
index 2af8ab5f..cd4da460 100644
--- 
a/interop-tests/src/main/java/org/apache/pekko/grpc/interop/PekkoGrpcServerJava.java
+++ 
b/interop-tests/src/main/java/org/apache/pekko/grpc/interop/PekkoGrpcServerJava.java
@@ -18,6 +18,7 @@ import io.grpc.internal.testing.TestUtils;
 import io.grpc.testing.integration.TestService;
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.security.KeyFactory;
@@ -122,9 +123,9 @@ public class PekkoGrpcServerJava extends 
GrpcServer<Tuple2<ActorSystem, ServerBi
 
   private HttpsConnectionContext serverHttpContext() throws Exception {
     String keyEncoded =
-        new String(
-                
Files.readAllBytes(Paths.get(TestUtils.loadCert("server1.key").getAbsolutePath())),
-                "UTF-8")
+        Files.readString(
+                Paths.get(TestUtils.loadCert("server1.key").getAbsolutePath()),
+                StandardCharsets.UTF_8)
             .replace("-----BEGIN PRIVATE KEY-----\n", "")
             .replace("-----END PRIVATE KEY-----\n", "")
             .replace("\n", "");


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

Reply via email to