summaryrefslogtreecommitdiffstats
path: root/poi-examples
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-07-15 21:52:32 +0000
committerPJ Fanning <fanningpj@apache.org>2022-07-15 21:52:32 +0000
commit87ee700d04af1fea764c0762f0fb5dada4411295 (patch)
treefadbb626410244764c087b4ed23cc467eed76764 /poi-examples
parent70bd85fda41f885427e3db8d5b32eb71656f8eb0 (diff)
downloadpoi-87ee700d04af1fea764c0762f0fb5dada4411295.tar.gz
poi-87ee700d04af1fea764c0762f0fb5dada4411295.zip
[github-340] make more use of StandardCharsets. Thanks to XenoAmess. This closes #340
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1902755 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-examples')
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/hsmf/Msg2txt.java3
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/ss/html/ToHtml.java2
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/BigGridDemo.java6
-rw-r--r--poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java8
4 files changed, 10 insertions, 9 deletions
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/hsmf/Msg2txt.java b/poi-examples/src/main/java/org/apache/poi/examples/hsmf/Msg2txt.java
index 54dd9a279e..151cfc6fa0 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/hsmf/Msg2txt.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/hsmf/Msg2txt.java
@@ -22,6 +22,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
+import java.nio.charset.StandardCharsets;
import org.apache.poi.hsmf.MAPIMessage;
import org.apache.poi.hsmf.datatypes.AttachmentChunks;
@@ -62,7 +63,7 @@ public class Msg2txt {
public void processMessage() throws IOException {
String txtFileName = fileNameStem + ".txt";
String attDirName = fileNameStem + "-att";
- try (PrintWriter txtOut = new PrintWriter(txtFileName, "UTF-8")) {
+ try (PrintWriter txtOut = new PrintWriter(txtFileName, StandardCharsets.UTF_8.name())) {
try {
String displayFrom = msg.getDisplayFrom();
txtOut.println("From: " + displayFrom);
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/html/ToHtml.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/html/ToHtml.java
index 5097f34e98..cf9eeaf5c0 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/ss/html/ToHtml.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/html/ToHtml.java
@@ -190,7 +190,7 @@ public final class ToHtml {
return;
}
- try (PrintWriter pw = new PrintWriter(args[1], "UTF-8")) {
+ try (PrintWriter pw = new PrintWriter(args[1], StandardCharsets.UTF_8.name())) {
ToHtml toHtml = create(args[0], pw);
toHtml.setCompleteHTML(true);
toHtml.printPage();
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/BigGridDemo.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/BigGridDemo.java
index f73e25a2c2..f0562be0b8 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/BigGridDemo.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/BigGridDemo.java
@@ -25,6 +25,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Enumeration;
import java.util.HashMap;
@@ -77,7 +78,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
*/
public final class BigGridDemo {
private static final Logger LOG = LogManager.getLogger(BigGridDemo.class);
- private static final String XML_ENCODING = "UTF-8";
private static final Random rnd = new Random();
@@ -105,7 +105,7 @@ public final class BigGridDemo {
tmp = TempFile.createTempFile("sheet", ".xml");
try (
FileOutputStream stream = new FileOutputStream(tmp);
- Writer fw = new OutputStreamWriter(stream, XML_ENCODING)
+ Writer fw = new OutputStreamWriter(stream, StandardCharsets.UTF_8)
) {
generate(fw, styles);
}
@@ -247,7 +247,7 @@ public final class BigGridDemo {
}
void beginSheet() throws IOException {
- _out.write("<?xml version=\"1.0\" encoding=\""+XML_ENCODING+"\"?>" +
+ _out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\">" );
_out.write("<sheetData>\n");
}
diff --git a/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java b/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java
index 4d1a95444d..a9bed39008 100644
--- a/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java
+++ b/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java
@@ -42,7 +42,7 @@ public class TestXLSX2CSV {
// remember and replace default error streams
err = System.err;
- PrintStream error = new PrintStream(errorBytes, true, "UTF-8");
+ PrintStream error = new PrintStream(errorBytes, true, StandardCharsets.UTF_8.name());
System.setErr(error);
}
@@ -71,14 +71,14 @@ public class TestXLSX2CSV {
// returns with some System.err
XLSX2CSV.main(new String[] { "not-existing-file.xlsx" });
- String output = errorBytes.toString("UTF-8");
+ String output = errorBytes.toString(StandardCharsets.UTF_8);
assertTrue(output.contains("Not found or not a file: not-existing-file.xlsx"), "Had: " + output);
}
@Test
public void testSampleFile() throws Exception {
final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
- PrintStream out = new PrintStream(outputBytes, true, "UTF-8");
+ PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
// The package open is instantaneous, as it should be.
try (OPCPackage p = OPCPackage.open(XSSFTestDataSamples.getSampleFile("sample.xlsx").getAbsolutePath(), PackageAccess.READ)) {
@@ -97,7 +97,7 @@ public class TestXLSX2CSV {
@Test
public void testMinColumns() throws Exception {
final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
- PrintStream out = new PrintStream(outputBytes, true, "UTF-8");
+ PrintStream out = new PrintStream(outputBytes, true, StandardCharsets.UTF_8.name());
// The package open is instantaneous, as it should be.
try (OPCPackage p = OPCPackage.open(XSSFTestDataSamples.getSampleFile("sample.xlsx").getAbsolutePath(), PackageAccess.READ)) {