diff options
13 files changed, 39 insertions, 32 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)) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java index eb37159ba4..bba3433850 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/util/HierarchyPrinter.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import org.apache.poi.xdgf.usermodel.XDGFPage; import org.apache.poi.xdgf.usermodel.XDGFShape; @@ -46,7 +47,7 @@ public class HierarchyPrinter { try ( OutputStream os = new FileOutputStream(pageFile); - PrintStream pos = new PrintStream(os, false, "utf-8") + PrintStream pos = new PrintStream(os, false, StandardCharsets.UTF_8.name()) ) { printHierarchy(page, pos); } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java index 1e467244f5..bd500bff25 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/StreamingSheetWriter.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -64,7 +65,7 @@ public class StreamingSheetWriter extends SheetDataWriter { * @param out the output stream to write to */ protected static Writer createWriter(OutputStream out) throws IOException { - return new BufferedWriter(new OutputStreamWriter(out, "UTF-8")); + return new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)); } @Override diff --git a/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 9100040136..66c7ae39e5 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -74,7 +74,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xml = os.toString("UTF-8"); + String xml = os.toString(StandardCharsets.UTF_8); assertNotNull(xml); assertFalse(xml.isEmpty()); @@ -122,7 +122,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xml = os.toString("UTF-8"); + String xml = os.toString(StandardCharsets.UTF_8); assertNotNull(xml); assertFalse(xml.isEmpty()); @@ -196,7 +196,7 @@ public final class TestXSSFExportToXML { String xml; try (UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream()) { exporter.exportToXML(os, true); - xml = os.toString("UTF-8"); + xml = os.toString(StandardCharsets.UTF_8); } assertNotNull(xml); @@ -258,7 +258,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -302,7 +302,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -337,7 +337,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -376,7 +376,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -402,7 +402,7 @@ public final class TestXSSFExportToXML { UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -480,7 +480,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -558,7 +558,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -589,7 +589,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, false); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -621,7 +621,7 @@ public final class TestXSSFExportToXML { XSSFExportToXml exporter = new XSSFExportToXml(map); UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, true); - String xmlData = os.toString("UTF-8"); + String xmlData = os.toString(StandardCharsets.UTF_8); assertNotNull(xmlData); assertFalse(xmlData.isEmpty()); @@ -647,7 +647,7 @@ public final class TestXSSFExportToXML { UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(os, false); - assertNotNull(os.toString("UTF-8")); + assertNotNull(os.toString(StandardCharsets.UTF_8)); } } } @@ -660,7 +660,7 @@ public final class TestXSSFExportToXML { UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); exporter.exportToXML(bos, true); assertNotNull(DocumentHelper.readDocument(bos.toInputStream())); - String exportedXml = bos.toString("UTF-8"); + String exportedXml = bos.toString(StandardCharsets.UTF_8); assertEquals("<Test><Test>1</Test></Test>", exportedXml.replaceAll("\\s+", "")); } } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java index 19eda1e7f7..b85592f112 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/Chunk.java @@ -222,7 +222,7 @@ public final class Chunk { } int strLen = endsAt - startsAt; - command.value = new String(contents, startsAt, strLen, header.getChunkCharset().name()); + command.value = new String(contents, startsAt, strLen, header.getChunkCharset()); break; case 25: command.value = LittleEndian.getShort(contents, offset); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java index 97be9616e8..cd61da75fe 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV4V5.java @@ -18,6 +18,7 @@ package org.apache.poi.hdgf.chunks; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * A chunk header from v4 or v5 @@ -59,7 +60,7 @@ public final class ChunkHeaderV4V5 extends ChunkHeader { @Override public Charset getChunkCharset() { - return Charset.forName("ASCII"); + return StandardCharsets.US_ASCII; } void setUnknown2(short unknown2) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java index 81bbe1ba14..9029b47880 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hdgf/chunks/ChunkHeaderV6.java @@ -18,6 +18,7 @@ package org.apache.poi.hdgf.chunks; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * A chunk header from v6 @@ -64,7 +65,7 @@ public class ChunkHeaderV6 extends ChunkHeader { @Override public Charset getChunkCharset() { - return Charset.forName("ASCII"); + return StandardCharsets.US_ASCII; } void setUnknown2(short unknown2) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java index f1ef43c766..482f8a941b 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/MessageSubmissionChunk.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Calendar; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -62,7 +63,7 @@ public class MessageSubmissionChunk extends Chunk { public void readValue(InputStream value) throws IOException { // Stored in the file as us-ascii byte[] data = IOUtils.toByteArray(value); - rawId = new String(data, Charset.forName("ASCII")); + rawId = new String(data, StandardCharsets.US_ASCII); // Now process the date String[] parts = rawId.split(";"); @@ -112,7 +113,7 @@ public class MessageSubmissionChunk extends Chunk { @Override public void writeValue(OutputStream out) throws IOException { - byte[] data = rawId.getBytes(Charset.forName("ASCII")); + final byte[] data = rawId.getBytes(StandardCharsets.US_ASCII); out.write(data); } diff --git a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java index 5362f406cd..8cee4a828c 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelCetabFunctionExtractor.java @@ -322,7 +322,7 @@ public final class ExcelCetabFunctionExtractor { private static void processFile(InputStream input, File outFile) throws IOException { try (OutputStream os = new SimpleAsciiOutputStream(new FileOutputStream(outFile)); - PrintStream ps = new PrintStream(os, true, "UTF-8")) { + PrintStream ps = new PrintStream(os, true, StandardCharsets.UTF_8.name())) { outputLicenseHeader(ps); Class<?> genClass = ExcelCetabFunctionExtractor.class; diff --git a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java index 3e7c1ab2a2..6e5f0645df 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/function/ExcelFileFormatDocFunctionExtractor.java @@ -30,6 +30,7 @@ import java.math.BigInteger; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.ArrayList; import java.util.Arrays; @@ -492,7 +493,7 @@ public final class ExcelFileFormatDocFunctionExtractor { os = new SimpleAsciiOutputStream(os); PrintStream ps; try { - ps = new PrintStream(os, true, "UTF-8"); + ps = new PrintStream(os, true, StandardCharsets.UTF_8.name()); } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); } |