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 d9714dc4 chore: use StandardCharsets.UTF_8 (#783)
d9714dc4 is described below
commit d9714dc4184f8b4af20e8d41c8f397cf48a3e88b
Author: He-Pin(kerr) <[email protected]>
AuthorDate: Mon Jul 6 23:17:34 2026 +0800
chore: use StandardCharsets.UTF_8 (#783)
Motivation:\nAvoid stringly-typed UTF-8 charset usage in encoding and
decoding code paths.\n\nModification:\nReplace UTF-8 charset string arguments
with StandardCharsets.UTF_8 and normalize touched XML declarations where
applicable.\n\nResult:\nCharset usage is type-safe and exact lowercase "utf-8"
string literals are removed from the touched areas.
---
codegen/src/main/scala/org/apache/pekko/grpc/gen/Logging.scala | 3 ++-
codegen/src/main/scala/org/apache/pekko/grpc/gen/Main.scala | 3 ++-
.../groovy/org/apache/pekko/grpc/gradle/PekkoGrpcPlugin.groovy | 3 ++-
.../main/java/io/grpc/testing/integration2/TestServiceClient.java | 3 ++-
.../scala/org/apache/pekko/grpc/interop/PekkoGrpcServerScala.scala | 4 +++-
.../src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml | 4 ++--
.../scala/org/apache/pekko/grpc/maven/AbstractGenerateMojo.scala | 7 ++++---
7 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/codegen/src/main/scala/org/apache/pekko/grpc/gen/Logging.scala
b/codegen/src/main/scala/org/apache/pekko/grpc/gen/Logging.scala
index 76d6ec75..f5769371 100644
--- a/codegen/src/main/scala/org/apache/pekko/grpc/gen/Logging.scala
+++ b/codegen/src/main/scala/org/apache/pekko/grpc/gen/Logging.scala
@@ -14,6 +14,7 @@
package org.apache.pekko.grpc.gen
import java.io.PrintWriter
+import java.nio.charset.StandardCharsets
// specific to gen so that the build tools can implement their own
trait Logger {
@@ -41,7 +42,7 @@ object SilencedLogger extends Logger {
}
class FileLogger(path: String) extends Logger {
- val printer = new PrintWriter(path, "UTF-8")
+ val printer = new PrintWriter(path, StandardCharsets.UTF_8)
def debug(text: String): Unit = {
printer.println(s"[debug] $text")
printer.flush()
diff --git a/codegen/src/main/scala/org/apache/pekko/grpc/gen/Main.scala
b/codegen/src/main/scala/org/apache/pekko/grpc/gen/Main.scala
index 9b7ad4d6..e3478c41 100644
--- a/codegen/src/main/scala/org/apache/pekko/grpc/gen/Main.scala
+++ b/codegen/src/main/scala/org/apache/pekko/grpc/gen/Main.scala
@@ -15,6 +15,7 @@ package org.apache.pekko.grpc.gen
import java.io.ByteArrayOutputStream
import java.net.URLDecoder
+import java.nio.charset.StandardCharsets
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest
import org.apache.pekko
@@ -61,7 +62,7 @@ object Main {
val logger: Logger =
parameters
.get("logfile_enc")
- .map(URLDecoder.decode(_, "utf-8"))
+ .map(URLDecoder.decode(_, StandardCharsets.UTF_8))
.orElse(parameters.get("logfile"))
.map(new FileLogger(_))
.getOrElse(SilencedLogger)
diff --git
a/gradle-plugin/src/main/groovy/org/apache/pekko/grpc/gradle/PekkoGrpcPlugin.groovy
b/gradle-plugin/src/main/groovy/org/apache/pekko/grpc/gradle/PekkoGrpcPlugin.groovy
index 090f5747..6f8e46ff 100644
---
a/gradle-plugin/src/main/groovy/org/apache/pekko/grpc/gradle/PekkoGrpcPlugin.groovy
+++
b/gradle-plugin/src/main/groovy/org/apache/pekko/grpc/gradle/PekkoGrpcPlugin.groovy
@@ -21,6 +21,7 @@ import org.gradle.util.GradleVersion
import org.gradle.util.VersionNumber
import java.net.URLEncoder
+import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
@@ -133,7 +134,7 @@ class PekkoGrpcPlugin implements Plugin<Project> {
option
"server_power_apis=${pekkoGrpcExt.serverPowerApis}"
option
"use_play_actions=${pekkoGrpcExt.usePlayActions}"
option
"extra_generators=${pekkoGrpcExt.extraGenerators.join(';')}"
- option
"logfile_enc=${URLEncoder.encode(logFileRelative, "utf-8")}"
+ option
"logfile_enc=${URLEncoder.encode(logFileRelative, StandardCharsets.UTF_8)}"
if (pekkoGrpcExt.includeStdTypes) {
option "include_std_types=true"
}
diff --git
a/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java
b/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java
index 6f0b68de..1b87bcc3 100644
---
a/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java
+++
b/interop-tests/src/main/java/io/grpc/testing/integration2/TestServiceClient.java
@@ -24,6 +24,7 @@ import io.grpc.testing.integration.TestServiceGrpc;
import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
/**
* Application that starts a client for the {@link
TestServiceGrpc.TestServiceImplBase} and runs
@@ -31,7 +32,7 @@ import java.nio.charset.Charset;
*/
public class TestServiceClient {
- private static final Charset UTF_8 = Charset.forName("UTF-8");
+ private static final Charset UTF_8 = StandardCharsets.UTF_8;
private String testCase = "empty_unary";
diff --git
a/interop-tests/src/main/scala/org/apache/pekko/grpc/interop/PekkoGrpcServerScala.scala
b/interop-tests/src/main/scala/org/apache/pekko/grpc/interop/PekkoGrpcServerScala.scala
index 8896e1ec..197135f4 100644
---
a/interop-tests/src/main/scala/org/apache/pekko/grpc/interop/PekkoGrpcServerScala.scala
+++
b/interop-tests/src/main/scala/org/apache/pekko/grpc/interop/PekkoGrpcServerScala.scala
@@ -14,6 +14,7 @@
package org.apache.pekko.grpc.interop
import java.io.FileInputStream
+import java.nio.charset.StandardCharsets
import java.nio.file.{ Files, Paths }
import java.security.cert.CertificateFactory
import java.security.spec.PKCS8EncodedKeySpec
@@ -61,7 +62,8 @@ case class PekkoGrpcServerScala(serverHandlerFactory:
ActorSystem => HttpRequest
private def serverHttpContext() = {
val keyEncoded =
- new
String(Files.readAllBytes(Paths.get(TestUtils.loadCert("server1.key").getAbsolutePath)),
"UTF-8")
+ new
String(Files.readAllBytes(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/maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
b/maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
index 0e652e38..2048ce08 100644
---
a/maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
+++
b/maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
@@ -15,4 +15,4 @@
</action>
</pluginExecution>
</pluginExecutions>
-</lifecycleMappingMetadata>
\ No newline at end of file
+</lifecycleMappingMetadata>
diff --git
a/maven-plugin/src/main/scala/org/apache/pekko/grpc/maven/AbstractGenerateMojo.scala
b/maven-plugin/src/main/scala/org/apache/pekko/grpc/maven/AbstractGenerateMojo.scala
index 61c7475c..11262253 100644
---
a/maven-plugin/src/main/scala/org/apache/pekko/grpc/maven/AbstractGenerateMojo.scala
+++
b/maven-plugin/src/main/scala/org/apache/pekko/grpc/maven/AbstractGenerateMojo.scala
@@ -14,6 +14,7 @@
package org.apache.pekko.grpc.maven
import java.io.{ ByteArrayOutputStream, File, PrintStream }
+import java.nio.charset.StandardCharsets
import org.apache.pekko
import pekko.grpc.gen.{ CodeGenerator, Logger, ProtocSettings }
@@ -47,9 +48,9 @@ object AbstractGenerateMojo {
private def captureStdOutAndErr[T](block: => T): (String, String, T) = {
val errBao = new ByteArrayOutputStream()
- val errPrinter = new PrintStream(errBao, true, "UTF-8")
+ val errPrinter = new PrintStream(errBao, true, StandardCharsets.UTF_8)
val outBao = new ByteArrayOutputStream()
- val outPrinter = new PrintStream(outBao, true, "UTF-8")
+ val outPrinter = new PrintStream(outBao, true, StandardCharsets.UTF_8)
val originalOut = System.out
val originalErr = System.err
System.setOut(outPrinter)
@@ -62,7 +63,7 @@ object AbstractGenerateMojo {
System.setErr(originalErr)
}
- (outBao.toString("UTF-8"), errBao.toString("UTF-8"), t)
+ (outBao.toString(StandardCharsets.UTF_8),
errBao.toString(StandardCharsets.UTF_8), t)
}
sealed trait Language {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]