You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/06/09 15:54:58 UTC

[commons-math] 03/09: Use UTF-8 encoding in PrintWriter

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

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-math.git

commit e300d2125133c245dbf891dc636306f6210ab8a8
Author: aherbert <ah...@apache.org>
AuthorDate: Wed Jun 9 16:25:35 2021 +0100

    Use UTF-8 encoding in PrintWriter
---
 .../apache/commons/math4/examples/sofm/chineserings/StandAlone.java    | 3 ++-
 .../java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java    | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java b/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java
index f23d20f..ad827b0 100644
--- a/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java
+++ b/commons-math-examples/examples-sofm/chinese-rings/src/main/java/org/apache/commons/math4/examples/sofm/chineserings/StandAlone.java
@@ -19,6 +19,7 @@ package org.apache.commons.math4.examples.sofm.chineserings;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Callable;
 
 import picocli.CommandLine;
@@ -80,7 +81,7 @@ public class StandAlone implements Callable<Void> {
                                     ChineseRingsClassifier sofm) {
         final NeuronSquareMesh2D.DataVisualization result = sofm.computeQualityIndicators();
 
-        try (final PrintWriter out = new PrintWriter(fileName)) {
+        try (final PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
             out.println("# Number of samples: " + result.getNumberOfSamples());
             out.println("# Quantization error: " + result.getMeanQuantizationError());
             out.println("# Topographic error: " + result.getMeanTopographicError());
diff --git a/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java b/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java
index 2d77877..9e25a6c 100644
--- a/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java
+++ b/commons-math-examples/examples-sofm/tsp/src/main/java/org/apache/commons/math4/examples/sofm/tsp/StandAlone.java
@@ -19,6 +19,7 @@ package org.apache.commons.math4.examples.sofm.tsp;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.concurrent.Callable;
 
 import picocli.CommandLine;
@@ -145,7 +146,7 @@ public class StandAlone implements Callable<Void> {
     private static void printSummary(String fileName,
                                      City[] travel,
                                      double optimalDistance) {
-        try (final PrintWriter out = new PrintWriter(fileName)) {
+        try (final PrintWriter out = new PrintWriter(fileName, StandardCharsets.UTF_8.name())) {
             out.println("# Number of unique cities: " + City.unique(travel).size());
             out.println("# Travel distance: " + computeDistance(travel));
             out.println("# Optimal travel distance: " + optimalDistance);