From 57e18ccd65043323daf72291dd25f0367ea2edd7 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 27 Aug 2021 18:54:01 +0000 Subject: [PATCH] more use of commons-io git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892658 13f79535-47bb-0310-9956-ffa450edef68 --- poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java | 4 ++-- .../java/org/apache/poi/poifs/filesystem/Ole10Native.java | 4 ++-- .../java/org/apache/poi/sl/draw/BitmapImageRenderer.java | 5 ++++- .../main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java | 4 ++-- .../main/java/org/apache/poi/sl/image/ImageHeaderPNG.java | 4 ++-- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java index 77aff5febc..c5fac266e3 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java @@ -21,7 +21,6 @@ import static org.apache.logging.log4j.util.Unbox.box; import java.awt.Dimension; import java.awt.Rectangle; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.Collections; import java.util.LinkedHashMap; @@ -30,6 +29,7 @@ import java.util.function.Supplier; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; +import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -177,7 +177,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord { * @return the inflated picture data. */ private static byte[] inflatePictureData(byte[] data) { - try (InflaterInputStream in = new InflaterInputStream(new ByteArrayInputStream(data)); + try (InflaterInputStream in = new InflaterInputStream(new UnsynchronizedByteArrayInputStream(data)); UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) { IOUtils.copy(in, out); return out.toByteArray(); diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java index 680763bac2..1ce4238f63 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java @@ -17,12 +17,12 @@ package org.apache.poi.poifs.filesystem; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndianByteArrayInputStream; @@ -224,7 +224,7 @@ public class Ole10Native { */ public static void createOleMarkerEntry(final DirectoryEntry parent) throws IOException { if (!parent.hasEntry(OLE_MARKER_NAME)) { - parent.createDocument(OLE_MARKER_NAME, new ByteArrayInputStream(OLE_MARKER_BYTES)); + parent.createDocument(OLE_MARKER_NAME, new UnsynchronizedByteArrayInputStream(OLE_MARKER_BYTES)); } } diff --git a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java index 4f2ca0ffbb..557aecd5b0 100644 --- a/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java +++ b/poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java @@ -39,6 +39,7 @@ import javax.imageio.ImageTypeSpecifier; import javax.imageio.stream.ImageInputStream; import javax.imageio.stream.MemoryCacheImageInputStream; +import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -91,7 +92,7 @@ public class BitmapImageRenderer implements ImageRenderer { cachedImage = data.clone(); cachedContentType = contentType; } - img = readImage(new ByteArrayInputStream(data), contentType); + img = readImage(new UnsynchronizedByteArrayInputStream(data), contentType); } /** @@ -110,6 +111,8 @@ public class BitmapImageRenderer implements ImageRenderer { final InputStream bis; if (data instanceof ByteArrayInputStream) { bis = data; + } else if (data instanceof UnsynchronizedByteArrayInputStream) { + bis = data; } else { UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(0x3FFFF); IOUtils.copy(data, bos); diff --git a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java index b7d0a3c4ec..9f7564cfe2 100644 --- a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java +++ b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java @@ -19,11 +19,11 @@ package org.apache.poi.sl.image; import java.awt.Dimension; import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; import java.io.IOException; import javax.imageio.ImageIO; +import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.poi.util.Internal; @@ -38,7 +38,7 @@ public class ImageHeaderBitmap { public ImageHeaderBitmap(byte[] data, int offset) { BufferedImage img = null; try { - img = ImageIO.read(new ByteArrayInputStream(data, offset, data.length-offset)); + img = ImageIO.read(new UnsynchronizedByteArrayInputStream(data, offset, data.length-offset)); } catch (IOException e) { LOG.atWarn().withThrowable(e).log("Can't determine image dimensions"); } diff --git a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderPNG.java b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderPNG.java index 400bedd74e..4a6b728fd3 100644 --- a/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderPNG.java +++ b/poi/src/main/java/org/apache/poi/sl/image/ImageHeaderPNG.java @@ -18,10 +18,10 @@ package org.apache.poi.sl.image; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream; import org.apache.poi.poifs.filesystem.FileMagic; import org.apache.poi.util.IOUtils; import org.apache.poi.util.RecordFormatException; @@ -46,7 +46,7 @@ public final class ImageHeaderPNG { public byte[] extractPNG() { // //Just cut it off!. - try (InputStream is = new ByteArrayInputStream(data)) { + try (InputStream is = new UnsynchronizedByteArrayInputStream(data)) { if (is.skip(MAGIC_OFFSET) == MAGIC_OFFSET && FileMagic.valueOf(is) == FileMagic.PNG) { return IOUtils.toByteArray(is); }