aboutsummaryrefslogtreecommitdiffstats
path: root/poi-examples/src
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2021-05-14 00:37:50 +0000
committerAndreas Beeker <kiwiwings@apache.org>2021-05-14 00:37:50 +0000
commit0614835c55f44ab6f3e9b0850ca51e0e53a65a49 (patch)
tree586c68c89edb0978a441facf0066ff56d84fa2c7 /poi-examples/src
parentfe753d473788fc24030d7066654c56c33fff23b5 (diff)
downloadpoi-0614835c55f44ab6f3e9b0850ca51e0e53a65a49.tar.gz
poi-0614835c55f44ab6f3e9b0850ca51e0e53a65a49.zip
#65304 - Add commons-io as a dependency
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1889871 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-examples/src')
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/hpsf/WriteAuthorAndTitle.java3
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java12
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java7
-rw-r--r--poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java23
4 files changed, 22 insertions, 23 deletions
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/hpsf/WriteAuthorAndTitle.java b/poi-examples/src/main/java/org/apache/poi/examples/hpsf/WriteAuthorAndTitle.java
index 94ceaf6c03..71f4d8aa93 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/hpsf/WriteAuthorAndTitle.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/hpsf/WriteAuthorAndTitle.java
@@ -24,7 +24,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.hpsf.HPSFRuntimeException;
-import org.apache.poi.hpsf.MarkUnsupportedException;
import org.apache.poi.hpsf.NoPropertySetStreamException;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
@@ -165,7 +164,7 @@ public final class WriteAuthorAndTitle {
de.createDocument(event.getName(), is);
}
- } catch (MarkUnsupportedException | WritingNotSupportedException | IOException | NoPropertySetStreamException ex) {
+ } catch (WritingNotSupportedException | IOException | NoPropertySetStreamException ex) {
// According to the definition of the processPOIFSReaderEvent method we cannot pass checked
// exceptions to the caller.
throw new HPSFRuntimeException("Could not read file " + event.getPath() + "/" + event.getName(), ex);
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java b/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java
index 4603864d86..2cefd3d87f 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/OfficeDrawing.java
@@ -17,11 +17,12 @@
package org.apache.poi.examples.hssf.usermodel;
-import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.hssf.usermodel.HSSFChildAnchor;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFFont;
@@ -188,14 +189,11 @@ public final class OfficeDrawing {
}
- private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException
- {
+ private static int loadPicture( String path, HSSFWorkbook wb ) throws IOException {
int pictureIndex;
try (FileInputStream fis = new FileInputStream(path);
- ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
- int c;
- while ((c = fis.read()) != -1)
- bos.write(c);
+ UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+ IOUtils.copy(fis, bos);
pictureIndex = wb.addPicture(bos.toByteArray(), Workbook.PICTURE_TYPE_PNG);
}
return pictureIndex;
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java
index ebc04a4d33..edba46bba3 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/usermodel/CustomXMLMapping.java
@@ -16,8 +16,9 @@
==================================================================== */
package org.apache.poi.examples.xssf.usermodel;
-import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.extractor.XSSFExportToXml;
import org.apache.poi.xssf.usermodel.XSSFMap;
@@ -37,9 +38,9 @@ public final class CustomXMLMapping {
for (XSSFMap map : wb.getCustomXMLMappings()) {
XSSFExportToXml exporter = new XSSFExportToXml(map);
- ByteArrayOutputStream os = new ByteArrayOutputStream();
+ UnsynchronizedByteArrayOutputStream os = new UnsynchronizedByteArrayOutputStream();
exporter.exportToXML(os, true);
- String xml = os.toString("UTF-8");
+ String xml = os.toString(StandardCharsets.UTF_8);
System.out.println(xml);
}
}
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 6863fc9bbe..f21f512284 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
@@ -20,9 +20,10 @@ package org.apache.poi.integration;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.examples.xssf.eventusermodel.XLSX2CSV;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
@@ -33,7 +34,7 @@ import org.junit.jupiter.api.Test;
public class TestXLSX2CSV {
private PrintStream err;
- private final ByteArrayOutputStream errorBytes = new ByteArrayOutputStream();
+ private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream();
@BeforeEach
public void setUp() {
@@ -45,13 +46,13 @@ public class TestXLSX2CSV {
}
@AfterEach
- public void tearDown() throws Exception {
+ public void tearDown() {
// restore output-streams again
System.setErr(err);
// Print out found error
if (errorBytes.size() > 0) {
- System.err.println("Had stderr: " + errorBytes.toString("UTF-8"));
+ System.err.println("Had stderr: " + errorBytes.toString(StandardCharsets.UTF_8));
}
}
@@ -60,7 +61,7 @@ public class TestXLSX2CSV {
// returns with some System.err
XLSX2CSV.main(new String[0]);
- String output = errorBytes.toString("UTF-8");
+ String output = errorBytes.toString(StandardCharsets.UTF_8);
assertTrue(output.contains("XLSX2CSV <xlsx file>"), "Had: " + output);
}
@@ -75,7 +76,7 @@ public class TestXLSX2CSV {
@Test
public void testSampleFile() throws Exception {
- final ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
PrintStream out = new PrintStream(outputBytes);
// The package open is instantaneous, as it should be.
@@ -84,17 +85,17 @@ public class TestXLSX2CSV {
xlsx2csv.process();
}
- String errorOutput = errorBytes.toString("UTF-8");
+ String errorOutput = errorBytes.toString(StandardCharsets.UTF_8);
assertEquals(errorOutput.length(), 0);
- String output = outputBytes.toString("UTF-8");
+ String output = outputBytes.toString(StandardCharsets.UTF_8);
assertTrue(output.contains("\"Lorem\",111"), "Had: " + output);
assertTrue(output.contains(",\"hello, xssf\",,\"hello, xssf\""), "Had: " + output);
}
@Test
public void testMinColumns() throws Exception {
- final ByteArrayOutputStream outputBytes = new ByteArrayOutputStream();
+ final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream();
PrintStream out = new PrintStream(outputBytes);
// The package open is instantaneous, as it should be.
@@ -103,10 +104,10 @@ public class TestXLSX2CSV {
xlsx2csv.process();
}
- String errorOutput = errorBytes.toString("UTF-8");
+ String errorOutput = errorBytes.toString(StandardCharsets.UTF_8);
assertEquals(errorOutput.length(), 0);
- String output = outputBytes.toString("UTF-8");
+ String output = outputBytes.toString(StandardCharsets.UTF_8);
assertTrue(output.contains("\"Lorem\",111,,,"), "Had: " + output);
assertTrue(output.contains(",\"hello, xssf\",,\"hello, xssf\","), "Had: " + output);
}