]> source.dussan.org Git - poi.git/commitdiff
more use of commons-io
authorPJ Fanning <fanningpj@apache.org>
Sat, 28 Aug 2021 09:13:21 +0000 (09:13 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 28 Aug 2021 09:13:21 +0000 (09:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892669 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/hpsf/PropertySet.java
poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java
poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
poi/src/main/java/org/apache/poi/hssf/record/Record.java
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java
poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java
poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java
poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java
poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java

index 324fb4b4c964645db31defb82e79847a8a661892..5237309c9c46b38ded3df5b5d75ff7507aa4dbfb 100644 (file)
@@ -17,7 +17,6 @@
 
 package org.apache.poi.hpsf;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -26,6 +25,7 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.EmptyFileException;
 import org.apache.poi.hpsf.wellknown.PropertyIDMap;
@@ -598,7 +598,7 @@ public class PropertySet {
      * @throws IOException if an I/O exception occurs.
      */
     public InputStream toInputStream() throws WritingNotSupportedException, IOException {
-        return new ByteArrayInputStream(toBytes());
+        return new UnsynchronizedByteArrayInputStream(toBytes());
     }
 
     /**
index e45d0c3cf46707dc97459901a91d5c19576a4b61..d90aa2ed6c69fc1ac01a8dbe2d6eae1ba2476866 100644 (file)
  */
 package org.apache.poi.hssf.record;
 
-import java.io.ByteArrayInputStream;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.function.Supplier;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.poi.util.GenericRecordUtil;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndianOutput;
@@ -278,7 +278,7 @@ public class DConRefRecord extends StandardRecord {
     }
 
     private static RecordInputStream bytesToRIStream(byte[] data) {
-        RecordInputStream ric = new RecordInputStream(new ByteArrayInputStream(data));
+        RecordInputStream ric = new RecordInputStream(new UnsynchronizedByteArrayInputStream(data));
         ric.nextRecord();
         return ric;
     }
index f03028d8234037839e568696c7df29910ffe8a18..a4cb805e039d8714d7a5838ab696bf1be03740cd 100644 (file)
@@ -17,7 +17,8 @@
 
 package org.apache.poi.hssf.record;
 
-import java.io.ByteArrayInputStream;
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
+
 import java.util.Map;
 import java.util.function.Supplier;
 
@@ -48,7 +49,7 @@ public final class DrawingRecordForBiffViewer extends AbstractEscherHolderRecord
     {
         byte[] data = r.serialize();
         RecordInputStream rinp = new RecordInputStream(
-                new ByteArrayInputStream(data)
+                new UnsynchronizedByteArrayInputStream(data)
         );
         rinp.nextRecord();
         return rinp;
index f43bf9ed52ca4d4aaa44f5fb70b0dc4409d16530..5aeef7dfb48c8a5875e04e49e58e4d3f3b4106a8 100644 (file)
 
 package org.apache.poi.hssf.record;
 
-import java.io.ByteArrayInputStream;
 import java.util.Map;
 import java.util.function.Supplier;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.poi.ss.formula.ptg.Area3DPtg;
@@ -179,7 +179,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
     }
 
     private static Ptg readRefPtg(byte[] formulaRawBytes) {
-        LittleEndianInput in = new LittleEndianInputStream(new ByteArrayInputStream(formulaRawBytes));
+        LittleEndianInput in = new LittleEndianInputStream(new UnsynchronizedByteArrayInputStream(formulaRawBytes));
         byte ptgSid = in.readByte();
         switch(ptgSid) {
             case AreaPtg.sid:   return new AreaPtg(in);
index ede39a04f21934b2796800ded1336ca447da383d..3ae5c1b3128ba3d9636cc3ef1177195c827655e9 100644 (file)
@@ -17,8 +17,7 @@
 
 package org.apache.poi.hssf.record;
 
-import java.io.ByteArrayInputStream;
-
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.poi.common.Duplicatable;
 import org.apache.poi.common.usermodel.GenericRecord;
 import org.apache.poi.util.GenericRecordJsonWriter;
@@ -76,7 +75,7 @@ public abstract class Record extends RecordBase implements Duplicatable, Generic
         // Do it via a re-serialization
         // It's a cheat, but it works...
         byte[] b = serialize();
-        RecordInputStream rinp = new RecordInputStream(new ByteArrayInputStream(b));
+        RecordInputStream rinp = new RecordInputStream(new UnsynchronizedByteArrayInputStream(b));
         rinp.nextRecord();
 
         Record[] r = RecordFactory.createRecord(rinp);
index bd450962344565494caac77f7cf336191eda6987..29b163ce67b4eb347c5e6f09275171b854bb4bec 100644 (file)
@@ -18,8 +18,8 @@
 package org.apache.poi.hssf.usermodel;
 
 import java.awt.Dimension;
-import java.io.ByteArrayInputStream;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.poi.ddf.DefaultEscherRecordFactory;
 import org.apache.poi.ddf.EscherBSERecord;
 import org.apache.poi.ddf.EscherBlipRecord;
@@ -191,7 +191,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
         EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
         byte[] data = bse.getBlipRecord().getPicturedata();
         int type = bse.getBlipTypeWin32();
-        return ImageUtils.getImageDimension(new ByteArrayInputStream(data), type);
+        return ImageUtils.getImageDimension(new UnsynchronizedByteArrayInputStream(data), type);
     }
 
     /**
index 136b02b75b4c8e42c290354d6674050da942282d..548e8c0279c8d180c2792451b2d1a739848d6ca1 100644 (file)
@@ -22,7 +22,6 @@ import static org.apache.poi.hssf.model.InternalWorkbook.OLD_WORKBOOK_DIR_ENTRY_
 import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAMES;
 
 import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -46,6 +45,7 @@ import java.util.Set;
 import java.util.regex.Pattern;
 
 import org.apache.commons.codec.digest.DigestUtils;
+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;
@@ -1305,7 +1305,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
         DocumentNode workbookNode = (DocumentNode) dir.getEntry(
                 getWorkbookDirEntryName(dir));
         POIFSDocument workbookDoc = new POIFSDocument(workbookNode);
-        workbookDoc.replaceContents(new ByteArrayInputStream(getBytes()));
+        workbookDoc.replaceContents(new UnsynchronizedByteArrayInputStream(getBytes()));
 
         // Update the properties streams in the file
         writeProperties();
@@ -1367,7 +1367,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
         List<String> excepts = new ArrayList<>(1);
 
         // Write out the Workbook stream
-        fs.createDocument(new ByteArrayInputStream(getBytes()), "Workbook");
+        fs.createDocument(new UnsynchronizedByteArrayInputStream(getBytes()), "Workbook");
 
         // Write out our HPFS properties, if we have them
         writeProperties(fs, excepts);
index ec15c114466ce3c5612c899d6eed6813bc3f9345..e848859a00b004d8a81b0f4338c0cfbd9c0862a1 100644 (file)
 
 package org.apache.poi.poifs.filesystem;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.poifs.common.POIFSConstants;
 import org.apache.poi.poifs.property.DocumentProperty;
@@ -105,7 +105,7 @@ public final class DocumentOutputStream extends OutputStream {
         }
 
         // Have an empty one created for now
-        return parent.createDocument(name, new ByteArrayInputStream(new byte[0]));
+        return parent.createDocument(name, new UnsynchronizedByteArrayInputStream(new byte[0]));
     }
 
     private void checkBufferSize() throws IOException {
index 049a80531898f53b31d37a1f8bdc2611c92173bb..71d6a4b4057fe340bb3c2d83b05117806071bb28 100644 (file)
@@ -21,7 +21,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
 import static org.apache.poi.util.StringUtil.endsWithIgnoreCase;
 import static org.apache.poi.util.StringUtil.startsWithIgnoreCase;
 
-import java.io.ByteArrayInputStream;
 import java.io.Closeable;
 import java.io.EOFException;
 import java.io.File;
@@ -37,6 +36,7 @@ import java.util.Map;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
+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;
@@ -232,7 +232,7 @@ public class VBAMacroReader implements Closeable {
         } else {
             // Decompress a previously found module and store the decompressed result into module.buf
             InputStream stream = new RLEDecompressingInputStream(
-                    new ByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset)
+                    new UnsynchronizedByteArrayInputStream(module.buf, moduleOffset, module.buf.length - moduleOffset)
             );
             module.read(stream);
             stream.close();
@@ -274,7 +274,7 @@ public class VBAMacroReader implements Closeable {
             }
 
             if (decompressedBytes != null) {
-                module.read(new ByteArrayInputStream(decompressedBytes));
+                module.read(new UnsynchronizedByteArrayInputStream(decompressedBytes));
             }
         }
 
@@ -802,7 +802,7 @@ public class VBAMacroReader implements Closeable {
                 if (w <= 0 || (w & 0x7000) != 0x3000) {
                     continue;
                 }
-                decompressed = tryToDecompress(new ByteArrayInputStream(compressed, i, compressed.length - i));
+                decompressed = tryToDecompress(new UnsynchronizedByteArrayInputStream(compressed, i, compressed.length - i));
                 if (decompressed != null) {
                     if (decompressed.length > 9) {
                         //this is a complete hack.  The challenge is that there
index 2b6a013e024f34683d4dd383e7f99f8d621e1c5f..45894428dddffd0452c9992c1d589e3c4cc12184 100644 (file)
@@ -20,7 +20,6 @@ import static org.apache.poi.util.Units.EMU_PER_PIXEL;
 
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
@@ -31,6 +30,7 @@ import javax.imageio.ImageIO;
 import javax.imageio.ImageReader;
 import javax.imageio.stream.ImageInputStream;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
@@ -151,7 +151,7 @@ public final class ImageUtils {
 
         // in pixel
         final Dimension imgSize = (scaleX == Double.MAX_VALUE || scaleY == Double.MAX_VALUE)
-            ? getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType())
+            ? getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType())
             : new Dimension();
 
         // in emus
@@ -191,7 +191,7 @@ public final class ImageUtils {
         Dimension imgSize = null;
         if (anchor.getCol2() < anchor.getCol1() || anchor.getRow2() < anchor.getRow1()) {
             PictureData data = picture.getPictureData();
-            imgSize = getImageDimension(new ByteArrayInputStream(data.getData()), data.getPictureType());
+            imgSize = getImageDimension(new UnsynchronizedByteArrayInputStream(data.getData()), data.getPictureType());
         }
 
         int w = getDimFromCell(imgSize == null ? 0 : imgSize.getWidth(), anchor.getCol1(), anchor.getDx1(), anchor.getCol2(), anchor.getDx2(),
index aa2211eb1ad101de73e676d2a7eab3bbbc003f01..b59950b96c84a6ced9cfa037d1910014e98f11e1 100644 (file)
 
 package org.apache.poi.util;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Locale;
 
+import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
 import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 
 /**
@@ -278,8 +278,8 @@ public class RLEDecompressingInputStream extends InputStream {
 
     public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException {
         try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
-            InputStream instream = new ByteArrayInputStream(compressed, offset, length);
-            InputStream stream = new RLEDecompressingInputStream(instream)) {
+             InputStream instream = new UnsynchronizedByteArrayInputStream(compressed, offset, length);
+             InputStream stream = new RLEDecompressingInputStream(instream)) {
 
             IOUtils.copy(stream, out);
             return out.toByteArray();