You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2021/05/14 00:37:53 UTC

svn commit: r1889871 [14/17] - in /poi: site/src/documentation/content/xdocs/ site/src/documentation/content/xdocs/components/ trunk/ trunk/maven/ trunk/osgi/ trunk/osgi/src/test/java/org/apache/poi/osgi/ trunk/poi-examples/src/main/java/org/apache/poi...

Modified: poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/sl/usermodel/ObjectShape.java Fri May 14 00:37:50 2021
@@ -17,12 +17,11 @@
 
 package org.apache.poi.sl.usermodel;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
 import org.apache.poi.poifs.filesystem.FileMagic;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@@ -54,7 +53,7 @@ public interface ObjectShape<
      * @return the ProgID
      */
     String getProgId();
-    
+
     /**
      * Returns the full name of the embedded object,
      *  e.g. "Microsoft Word Document" or "Microsoft Office Excel Worksheet".
@@ -62,11 +61,11 @@ public interface ObjectShape<
      * @return the full name of the embedded object
      */
     String getFullName();
-    
+
     /**
      * Updates the ole data. If there wasn't an object registered before, a new
      * ole embedding is registered in the parent slideshow.<p>
-     * 
+     *
      * For HSLF this needs to be a {@link POIFSFileSystem} stream.
      *
      * @param application a preset application enum
@@ -81,10 +80,10 @@ public interface ObjectShape<
     /**
      * Reads the ole data as stream - the application specific stream is served
      * The {@link #readObjectDataRaw() raw data} serves the outer/wrapped object, which is usually a
-     * {@link POIFSFileSystem} stream, whereas this method return the unwrapped entry 
+     * {@link POIFSFileSystem} stream, whereas this method return the unwrapped entry
      *
      * @return an {@link InputStream} which serves the object data
-     * 
+     *
      * @throws IOException if the linked object data couldn't be found
      */
     default InputStream readObjectData() throws IOException {
@@ -97,8 +96,9 @@ public interface ObjectShape<
 
         final Application app = Application.lookup(progId);
 
-        final ByteArrayOutputStream bos = new ByteArrayOutputStream(50000);
-        try (final InputStream is = FileMagic.prepareToCheckMagic(readObjectDataRaw())) {
+        try (final UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+             final InputStream is = FileMagic.prepareToCheckMagic(readObjectDataRaw())) {
+
             final FileMagic fm = FileMagic.valueOf(is);
             if (fm == FileMagic.OLE2) {
                 try (final POIFSFileSystem poifs = new POIFSFileSystem(is)) {
@@ -129,11 +129,10 @@ public interface ObjectShape<
             } else {
                 IOUtils.copy(is, bos);
             }
+            return bos.toInputStream();
         }
-
-        return new ByteArrayInputStream(bos.toByteArray());
     }
-    
+
     /**
      * Convenience method to return the raw data as {@code InputStream}
      *

Modified: poi/trunk/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java Fri May 14 00:37:50 2021
@@ -19,7 +19,6 @@ package org.apache.poi.ss.extractor;
 
 import static org.apache.poi.util.StringUtil.endsWithIgnoreCase;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -28,6 +27,7 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.poi.hpsf.ClassID;
@@ -162,7 +162,7 @@ public class EmbeddedExtractor implement
 
     protected EmbeddedData extract(DirectoryNode dn) throws IOException {
         assert(canExtract(dn));
-        ByteArrayOutputStream bos = new ByteArrayOutputStream(20000);
+        UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(20000);
         try (POIFSFileSystem dest = new POIFSFileSystem()) {
             copyNodes(dn, dest.getRoot());
             // start with a reasonable big size
@@ -204,7 +204,7 @@ public class EmbeddedExtractor implement
 
         @Override
         public EmbeddedData extract(DirectoryNode dn) throws IOException {
-            try(ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            try(UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
                 InputStream is = dn.createDocumentInputStream("CONTENTS")) {
                 IOUtils.copy(is, bos);
                 return new EmbeddedData(dn.getName() + ".pdf", bos.toByteArray(), CONTENT_TYPE_PDF);

Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordJsonWriter.java Fri May 14 00:37:50 2021
@@ -19,6 +19,8 @@
 
 package org.apache.poi.util;
 
+import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
+
 import java.awt.Color;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Dimension2D;
@@ -115,7 +117,7 @@ public class GenericRecordJsonWriter imp
     protected int childIndex = 0;
 
     public GenericRecordJsonWriter(File fileName) throws IOException {
-        OutputStream os = ("null".equals(fileName.getName())) ? new NullOutputStream() : new FileOutputStream(fileName);
+        OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName);
         aw = new AppendableWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
         fw = new PrintWriter(aw);
     }
@@ -531,23 +533,6 @@ public class GenericRecordJsonWriter imp
         return ZEROS.substring(0, Math.max(0,size-len)) + b.substring(Math.max(0,len-size), len);
     }
 
-    static class NullOutputStream extends OutputStream {
-        NullOutputStream() {
-        }
-
-        @Override
-        public void write(byte[] b, int off, int len) {
-        }
-
-        @Override
-        public void write(int b) {
-        }
-
-        @Override
-        public void write(byte[] b) {
-        }
-    }
-
     static class AppendableWriter extends Writer {
         private final Appendable appender;
         private final Writer writer;

Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/GenericRecordXmlWriter.java Fri May 14 00:37:50 2021
@@ -19,6 +19,8 @@
 
 package org.apache.poi.util;
 
+import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
+
 import java.awt.Color;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Dimension2D;
@@ -50,7 +52,6 @@ import java.util.stream.Stream;
 
 import org.apache.poi.common.usermodel.GenericRecord;
 import org.apache.poi.util.GenericRecordJsonWriter.AppendableWriter;
-import org.apache.poi.util.GenericRecordJsonWriter.NullOutputStream;
 
 @SuppressWarnings("WeakerAccess")
 public class GenericRecordXmlWriter implements Closeable {
@@ -73,7 +74,7 @@ public class GenericRecordXmlWriter impl
         boolean print(GenericRecordXmlWriter record, String name, Object object);
     }
 
-    private static final List<Map.Entry<Class, GenericRecordHandler>> handler = new ArrayList<>();
+    private static final List<Map.Entry<Class<?>, GenericRecordHandler>> handler = new ArrayList<>();
 
     static {
         char[] t = new char[255];
@@ -97,7 +98,7 @@ public class GenericRecordXmlWriter impl
         handler(Object.class, GenericRecordXmlWriter::printObject);
     }
 
-    private static void handler(Class c, GenericRecordHandler printer) {
+    private static void handler(Class<?> c, GenericRecordHandler printer) {
         handler.add(new AbstractMap.SimpleEntry<>(c, printer));
     }
 
@@ -108,7 +109,7 @@ public class GenericRecordXmlWriter impl
     private boolean attributePhase = true;
 
     public GenericRecordXmlWriter(File fileName) throws IOException {
-        OutputStream os = ("null".equals(fileName.getName())) ? new NullOutputStream() : new FileOutputStream(fileName);
+        OutputStream os = ("null".equals(fileName.getName())) ? NULL_OUTPUT_STREAM : new FileOutputStream(fileName);
         fw = new PrintWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
     }
 
@@ -150,10 +151,10 @@ public class GenericRecordXmlWriter impl
 
     protected void write(final String name, GenericRecord record) {
         final String tabs = tabs();
-        Enum type = record.getGenericRecordType();
+        Enum<?> type = record.getGenericRecordType();
         String recordName = (type != null) ? type.name() : record.getClass().getSimpleName();
         fw.append(tabs);
-        fw.append("<"+name+" type=\"");
+        fw.append("<").append(name).append(" type=\"");
         fw.append(recordName);
         fw.append("\"");
         if (childIndex > 0) {
@@ -279,7 +280,7 @@ public class GenericRecordXmlWriter impl
         }
     }
 
-    protected static boolean matchInstanceOrArray(Class key, Object instance) {
+    protected static boolean matchInstanceOrArray(Class<?> key, Object instance) {
         return key.isInstance(instance) || (Array.class.equals(key) && instance.getClass().isArray());
     }
 
@@ -332,8 +333,7 @@ public class GenericRecordXmlWriter impl
         openName(name+">");
         int oldChildIndex = childIndex;
         childIndex = 0;
-        //noinspection unchecked
-        ((List)o).forEach(e -> { writeValue("item>", e); childIndex++; });
+        ((List<?>)o).forEach(e -> { writeValue("item>", e); childIndex++; });
         childIndex = oldChildIndex;
         closeName(name+">");
         return true;
@@ -478,7 +478,7 @@ public class GenericRecordXmlWriter impl
                 case "&":
                     fw.write("&amp;");
                     break;
-                case "\'":
+                case "'":
                     fw.write("&apos;");
                     break;
                 case "\"":

Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/IOUtils.java Fri May 14 00:37:50 2021
@@ -17,7 +17,6 @@
 
 package org.apache.poi.util;
 
-import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.EOFException;
 import java.io.File;
@@ -33,6 +32,8 @@ import java.util.Locale;
 import java.util.zip.CRC32;
 import java.util.zip.Checksum;
 
+import org.apache.commons.io.input.BoundedInputStream;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.poi.EmptyFileException;
@@ -106,7 +107,7 @@ public final class IOUtils {
         checkByteSizeLimit(limit);
 
         stream.mark(limit);
-        ByteArrayOutputStream bos = new ByteArrayOutputStream(limit);
+        UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(limit);
         copy(new BoundedInputStream(stream, limit), bos);
 
         int readBytes = bos.size();
@@ -177,7 +178,7 @@ public final class IOUtils {
         }
 
         final int len = Math.min(length, maxLength);
-        ByteArrayOutputStream baos = new ByteArrayOutputStream(len == Integer.MAX_VALUE ? 4096 : len);
+        UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(len == Integer.MAX_VALUE ? 4096 : len);
 
         byte[] buffer = new byte[4096];
         int totalBytes = 0, readBytes;

Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java Fri May 14 00:37:50 2021
@@ -16,11 +16,12 @@
 ==================================================================== */
 package org.apache.poi.util;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+
 /**
  * This class provides common functionality for the
  * various LZW implementations in the different file
@@ -86,7 +87,7 @@ public abstract class LZWDecompresser {
      * of the decompressed input.
      */
     public byte[] decompress(InputStream src) throws IOException {
-        ByteArrayOutputStream res = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream res = new UnsynchronizedByteArrayOutputStream();
         decompress(src, res);
         return res.toByteArray();
     }

Modified: poi/trunk/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/util/RLEDecompressingInputStream.java Fri May 14 00:37:50 2021
@@ -18,11 +18,12 @@
 package org.apache.poi.util;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Locale;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+
 /**
  * Wrapper of InputStream which provides Run Length Encoding (RLE)
  *  decompression on the fly. Uses MS-OVBA decompression algorithm. See
@@ -68,7 +69,6 @@ public class RLEDecompressingInputStream
      * Creates a new wrapper RLE Decompression InputStream.
      *
      * @param in The stream to wrap with the RLE Decompression
-     * @throws IOException
      */
     public RLEDecompressingInputStream(InputStream in) throws IOException {
         this.in = in;
@@ -152,7 +152,6 @@ public class RLEDecompressingInputStream
      * Reads a single chunk from the underlying inputstream.
      *
      * @return number of bytes that were read, or -1 if the end of the stream was reached.
-     * @throws IOException
      */
     private int readChunk() throws IOException {
         pos = 0;
@@ -216,7 +215,6 @@ public class RLEDecompressingInputStream
     /**
      * Helper method to determine how many bits in the CopyToken are used for the CopyLength.
      *
-     * @param offset
      * @return returns the number of bits in the copy token (a value between 4 and 12)
      */
     static int getCopyLenBits(int offset) {
@@ -232,7 +230,6 @@ public class RLEDecompressingInputStream
      * Convenience method for read a 2-bytes short in little endian encoding.
      *
      * @return short value from the stream, -1 if end of stream is reached
-     * @throws IOException
      */
     public int readShort() throws IOException {
         return readShort(this);
@@ -242,7 +239,6 @@ public class RLEDecompressingInputStream
      * Convenience method for read a 4-bytes int in little endian encoding.
      *
      * @return integer value from the stream, -1 if end of stream is reached
-     * @throws IOException
      */
     public int readInt() throws IOException {
         return readInt(this);
@@ -281,12 +277,12 @@ public class RLEDecompressingInputStream
     }
 
     public static byte[] decompress(byte[] compressed, int offset, int length) throws IOException {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        InputStream instream = new ByteArrayInputStream(compressed, offset, length);
-        InputStream stream = new RLEDecompressingInputStream(instream);
-        IOUtils.copy(stream, out);
-        stream.close();
-        out.close();
-        return out.toByteArray();
+        try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+            InputStream instream = new ByteArrayInputStream(compressed, offset, length);
+            InputStream stream = new RLEDecompressingInputStream(instream)) {
+
+            IOUtils.copy(stream, out);
+            return out.toByteArray();
+        }
     }
 }

Modified: poi/trunk/poi/src/test/java/org/apache/poi/POIDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/POIDataSamples.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/POIDataSamples.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/POIDataSamples.java Fri May 14 00:37:50 2021
@@ -16,13 +16,16 @@
 ==================================================================== */
 package org.apache.poi;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.util.IOUtils;
+
 /**
  * Centralises logic for finding/opening sample files
  */
@@ -47,7 +50,7 @@ public final class POIDataSamples {
     private static POIDataSamples _instXmlDSign;
 
     private File _resolvedDataDir;
-    /** {@code true} if standard system propery is not set,
+    /** {@code true} if standard system property is not set,
      * but the data is available on the test runtime classpath */
     private boolean _sampleDataIsAvaliableOnClassPath;
     private final String _moduleDir;
@@ -260,24 +263,19 @@ public final class POIDataSamples {
      * @return byte array of sample file content from file found in standard test-data directory
      */
     public byte[] readFile(String fileName) {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-
-        try {
-            InputStream fis = openResourceAsStream(fileName);
-
-            byte[] buf = new byte[512];
-            while (true) {
-                int bytesRead = fis.read(buf);
-                if (bytesRead < 1) {
-                    break;
-                }
-                bos.write(buf, 0, bytesRead);
-            }
-            fis.close();
+        try (InputStream fis = openResourceAsStream(fileName);
+             UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()) {
+            IOUtils.copy(fis, bos);
+            return bos.toByteArray();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
-        return bos.toByteArray();
     }
 
+    public static POIFSFileSystem writeOutAndReadBack(POIFSFileSystem original) throws IOException {
+        try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+            original.writeFilesystem(baos);
+            return new POIFSFileSystem(baos.toInputStream());
+        }
+    }
 }

Modified: poi/trunk/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/TestPOIDocumentMain.java Fri May 14 00:37:50 2021
@@ -17,21 +17,20 @@
 
 package org.apache.poi;
 
+import static org.apache.poi.hssf.HSSFTestDataSamples.openSampleWorkbook;
+import static org.apache.poi.hssf.HSSFTestDataSamples.writeOutAndReadBack;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
 import org.apache.poi.hpsf.SummaryInformation;
-import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -42,22 +41,11 @@ import org.junit.jupiter.api.Test;
  *  which are part of the Main (not scratchpad)
  */
 final class TestPOIDocumentMain {
-    // The POI Documents to work on
-    private POIDocument doc;
-    private POIDocument doc2;
-
-    /**
-     * Set things up, two spreadsheets for our testing
-     */
-    @BeforeEach
-    void setUp() {
-        doc = HSSFTestDataSamples.openSampleWorkbook("DateFormats.xls");
-        doc2 = HSSFTestDataSamples.openSampleWorkbook("StringFormulas.xls");
-    }
-
     @Test
-    void readProperties() {
-        readPropertiesHelper(doc);
+    void readProperties() throws IOException {
+        try (POIDocument xls = openSampleWorkbook("DateFormats.xls")) {
+            readPropertiesHelper(xls);
+        }
     }
 
     private void readPropertiesHelper(POIDocument docWB) {
@@ -71,130 +59,108 @@ final class TestPOIDocumentMain {
     }
 
     @Test
-    void readProperties2() {
-        // Check again on the word one
-        assertNotNull(doc2.getDocumentSummaryInformation());
-        assertNotNull(doc2.getSummaryInformation());
-
-        assertEquals("Avik Sengupta", doc2.getSummaryInformation().getAuthor());
-        assertNull(doc2.getSummaryInformation().getKeywords());
-        assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
+    void readProperties2() throws IOException {
+        try (POIDocument xls = openSampleWorkbook("StringFormulas.xls")) {
+            // Check again on the word one
+            assertNotNull(xls.getDocumentSummaryInformation());
+            assertNotNull(xls.getSummaryInformation());
+
+            assertEquals("Avik Sengupta", xls.getSummaryInformation().getAuthor());
+            assertNull(xls.getSummaryInformation().getKeywords());
+            assertEquals(0, xls.getDocumentSummaryInformation().getByteCount());
+        }
     }
 
     @Test
     void writeProperties() throws IOException {
         // Just check we can write them back out into a filesystem
-        POIFSFileSystem outFS = new POIFSFileSystem();
-        doc.readProperties();
-        doc.writeProperties(outFS);
-
-        // Should now hold them
-        assertNotNull(
-                outFS.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME)
-        );
-        assertNotNull(
-                outFS.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME)
-        );
+        try (POIDocument xls = openSampleWorkbook("DateFormats.xls");
+             POIFSFileSystem outFS = new POIFSFileSystem()) {
+            xls.readProperties();
+            xls.writeProperties(outFS);
+
+            // Should now hold them
+            assertNotNull(outFS.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
+            assertNotNull(outFS.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME));
+        }
     }
 
     @Test
     void WriteReadProperties() throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
 
         // Write them out
-        POIFSFileSystem outFS = new POIFSFileSystem();
-        doc.readProperties();
-        doc.writeProperties(outFS);
-        outFS.writeFilesystem(baos);
+        try (POIDocument xls = openSampleWorkbook("DateFormats.xls");
+             POIFSFileSystem outFS = new POIFSFileSystem()) {
+            xls.readProperties();
+            xls.writeProperties(outFS);
+            outFS.writeFilesystem(baos);
+        }
 
         // Create a new version
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        POIFSFileSystem inFS = new POIFSFileSystem(bais);
+        try (POIFSFileSystem inFS = new POIFSFileSystem(baos.toInputStream());
+             POIDocument doc3 = new HPSFPropertiesOnlyDocument(inFS)) {
+
+            // Check they're still there
+            doc3.readProperties();
 
-        // Check they're still there
-        POIDocument doc3 = new HPSFPropertiesOnlyDocument(inFS);
-        doc3.readProperties();
-
-        // Delegate test
-        readPropertiesHelper(doc3);
-        doc3.close();
+            // Delegate test
+            readPropertiesHelper(doc3);
+        }
     }
 
     @Test
     void createNewProperties() throws IOException {
-        POIDocument doc = new HSSFWorkbook();
-
-        // New document won't have them
-        assertNull(doc.getSummaryInformation());
-        assertNull(doc.getDocumentSummaryInformation());
-
-        // Add them in
-        doc.createInformationProperties();
-        assertNotNull(doc.getSummaryInformation());
-        assertNotNull(doc.getDocumentSummaryInformation());
-
-        // Write out and back in again, no change
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        doc.write(baos);
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        try (HSSFWorkbook xls1 = new HSSFWorkbook()) {
+            // New document won't have them
+            assertNull(xls1.getSummaryInformation());
+            assertNull(xls1.getDocumentSummaryInformation());
+
+            // Add them in
+            xls1.createInformationProperties();
+            assertNotNull(xls1.getSummaryInformation());
+            assertNotNull(xls1.getDocumentSummaryInformation());
+
+            try (HSSFWorkbook xls2 = writeOutAndReadBack(xls1)) {
+                assertNotNull(xls2.getSummaryInformation());
+                assertNotNull(xls2.getDocumentSummaryInformation());
+            }
+        }
 
-        doc.close();
-
-        doc = new HSSFWorkbook(bais);
-
-        assertNotNull(doc.getSummaryInformation());
-        assertNotNull(doc.getDocumentSummaryInformation());
-
-        doc.close();
     }
 
     @Test
     void createNewPropertiesOnExistingFile() throws IOException {
-        POIDocument doc = new HSSFWorkbook();
-
-        // New document won't have them
-        assertNull(doc.getSummaryInformation());
-        assertNull(doc.getDocumentSummaryInformation());
-
-        // Write out and back in again, no change
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        doc.write(baos);
-
-        doc.close();
-
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-        doc = new HSSFWorkbook(bais);
-
-        assertNull(doc.getSummaryInformation());
-        assertNull(doc.getDocumentSummaryInformation());
-
-        // Create, and change
-        doc.createInformationProperties();
-        doc.getSummaryInformation().setAuthor("POI Testing");
-        doc.getDocumentSummaryInformation().setCompany("ASF");
-
-        // Save and re-load
-        baos = new ByteArrayOutputStream();
-        doc.write(baos);
-
-        doc.close();
-
-        bais = new ByteArrayInputStream(baos.toByteArray());
-        doc = new HSSFWorkbook(bais);
-
-        // Check
-        assertNotNull(doc.getSummaryInformation());
-        assertNotNull(doc.getDocumentSummaryInformation());
-        assertEquals("POI Testing", doc.getSummaryInformation().getAuthor());
-        assertEquals("ASF", doc.getDocumentSummaryInformation().getCompany());
-
-        // Asking to re-create will make no difference now
-        doc.createInformationProperties();
-        assertNotNull(doc.getSummaryInformation());
-        assertNotNull(doc.getDocumentSummaryInformation());
-        assertEquals("POI Testing", doc.getSummaryInformation().getAuthor());
-        assertEquals("ASF", doc.getDocumentSummaryInformation().getCompany());
-
-        doc.close();
+        try (HSSFWorkbook xls1 = new HSSFWorkbook()) {
+            // New document won't have them
+            assertNull(xls1.getSummaryInformation());
+            assertNull(xls1.getDocumentSummaryInformation());
+
+            try (HSSFWorkbook xls2 = writeOutAndReadBack(xls1)) {
+
+                assertNull(xls2.getSummaryInformation());
+                assertNull(xls2.getDocumentSummaryInformation());
+
+                // Create, and change
+                xls2.createInformationProperties();
+                xls2.getSummaryInformation().setAuthor("POI Testing");
+                xls2.getDocumentSummaryInformation().setCompany("ASF");
+
+                try (HSSFWorkbook xls3 = writeOutAndReadBack(xls2)) {
+                    // Check
+                    assertNotNull(xls3.getSummaryInformation());
+                    assertNotNull(xls3.getDocumentSummaryInformation());
+                    assertEquals("POI Testing", xls3.getSummaryInformation().getAuthor());
+                    assertEquals("ASF", xls3.getDocumentSummaryInformation().getCompany());
+
+                    // Asking to re-create will make no difference now
+                    xls3.createInformationProperties();
+                    assertNotNull(xls3.getSummaryInformation());
+                    assertNotNull(xls3.getDocumentSummaryInformation());
+                    assertEquals("POI Testing", xls3.getSummaryInformation().getAuthor());
+                    assertEquals("ASF", xls3.getDocumentSummaryInformation().getCompany());
+                }
+            }
+        }
     }
 }

Modified: poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherBlipRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherBlipRecord.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherBlipRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherBlipRecord.java Fri May 14 00:37:50 2021
@@ -17,6 +17,7 @@
 
 package org.apache.poi.ddf;
 
+import static org.apache.poi.ddf.EscherRecordTypes.BLIP_PICT;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -100,7 +101,7 @@ final class TestEscherBlipRecord {
 
         EscherMetafileBlip blip1 = (EscherMetafileBlip)bse1.getBlipRecord();
         assertEquals(0x5430, blip1.getOptions());
-        assertEquals(EscherMetafileBlip.RECORD_ID_PICT, blip1.getRecordId());
+        assertEquals(BLIP_PICT.typeID, blip1.getRecordId());
         assertArrayEquals(new byte[]{
             0x57, 0x32, 0x7B, (byte)0x91, 0x23, 0x5D, (byte)0xDB, 0x36,
             0x7A, (byte)0xDB, (byte)0xFF, 0x17, (byte)0xFE, (byte)0xF3, (byte)0xA7, 0x05
@@ -151,11 +152,13 @@ final class TestEscherBlipRecord {
         byte[] data = _samples.readFile("47143.dat");
         EscherBSERecord bse = new EscherBSERecord();
         bse.fillFields(data, 0, new DefaultEscherRecordFactory());
-        bse.toString(); //assert that toString() works
+        //assert that toString() works
+        assertNotNull(bse.toString());
         assertTrue(bse.getBlipRecord() instanceof EscherMetafileBlip);
 
         EscherMetafileBlip blip = (EscherMetafileBlip)bse.getBlipRecord();
-        blip.toString(); //assert that toString() works
+        //assert that toString() works
+        assertNotNull(blip.toString());
         byte[] remaining = blip.getRemainingData();
         assertNotNull(remaining);
 

Modified: poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/ddf/TestEscherDump.java Fri May 14 00:37:50 2021
@@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
@@ -29,6 +28,7 @@ import java.nio.charset.StandardCharsets
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.storage.RawDataUtil;
@@ -63,8 +63,8 @@ class TestEscherDump {
         "cT19LR+PfTgjN4CKCS5Es4LS+7nLt9hQ7ejwGQnEyxebOgJzlHjotWUACpoZsFkAgGqBeUDZAzB6h4N2MFCNhmIuFJMAgPsH" +
         "eJr+iZEHAAA=";
 
-    private EscherDump dumper = new EscherDump();
-    private ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    private final EscherDump dumper = new EscherDump();
+    private final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
     private PrintStream stream;
 
     @BeforeEach
@@ -126,7 +126,7 @@ class TestEscherDump {
     }
 
     private int countProperties() {
-        String data = new String(baos.toByteArray(), StandardCharsets.UTF_8);
+        String data = baos.toString(StandardCharsets.UTF_8);
         Matcher matcher = Pattern.compile(",? \"[^\"]+\": ").matcher(data);
         int count = 0;
         while (matcher.find()) {

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/TestVariantSupport.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/TestVariantSupport.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/TestVariantSupport.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/TestVariantSupport.java Fri May 14 00:37:50 2021
@@ -21,11 +21,12 @@ package org.apache.poi.hpsf;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.math.BigInteger;
 
+import org.apache.poi.POIDataSamples;
 import org.apache.poi.hpsf.wellknown.PropertyIDMap;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.poifs.storage.RawDataUtil;
@@ -51,7 +52,7 @@ class TestVariantSupport {
 
         Object hdrs =  s.getProperty(PropertyIDMap.PID_HEADINGPAIR);
         assertNotNull(hdrs);
-        assertEquals(byte[].class, hdrs.getClass());
+        assertSame(byte[].class, hdrs.getClass());
 
         // parse the value
         Vector v = new Vector((short)Variant.VT_VARIANT);
@@ -63,10 +64,10 @@ class TestVariantSupport {
 
         Object cp = items[0].getValue();
         assertNotNull(cp);
-        assertEquals(CodePageString.class, cp.getClass());
+        assertSame(CodePageString.class, cp.getClass());
         Object i = items[1].getValue();
         assertNotNull(i);
-        assertEquals(Integer.class, i.getClass());
+        assertSame(Integer.class, i.getClass());
         assertEquals(1, i);
 
     }
@@ -91,34 +92,33 @@ class TestVariantSupport {
                 {Variant.VT_R8, -999.99d},
         };
 
-        POIFSFileSystem poifs = new POIFSFileSystem();
-        DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
-        CustomProperties cpList = new CustomProperties();
-        for (Object[] o : exp) {
-            int type = (Integer)o[0];
-            Property p = new Property(PropertyIDMap.PID_MAX+type, type, o[1]);
-            cpList.put("testprop"+type, new CustomProperty(p, "testprop"+type));
+        try (POIFSFileSystem poifs = new POIFSFileSystem()) {
+            DocumentSummaryInformation dsi = PropertySetFactory.newDocumentSummaryInformation();
+            CustomProperties cpList = new CustomProperties();
+            for (Object[] o : exp) {
+                int type = (Integer) o[0];
+                Property p = new Property(PropertyIDMap.PID_MAX + type, type, o[1]);
+                cpList.put("testprop" + type, new CustomProperty(p, "testprop" + type));
 
-        }
-        dsi.setCustomProperties(cpList);
-        dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        poifs.writeFilesystem(bos);
-        poifs.close();
-        poifs = new POIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
-        dsi = (DocumentSummaryInformation)PropertySetFactory.create(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
-        assertNotNull(dsi);
-        cpList = dsi.getCustomProperties();
-        int i=0;
-        for (Object[] o : exp) {
-            Object obj = cpList.get("testprop"+o[0]);
-            if (o[1] instanceof byte[]) {
-                assertArrayEquals((byte[])o[1], (byte[])obj, "property "+i);
-            } else {
-                assertEquals(o[1], obj, "property "+i);
             }
-            i++;
+            dsi.setCustomProperties(cpList);
+            dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+
+            try (POIFSFileSystem poifs2 = POIDataSamples.writeOutAndReadBack(poifs)) {
+                DocumentSummaryInformation dsi2 = (DocumentSummaryInformation) PropertySetFactory.create(poifs2.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+                assertNotNull(dsi2);
+                CustomProperties cpList2 = dsi2.getCustomProperties();
+                int i = 0;
+                for (Object[] o : exp) {
+                    Object obj = cpList2.get("testprop" + o[0]);
+                    if (o[1] instanceof byte[]) {
+                        assertArrayEquals((byte[]) o[1], (byte[]) obj, "property " + i);
+                    } else {
+                        assertEquals(o[1], obj, "property " + i);
+                    }
+                    i++;
+                }
+            }
         }
-        poifs.close();
     }
 }

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestBasic.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestBasic.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestBasic.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestBasic.java Fri May 14 00:37:50 2021
@@ -19,6 +19,7 @@ package org.apache.poi.hpsf.basic;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
@@ -35,7 +36,6 @@ import org.apache.poi.hpsf.ClassID;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.Filetime;
 import org.apache.poi.hpsf.HPSFException;
-import org.apache.poi.hpsf.MarkUnsupportedException;
 import org.apache.poi.hpsf.NoPropertySetStreamException;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.PropertySetFactory;
@@ -109,8 +109,7 @@ final class TestBasic {
      * supported.
      */
     @Test
-    void testCreatePropertySets()
-    throws UnsupportedEncodingException, IOException {
+    void testCreatePropertySets() throws IOException {
         Class<?>[] expected = {
             SummaryInformation.class,
             DocumentSummaryInformation.class,
@@ -123,11 +122,11 @@ final class TestBasic {
             Object o;
             try {
                 o = PropertySetFactory.create(in);
-            } catch (NoPropertySetStreamException | MarkUnsupportedException ex) {
+            } catch (NoPropertySetStreamException ex) {
                 o = ex;
             }
             in.close();
-            assertEquals(expected[i], o.getClass());
+            assertSame(expected[i], o.getClass());
         }
     }
 

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestEmptyProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestEmptyProperties.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestEmptyProperties.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestEmptyProperties.java Fri May 14 00:37:50 2021
@@ -20,6 +20,7 @@ package org.apache.poi.hpsf.basic;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -32,7 +33,6 @@ import java.util.List;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFException;
-import org.apache.poi.hpsf.MarkUnsupportedException;
 import org.apache.poi.hpsf.NoPropertySetStreamException;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.PropertySetFactory;
@@ -101,8 +101,7 @@ final class TestEmptyProperties {
      * supported.
      */
     @Test
-    void testCreatePropertySets()
-    throws UnsupportedEncodingException, IOException {
+    void testCreatePropertySets() throws IOException {
         Class<?>[] expected =  {
             NoPropertySetStreamException.class,
             SummaryInformation.class,
@@ -113,11 +112,11 @@ final class TestEmptyProperties {
             Object o;
             try {
                 o = PropertySetFactory.create(in);
-            } catch (NoPropertySetStreamException | MarkUnsupportedException ex) {
+            } catch (NoPropertySetStreamException ex) {
                 o = ex;
             }
             in.close();
-            assertEquals(o.getClass(), expected[i]);
+            assertSame(o.getClass(), expected[i]);
         }
     }
 

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestHPSFBugs.java Fri May 14 00:37:50 2021
@@ -21,17 +21,15 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.POIDocument;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFPropertiesOnlyDocument;
-import org.apache.poi.hpsf.MarkUnsupportedException;
 import org.apache.poi.hpsf.NoPropertySetStreamException;
 import org.apache.poi.hpsf.PropertySetFactory;
 import org.apache.poi.hpsf.SummaryInformation;
@@ -112,38 +110,37 @@ final class TestHPSFBugs {
     * reading junk
     */
    @Test
-   void test54233() throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
-       InputStream is = _samples.openResourceAsStream("TestNon4ByteBoundary.doc");
-       POIFSFileSystem fs = new POIFSFileSystem(is);
-       is.close();
-
-       SummaryInformation si = (SummaryInformation)
-           PropertySetFactory.create(fs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
-       DocumentSummaryInformation dsi = (DocumentSummaryInformation)
-           PropertySetFactory.create(fs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
-
-       // Test
-       assertEquals("Microsoft Word 10.0", si.getApplicationName());
-       assertEquals("", si.getTitle());
-       assertEquals("", si.getAuthor());
-       assertEquals("Cour de Justice", dsi.getCompany());
-
-
-       // Write out and read back, should still be valid
-       POIDocument doc = new HPSFPropertiesOnlyDocument(fs);
-       ByteArrayOutputStream baos = new ByteArrayOutputStream();
-       doc.write(baos);
-       ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-       doc = new HPSFPropertiesOnlyDocument(new POIFSFileSystem(bais));
-
-       // Check properties are still there
-       assertEquals("Microsoft Word 10.0", si.getApplicationName());
-       assertEquals("", si.getTitle());
-       assertEquals("", si.getAuthor());
-       assertEquals("Cour de Justice", dsi.getCompany());
-
-       doc.close();
-       fs.close();
+   void test54233() throws IOException, NoPropertySetStreamException {
+       try (InputStream is = _samples.openResourceAsStream("TestNon4ByteBoundary.doc");
+        POIFSFileSystem fs = new POIFSFileSystem(is)) {
+
+           SummaryInformation si = (SummaryInformation)
+               PropertySetFactory.create(fs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
+           DocumentSummaryInformation dsi = (DocumentSummaryInformation)
+               PropertySetFactory.create(fs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
+
+           // Test
+           assertEquals("Microsoft Word 10.0", si.getApplicationName());
+           assertEquals("", si.getTitle());
+           assertEquals("", si.getAuthor());
+           assertEquals("Cour de Justice", dsi.getCompany());
+
+
+           // Write out and read back, should still be valid
+           UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+           try (POIDocument doc = new HPSFPropertiesOnlyDocument(fs)) {
+               doc.write(baos);
+           }
+           try (POIDocument doc = new HPSFPropertiesOnlyDocument(new POIFSFileSystem(baos.toInputStream()))) {
+               si = doc.getSummaryInformation();
+               dsi = doc.getDocumentSummaryInformation();
+               // Check properties are still there
+               assertEquals("Microsoft Word 10.0", si.getApplicationName());
+               assertEquals("", si.getTitle());
+               assertEquals("", si.getAuthor());
+               assertEquals("Cour de Justice", dsi.getCompany());
+           }
+       }
    }
 
    /**

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestMetaDataIPI.java Fri May 14 00:37:50 2021
@@ -23,13 +23,12 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Date;
 import java.util.Random;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.hpsf.CustomProperties;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFException;
@@ -44,7 +43,7 @@ import org.junit.jupiter.api.Test;
 /**
  * Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java
  * This class tests reading and writing of meta data. No actual document is created. All information
- * is stored in a virtual document in a ByteArrayOutputStream
+ * is stored in a virtual document in a UnsynchronizedByteArrayOutputStream
  */
 final class TestMetaDataIPI {
 
@@ -520,7 +519,7 @@ final class TestMetaDataIPI {
 
 
     /**
-     * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream.
+     * Closes the UnsynchronizedByteArrayOutputStream and reads it into a ByteArrayInputStream.
      * When finished writing information this method is used in the tests to
      * start reading from the created document and then the see if the results match.
      */
@@ -528,13 +527,13 @@ final class TestMetaDataIPI {
         dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
         si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
 
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream bout = new UnsynchronizedByteArrayOutputStream();
         poifs.writeFilesystem(bout);
         poifs.close();
 
-        InputStream is = new ByteArrayInputStream(bout.toByteArray());
-        poifs = new POIFSFileSystem(is);
-        is.close();
+        try (InputStream is = bout.toInputStream()) {
+			poifs = new POIFSFileSystem(is);
+		}
 
         /* Read the document summary information. */
         DirectoryEntry dir = poifs.getRoot();

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestReadAllFiles.java Fri May 14 00:37:50 2021
@@ -21,7 +21,6 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -31,12 +30,12 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Stream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hpsf.CustomProperties;
 import org.apache.poi.hpsf.CustomProperty;
 import org.apache.poi.hpsf.DocumentSummaryInformation;
 import org.apache.poi.hpsf.HPSFException;
-import org.apache.poi.hpsf.MarkUnsupportedException;
 import org.apache.poi.hpsf.NoPropertySetStreamException;
 import org.apache.poi.hpsf.PropertySet;
 import org.apache.poi.hpsf.PropertySetFactory;
@@ -70,7 +69,7 @@ class TestReadAllFiles {
      */
     @ParameterizedTest
     @MethodSource("files")
-    void read(File file) throws IOException, NoPropertySetStreamException, MarkUnsupportedException {
+    void read(File file) throws IOException, NoPropertySetStreamException {
         /* Read the POI filesystem's property set streams: */
         for (POIFile pf : Util.readPropertySets(file)) {
             try (InputStream in = new ByteArrayInputStream(pf.getBytes())) {
@@ -84,7 +83,7 @@ class TestReadAllFiles {
     /**
      * This test method does a write and read back test with all POI
      * filesystems in the "data" directory by performing the following
-     * actions for each file:<p>
+     * actions for each file:
      *
      * <ul>
      * <li>Read its property set streams.
@@ -102,35 +101,35 @@ class TestReadAllFiles {
 
         /* Create a new POI filesystem containing the origin file's
          * property set streams: */
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        final POIFSFileSystem poiFs = new POIFSFileSystem();
-        for (POIFile poifile : Util.readPropertySets(file)) {
-            final InputStream in = new ByteArrayInputStream(poifile.getBytes());
-            final PropertySet psIn = PropertySetFactory.create(in);
-            psMap.put(poifile.getName(), psIn);
-            bos.reset();
-            psIn.write(bos);
-            poiFs.createDocument(new ByteArrayInputStream(bos.toByteArray()), poifile.getName());
-        }
+        UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
+        try (POIFSFileSystem poiFs = new POIFSFileSystem()) {
+            for (POIFile poifile : Util.readPropertySets(file)) {
+                final InputStream in = new ByteArrayInputStream(poifile.getBytes());
+                final PropertySet psIn = PropertySetFactory.create(in);
+                psMap.put(poifile.getName(), psIn);
+                bos.reset();
+                psIn.write(bos);
+                poiFs.createDocument(bos.toInputStream(), poifile.getName());
+            }
 
-        /* Read the property set streams from the POI filesystem just
-         * created. */
-        for (Map.Entry<String,PropertySet> me : psMap.entrySet()) {
-            final PropertySet ps1 = me.getValue();
-            final PropertySet ps2 = PropertySetFactory.create(poiFs.getRoot(), me.getKey());
-            assertNotNull(ps2);
-
-            /* Compare the property set stream with the corresponding one
-             * from the origin file and check whether they are equal. */
-
-            // Because of missing 0-paddings in the original input files, the bytes might differ.
-            // This fixes the comparison
-            String ps1str = ps1.toString().replace(" 00", "   ").replace(".", " ").replaceAll("(?m)( +$|(size|offset): [0-9]+)","");
-            String ps2str = ps2.toString().replace(" 00", "   ").replace(".", " ").replaceAll("(?m)( +$|(size|offset): [0-9]+)","");
+            /* Read the property set streams from the POI filesystem just
+             * created. */
+            for (Map.Entry<String, PropertySet> me : psMap.entrySet()) {
+                final PropertySet ps1 = me.getValue();
+                final PropertySet ps2 = PropertySetFactory.create(poiFs.getRoot(), me.getKey());
+                assertNotNull(ps2);
+
+                /* Compare the property set stream with the corresponding one
+                 * from the origin file and check whether they are equal. */
+
+                // Because of missing 0-paddings in the original input files, the bytes might differ.
+                // This fixes the comparison
+                String ps1str = ps1.toString().replace(" 00", "   ").replace(".", " ").replaceAll("(?m)( +$|(size|offset): [0-9]+)", "");
+                String ps2str = ps2.toString().replace(" 00", "   ").replace(".", " ").replaceAll("(?m)( +$|(size|offset): [0-9]+)", "");
 
-            assertEquals(ps1str, ps2str, "Equality for file " + file.getName());
+                assertEquals(ps1str, ps2str, "Equality for file " + file.getName());
+            }
         }
-        poiFs.close();
     }
 
     /**

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hpsf/basic/TestWrite.java Fri May 14 00:37:50 2021
@@ -26,10 +26,8 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -44,6 +42,7 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hpsf.ClassID;
 import org.apache.poi.hpsf.ClassIDPredefined;
@@ -118,9 +117,9 @@ class TestWrite {
         /* Write it to a POIFS and the latter to disk: */
         try (OutputStream out = new FileOutputStream(filename);
              POIFSFileSystem poiFs = new POIFSFileSystem();
-             ByteArrayOutputStream psStream = new ByteArrayOutputStream()) {
+             UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) {
             assertThrows(NoFormatIDException.class, () -> ps.write(psStream));
-            poiFs.createDocument(new ByteArrayInputStream(psStream.toByteArray()), SummaryInformation.DEFAULT_STREAM_NAME);
+            poiFs.createDocument(psStream.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
             poiFs.writeFilesystem(out);
         }
     }
@@ -142,12 +141,12 @@ class TestWrite {
         /* Create a mutable property set and write it to a POIFS: */
         try (OutputStream out = new FileOutputStream(filename);
             POIFSFileSystem poiFs = new POIFSFileSystem();
-             ByteArrayOutputStream psStream = new ByteArrayOutputStream()) {
+             UnsynchronizedByteArrayOutputStream psStream = new UnsynchronizedByteArrayOutputStream()) {
             final PropertySet ps = new PropertySet();
             final Section s = ps.getSections().get(0);
             s.setFormatID(SummaryInformation.FORMAT_ID);
             ps.write(psStream);
-            poiFs.createDocument(new ByteArrayInputStream(psStream.toByteArray()), SummaryInformation.DEFAULT_STREAM_NAME);
+            poiFs.createDocument(psStream.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME);
             poiFs.writeFilesystem(out);
         }
 
@@ -254,9 +253,8 @@ class TestWrite {
         /* Read the POIFS: */
         final PropertySet[] psa = new PropertySet[1];
         final POIFSReader r = new POIFSReader();
-        final POIFSReaderListener listener = (event) -> {
+        final POIFSReaderListener listener = (event) ->
             assertDoesNotThrow(() -> psa[0] = PropertySetFactory.create(event.getStream()));
-        };
 
         r.registerListener(listener,STREAM_NAME);
         r.read(filename);
@@ -357,9 +355,8 @@ class TestWrite {
         p.setValue(TITLE);
         ms.setProperty(p);
 
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
         mps.write(out);
-        out.close();
         byte[] bytes = out.toByteArray();
 
         PropertySet psr = new PropertySet(bytes);
@@ -388,9 +385,8 @@ class TestWrite {
     private void check(final long variantType, final Object value, final int codepage)
     throws UnsupportedVariantTypeException, IOException
     {
-        final ByteArrayOutputStream out = new ByteArrayOutputStream();
+        final UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
         VariantSupport.write(out, variantType, value, codepage);
-        out.close();
         final byte[] b = out.toByteArray();
         final Object objRead =
             VariantSupport.read(b, 0, b.length + LittleEndianConsts.INT_SIZE, variantType, codepage);
@@ -402,7 +398,7 @@ class TestWrite {
     }
 
     /**
-     * <p>Tests writing and reading back a proper dictionary.</p>
+     * Tests writing and reading back a proper dictionary.
      */
     @Test
     void dictionary() throws IOException, HPSFException {
@@ -410,37 +406,36 @@ class TestWrite {
         copy.deleteOnExit();
 
         /* Write: */
-        final OutputStream out = new FileOutputStream(copy);
-        final POIFSFileSystem poiFs = new POIFSFileSystem();
-        final PropertySet ps1 = new PropertySet();
-        final Section s = ps1.getSections().get(0);
-        final Map<Long,String> m = new HashMap<>(3, 1.0f);
-        m.put(1L, "String 1");
-        m.put(2L, "String 2");
-        m.put(3L, "String 3");
-        s.setDictionary(m);
-        s.setFormatID(DocumentSummaryInformation.FORMAT_ID[0]);
-        int codepage = CodePageUtil.CP_UNICODE;
-        s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, codepage);
-        poiFs.createDocument(ps1.toInputStream(), "Test");
-        poiFs.writeFilesystem(out);
-        poiFs.close();
-        out.close();
-
-        /* Read back: */
-        final List<POIFile> psf = Util.readPropertySets(copy);
-        assertEquals(1, psf.size());
-        final byte[] bytes = psf.get(0).getBytes();
-        final InputStream in = new ByteArrayInputStream(bytes);
-        final PropertySet ps2 = PropertySetFactory.create(in);
-
-        /* Check if the result is a DocumentSummaryInformation stream, as
-         * specified. */
-        assertTrue(ps2.isDocumentSummaryInformation());
-
-        /* Compare the property set stream with the corresponding one
-         * from the origin file and check whether they are equal. */
-        assertEquals(ps1, ps2);
+        try (OutputStream out = new FileOutputStream(copy);
+            POIFSFileSystem poiFs = new POIFSFileSystem()) {
+            final PropertySet ps1 = new PropertySet();
+            final Section s = ps1.getSections().get(0);
+            final Map<Long, String> m = new HashMap<>(3, 1.0f);
+            m.put(1L, "String 1");
+            m.put(2L, "String 2");
+            m.put(3L, "String 3");
+            s.setDictionary(m);
+            s.setFormatID(DocumentSummaryInformation.FORMAT_ID[0]);
+            int codepage = CodePageUtil.CP_UNICODE;
+            s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, codepage);
+            poiFs.createDocument(ps1.toInputStream(), "Test");
+            poiFs.writeFilesystem(out);
+
+            /* Read back: */
+            final List<POIFile> psf = Util.readPropertySets(copy);
+            assertEquals(1, psf.size());
+            final byte[] bytes = psf.get(0).getBytes();
+            final InputStream in = new ByteArrayInputStream(bytes);
+            final PropertySet ps2 = PropertySetFactory.create(in);
+
+            /* Check if the result is a DocumentSummaryInformation stream, as
+             * specified. */
+            assertTrue(ps2.isDocumentSummaryInformation());
+
+            /* Compare the property set stream with the corresponding one
+             * from the origin file and check whether they are equal. */
+            assertEquals(ps1, ps2);
+        }
     }
 
     /**
@@ -543,9 +538,9 @@ class TestWrite {
             doufStream.close();
 
             // And also write to some bytes for checking
-            ByteArrayOutputStream sinfBytes = new ByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream sinfBytes = new UnsynchronizedByteArrayOutputStream();
             sinf.write(sinfBytes);
-            ByteArrayOutputStream dinfBytes = new ByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream dinfBytes = new UnsynchronizedByteArrayOutputStream();
             dinf.write(dinfBytes);
 
 
@@ -656,7 +651,7 @@ class TestWrite {
      * codepage. (HPSF writes Unicode dictionaries only.)
      */
     @Test
-    void dictionaryWithInvalidCodepage() throws IOException, HPSFException {
+    void dictionaryWithInvalidCodepage() throws IOException {
         final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
         copy.deleteOnExit();
 
@@ -696,8 +691,8 @@ class TestWrite {
      * method checks whether the application is runing in an environment
      * where the default character set is 16-bit-capable.</p>
      *
-     * @return <code>true</code> if the default character set is 16-bit-capable,
-     * else <code>false</code>.
+     * @return {@code true} if the default character set is 16-bit-capable,
+     * else {@code false}.
      */
     private boolean hasProperDefaultCharset() {
         final String charSetName = System.getProperty("file.encoding");

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/HSSFTestDataSamples.java Fri May 14 00:37:50 2021
@@ -17,12 +17,11 @@
 
 package org.apache.poi.hssf;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 
@@ -56,11 +55,11 @@ public final class HSSFTestDataSamples {
 	 * Useful for verifying that the serialisation round trip
 	 */
 	public static HSSFWorkbook writeOutAndReadBack(HSSFWorkbook original) {
-		try {
-			ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+		try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
 			original.write(baos);
-			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-			return new HSSFWorkbook(bais);
+			try (InputStream is = baos.toInputStream()) {
+				return new HSSFWorkbook(is);
+			}
 		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffDrawingToXml.java Fri May 14 00:37:50 2021
@@ -16,6 +16,8 @@
 ==================================================================== */
 package org.apache.poi.hssf.dev;
 
+import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStream;
@@ -23,7 +25,6 @@ import java.util.Map;
 
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.NullOutputStream;
 
 class TestBiffDrawingToXml extends BaseTestIteratingXLS {
 
@@ -44,7 +45,7 @@ class TestBiffDrawingToXml extends BaseT
 	@Override
 	void runOneFile(File pFile) throws Exception {
         try (InputStream wb = new FileInputStream(pFile)) {
-            BiffDrawingToXml.writeToFile(new NullOutputStream(), wb, false, new String[0]);
+            BiffDrawingToXml.writeToFile(NULL_OUTPUT_STREAM, wb, false, new String[0]);
         }
 	}
 }

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestBiffViewer.java Fri May 14 00:37:50 2021
@@ -16,6 +16,8 @@
 ==================================================================== */
 package org.apache.poi.hssf.dev;
 
+import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
+
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -25,7 +27,6 @@ import java.util.Map;
 
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.NullOutputStream;
 import org.apache.poi.util.RecordFormatException;
 
 class TestBiffViewer extends BaseTestIteratingXLS {
@@ -54,7 +55,7 @@ class TestBiffViewer extends BaseTestIte
         try (POIFSFileSystem fs = new POIFSFileSystem(fileIn, true);
              InputStream is = BiffViewer.getPOIFSInputStream(fs)) {
             // use a NullOutputStream to not write the bytes anywhere for best runtime
-            PrintWriter dummy = new PrintWriter(new OutputStreamWriter(new NullOutputStream(), LocaleUtil.CHARSET_1252));
+            PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
             BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
         }
     }

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestEFBiffViewer.java Fri May 14 00:37:50 2021
@@ -23,7 +23,7 @@ import java.util.Map;
 
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.parallel.ResourceLock;
 import org.junit.jupiter.api.parallel.Resources;
 
@@ -32,13 +32,16 @@ class TestEFBiffViewer extends BaseTestI
     @Override
     protected Map<String, Class<? extends Throwable>> getExcludes() {
         Map<String, Class<? extends Throwable>> excludes = super.getExcludes();
-        excludes.put("35897-type4.xls", EncryptedDocumentException.class); // unsupported crypto api header
+		// unsupported crypto api header
+        excludes.put("35897-type4.xls", EncryptedDocumentException.class);
         excludes.put("51832.xls", EncryptedDocumentException.class);
         excludes.put("xor-encryption-abc.xls", EncryptedDocumentException.class);
         excludes.put("password.xls", EncryptedDocumentException.class);
-        excludes.put("43493.xls", RecordInputStream.LeftoverDataException.class);  // HSSFWorkbook cannot open it as well
+		// HSSFWorkbook cannot open it as well
+        excludes.put("43493.xls", RecordInputStream.LeftoverDataException.class);
         excludes.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
-        // EXCLUDED.put("XRefCalc.xls", RuntimeException.class);            // "Buffer overrun"
+		// "Buffer overrun"
+        excludes.put("XRefCalc.xls", RuntimeException.class);
         return excludes;
     }
 

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestFormulaViewer.java Fri May 14 00:37:50 2021
@@ -24,7 +24,7 @@ import java.util.Map;
 
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.parallel.ResourceLock;
 import org.junit.jupiter.api.parallel.Resources;
 

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestReSave.java Fri May 14 00:37:50 2021
@@ -25,7 +25,7 @@ import java.util.Map;
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.parallel.Isolated;

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/dev/TestRecordLister.java Fri May 14 00:37:50 2021
@@ -20,7 +20,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
 
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.parallel.ResourceLock;
 import org.junit.jupiter.api.parallel.Resources;
 

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/eventmodel/TestEventRecordFactory.java Fri May 14 00:37:50 2021
@@ -20,10 +20,10 @@ package org.apache.poi.hssf.eventmodel;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
@@ -31,6 +31,7 @@ import java.util.Iterator;
 import java.util.stream.Stream;
 
 import org.apache.commons.collections4.IteratorUtils;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.hssf.record.BOFRecord;
 import org.apache.poi.hssf.record.ContinueRecord;
 import org.apache.poi.hssf.record.EOFRecord;
@@ -130,16 +131,15 @@ final class TestEventRecordFactory {
      * OBJECTIVE:  Test that the RecordFactory given an InputStream
      *             constructs the expected records.<P>
      * SUCCESS:    Record factory creates the expected records.<P>
-     * FAILURE:    The wrong records are created or contain the wrong values <P>
-     *
+     * FAILURE:    The wrong records are created or contain the wrong values
      */
     @Test
      void testContinuedUnknownRecord() throws IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
         for (byte[] b : CONTINUE_DATA) {
             bos.write(b);
         }
-        continueHelper(new ByteArrayInputStream(bos.toByteArray()));
+        continueHelper(bos.toInputStream());
     }
 
     @Test
@@ -156,7 +156,7 @@ final class TestEventRecordFactory {
         Iterator<byte[]> expectedData = Stream.of(CONTINUE_DATA).iterator();
 
         ERFListener listener = rec -> {
-            assertEquals(expectedType.next(), rec.getClass());
+            assertSame(expectedType.next(), rec.getClass());
             assertArrayEquals(expectedData.next(), rec.serialize());
             return true;
         };

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/extractor/TestOldExcelExtractor.java Fri May 14 00:37:50 2021
@@ -23,15 +23,16 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
 import java.security.Permission;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.EmptyFileException;
 import org.apache.poi.EncryptedDocumentException;
 import org.apache.poi.POIDataSamples;
@@ -39,7 +40,7 @@ import org.apache.poi.extractor.POITextE
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.apache.poi.util.RecordFormatException;
 import org.junit.jupiter.api.Test;
 
@@ -321,12 +322,11 @@ final class TestOldExcelExtractor {
     void testMain() throws IOException {
         File file = HSSFTestDataSamples.getSampleFile("testEXCEL_3.xls");
         PrintStream save = System.out;
-        try {
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
-            PrintStream str = new PrintStream(out, false, "UTF-8");
+        try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+             PrintStream str = new PrintStream(out, false, StandardCharsets.UTF_8.displayName())) {
             System.setOut(str);
             OldExcelExtractor.main(new String[] {file.getAbsolutePath()});
-            String string = out.toString("UTF-8");
+            String string = out.toString(StandardCharsets.UTF_8);
             assertTrue(string.contains("Table C-13--Lemons"), "Had: " + string);
         } finally {
             System.setOut(save);

Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/model/TestDrawingAggregate.java Fri May 14 00:37:50 2021
@@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
@@ -33,6 +32,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Stream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.ddf.DefaultEscherRecordFactory;
 import org.apache.poi.ddf.EscherContainerRecord;
 import org.apache.poi.ddf.EscherDggRecord;
@@ -113,7 +113,7 @@ class TestDrawingAggregate {
          * @return the raw data being aggregated
          */
         byte[] getRawBytes(){
-            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
             for (RecordBase rb : aggRecords) {
                 Record r = (org.apache.poi.hssf.record.Record) rb;
                 try {
@@ -216,7 +216,7 @@ class TestDrawingAggregate {
         assertEquals(dgBytes.length, pos, "data was not fully read");
 
         // serialize to byte array
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
         for(EscherRecord r : records) {
             out.write(r.serialize());
         }
@@ -242,7 +242,7 @@ class TestDrawingAggregate {
     }
 
     private static byte[] toByteArray(List<RecordBase> records) {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
         for (RecordBase rb : records) {
             Record r = (org.apache.poi.hssf.record.Record) rb;
             try {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org