aboutsummaryrefslogtreecommitdiffstats
path: root/poi-examples/src/main/java/org
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/main/java/org
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/main/java/org')
-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
3 files changed, 10 insertions, 12 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);
}
}