]> source.dussan.org Git - poi.git/commitdiff
more use of commons-io
authorPJ Fanning <fanningpj@apache.org>
Fri, 27 Aug 2021 18:54:01 +0000 (18:54 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 27 Aug 2021 18:54:01 +0000 (18:54 +0000)
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
poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java
poi/src/main/java/org/apache/poi/sl/draw/BitmapImageRenderer.java
poi/src/main/java/org/apache/poi/sl/image/ImageHeaderBitmap.java
poi/src/main/java/org/apache/poi/sl/image/ImageHeaderPNG.java

index 77aff5febc9f364ab4de46add8695c149d3a1693..c5fac266e355b924ab52b3380fadf32d6ccbef44 100644 (file)
@@ -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();
index 680763bac244fd70f50ffc4c27d12c05be5c656e..1ce4238f638cd60aec0a25474af5fb4a9a563767 100644 (file)
 
 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));
         }
     }
 
index 4f2ca0ffbbd4885fa5b90dc3e66706c96f85dbce..557aecd5b05c8f8f4df28cc00721a8da6eecb43e 100644 (file)
@@ -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);
index b7d0a3c4ecfdc263ef9512bd7f4b65419c9a1309..9f7564cfe2da0cf57f75fb8e41486a0eedf2c1c1 100644 (file)
@@ -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");
         }
index 400bedd74ed4e98f120f1c0ff81fdfd85dcfeb1d..4a6b728fd372ff09b83a5ae60cd89a1d5073c237 100644 (file)
 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);
             }