From: PJ Fanning Date: Sat, 28 Aug 2021 09:13:21 +0000 (+0000) Subject: more use of commons-io X-Git-Tag: REL_5_1_0~15 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1e6416551e9eec93a9ccaa30d1f6b9cd04ed4fae;p=poi.git more use of commons-io git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892669 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java b/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java index 324fb4b4c9..5237309c9c 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java +++ b/poi/src/main/java/org/apache/poi/hpsf/PropertySet.java @@ -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()); } /** diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java index e45d0c3cf4..d90aa2ed6c 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java @@ -18,11 +18,11 @@ */ 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; } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java b/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java index f03028d823..a4cb805e03 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/DrawingRecordForBiffViewer.java @@ -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; diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java index f43bf9ed52..5aeef7dfb4 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java @@ -17,10 +17,10 @@ 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); diff --git a/poi/src/main/java/org/apache/poi/hssf/record/Record.java b/poi/src/main/java/org/apache/poi/hssf/record/Record.java index ede39a04f2..3ae5c1b312 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/Record.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/Record.java @@ -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); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java index bd45096234..29b163ce67 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFPicture.java @@ -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); } /** diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 136b02b75b..548e8c0279 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -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 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); diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java index ec15c11446..e848859a00 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/DocumentOutputStream.java @@ -17,10 +17,10 @@ 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 { diff --git a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java index 049a805318..71d6a4b405 100644 --- a/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java +++ b/poi/src/main/java/org/apache/poi/poifs/macros/VBAMacroReader.java @@ -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 diff --git a/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java b/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java index 2b6a013e02..45894428dd 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java +++ b/poi/src/main/java/org/apache/poi/ss/util/ImageUtils.java @@ -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(), diff --git a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java index aa2211eb1a..b59950b96c 100644 --- a/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java +++ b/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java @@ -17,11 +17,11 @@ 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();