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 [9/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-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hsmf/datatypes/PropertiesChunk.java Fri May 14 00:37:50 2021
@@ -17,8 +17,9 @@
 
 package org.apache.poi.hsmf.datatypes;
 
+import static org.apache.logging.log4j.util.Unbox.box;
+
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -30,6 +31,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.poi.hsmf.datatypes.PropertyValue.BooleanPropertyValue;
@@ -47,8 +49,6 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndian;
 import org.apache.poi.util.LittleEndian.BufferUnderrunException;
 
-import static org.apache.logging.log4j.util.Unbox.box;
-
 /**
  * <p>
  * A Chunk which holds (single) fixed-length properties, and pointer to the
@@ -76,13 +76,13 @@ public abstract class PropertiesChunk ex
      * Holds properties, indexed by type. If a property is multi-valued, or
      * variable length, it will be held via a {@link ChunkBasedPropertyValue}.
      */
-    private Map<MAPIProperty, PropertyValue> properties = new HashMap<>();
+    private final Map<MAPIProperty, PropertyValue> properties = new HashMap<>();
 
     /**
      * The ChunkGroup that these properties apply to. Used when matching chunks
      * to variable sized and multi-valued properties
      */
-    private ChunkGroup parentGroup;
+    private final ChunkGroup parentGroup;
 
     /**
      * Creates a Properties Chunk.
@@ -254,7 +254,7 @@ public abstract class PropertiesChunk ex
                 }
 
                 // Wrap and store
-                PropertyValue propVal = null;
+                PropertyValue propVal;
                 if (isPointer) {
                     // We'll match up the chunk later
                     propVal = new ChunkBasedPropertyValue(prop, flags, data, type);
@@ -302,16 +302,17 @@ public abstract class PropertiesChunk ex
      *         If an I/O error occurs.
      */
     public void writeProperties(DirectoryEntry directory) throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        List<PropertyValue> values = writeProperties(baos);
-        baos.close();
-
-        // write the header data with the properties declaration
-        directory.createDocument(PropertiesChunk.NAME,
-            new ByteArrayInputStream(baos.toByteArray()));
+        try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
+            List<PropertyValue> values = writeProperties(baos);
 
-        // write the property values
-        writeNodeData(directory, values);
+            // write the header data with the properties declaration
+            try (InputStream is = baos.toInputStream()) {
+                directory.createDocument(PropertiesChunk.NAME, is);
+            }
+
+            // write the property values
+            writeNodeData(directory, values);
+        }
     }
 
     /**

Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfEscape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfEscape.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfEscape.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfEscape.java Fri May 14 00:37:50 2021
@@ -190,7 +190,7 @@ public class HwmfEscape implements HwmfR
     }
 
     public interface HwmfEscapeData {
-        public int init(LittleEndianInputStream leis, long recordSize, EscapeFunction escapeFunction) throws IOException;
+        int init(LittleEndianInputStream leis, long recordSize, EscapeFunction escapeFunction) throws IOException;
     }
 
 

Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwmf/usermodel/HwmfEmbeddedIterator.java Fri May 14 00:37:50 2021
@@ -17,13 +17,13 @@
 
 package org.apache.poi.hwmf.usermodel;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.hwmf.record.HwmfEscape;
 import org.apache.poi.hwmf.record.HwmfEscape.EscapeFunction;
 import org.apache.poi.hwmf.record.HwmfEscape.WmfEscapeEMF;
@@ -120,7 +120,7 @@ public class HwmfEmbeddedIterator implem
         final HwmfEmbedded emb = new HwmfEmbedded();
         emb.setEmbeddedType(HwmfEmbeddedType.EMF);
 
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
         try {
             for (;;) {
                 bos.write(img.getEmfData());
@@ -132,8 +132,8 @@ public class HwmfEmbeddedIterator implem
                     return emb;
                 }
             }
-        } catch (IOException e) {
-            // ByteArrayOutputStream doesn't throw IOException
+        } catch (IOException ignored) {
+            // UnsynchronizedByteArrayOutputStream doesn't throw IOException
             return null;
         } finally {
             emb.setData(bos.toByteArray());

Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/dev/HWPFLister.java Fri May 14 00:37:50 2021
@@ -17,8 +17,6 @@
 
 package org.apache.poi.hwpf.dev;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -31,6 +29,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFDocumentCore;
 import org.apache.poi.hwpf.HWPFOldDocument;
@@ -262,12 +261,11 @@ public final class HWPFLister {
 
     private static HWPFDocumentCore writeOutAndReadBack(
             HWPFDocumentCore original ) {
-        try {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream( 4096 );
+        try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
             original.write( baos );
-            ByteArrayInputStream bais = new ByteArrayInputStream(
-                    baos.toByteArray() );
-            return loadDoc( bais );
+            try (InputStream is = baos.toInputStream()) {
+                return loadDoc(is);
+            }
         }
         catch ( IOException e ) {
             throw new RuntimeException( e );
@@ -388,7 +386,7 @@ public final class HWPFLister {
         }
     }
 
-    public void dumpFileSystem() throws Exception {
+    public void dumpFileSystem() {
         System.out.println( dumpFileSystem( _doc.getDirectory() ) );
     }
 
@@ -439,8 +437,7 @@ public final class HWPFLister {
         }
     }
 
-    public void dumpPapx( boolean withProperties, boolean withSprms )
-            throws Exception {
+    public void dumpPapx( boolean withProperties, boolean withSprms ) {
         if ( _doc instanceof HWPFDocument ) {
             System.out.println( "binary PAP pages " );
 
@@ -514,8 +511,8 @@ public final class HWPFLister {
             if ( dumpAssotiatedPapx ) {
                 boolean hasAssotiatedPapx = false;
                 for ( PAPX papx : _doc.getParagraphTable().getParagraphs() ) {
-                    if ( papx.getStart() <= endOfParagraphCharOffset.intValue()
-                            && endOfParagraphCharOffset.intValue() < papx
+                    if ( papx.getStart() <= endOfParagraphCharOffset
+                            && endOfParagraphCharOffset < papx
                                     .getEnd() ) {
                         hasAssotiatedPapx = true;
                         System.out.println( "* " + papx );

Modified: poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java (original)
+++ poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hwpf/usermodel/Picture.java Fri May 14 00:37:50 2021
@@ -18,13 +18,13 @@
 package org.apache.poi.hwpf.usermodel;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Collections;
 import java.util.List;
 import java.util.zip.InflaterInputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.poi.ddf.EscherBSERecord;
@@ -37,6 +37,7 @@ import org.apache.poi.ddf.EscherRecord;
 import org.apache.poi.hwpf.model.PICF;
 import org.apache.poi.hwpf.model.PICFAndOfficeArtData;
 import org.apache.poi.sl.image.ImageHeaderPNG;
+import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.StringUtil;
 
 /**
@@ -120,10 +121,10 @@ public final class Picture {
         }
     }
 
-    private void fillImageContent()
-    {
-        if ( content != null && content.length > 0 )
+    private void fillImageContent() {
+        if ( content != null && content.length > 0 ) {
             return;
+        }
 
         byte[] rawContent = getRawContent();
 
@@ -134,33 +135,21 @@ public final class Picture {
          * similarity in the data block contents.
          */
         if ( matchSignature( rawContent, COMPRESSED1, 32 )
-                || matchSignature( rawContent, COMPRESSED2, 32 ) )
-        {
-            try
-            {
-                InflaterInputStream in = new InflaterInputStream(
-                        new ByteArrayInputStream( rawContent, 33,
-                                rawContent.length - 33 ) );
-                ByteArrayOutputStream out = new ByteArrayOutputStream();
-                byte[] buf = new byte[4096];
-                int readBytes;
-                while ( ( readBytes = in.read( buf ) ) > 0 )
-                {
-                    out.write( buf, 0, readBytes );
-                }
+                || matchSignature( rawContent, COMPRESSED2, 32 ) ) {
+            try (ByteArrayInputStream bis = new ByteArrayInputStream( rawContent, 33, rawContent.length - 33 );
+                InflaterInputStream in = new InflaterInputStream(bis);
+                 UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+
+                IOUtils.copy(in, out);
                 content = out.toByteArray();
-            }
-            catch ( IOException e )
-            {
+            } catch (IOException e) {
                 /*
                  * Problems reading from the actual ByteArrayInputStream should
                  * never happen so this will only ever be a ZipException.
                  */
                 LOGGER.atInfo().withThrowable(e).log("Possibly corrupt compression or non-compressed data");
             }
-        }
-        else
-        {
+        } else {
             // Raw data is not compressed.
             content = new ImageHeaderPNG(rawContent).extractPNG();
         }
@@ -186,8 +175,8 @@ public final class Picture {
         byte[] jpegContent = getContent();
 
         int pointer = 2;
-        int firstByte = jpegContent[pointer];
-        int secondByte = jpegContent[pointer + 1];
+        int firstByte;
+        int secondByte;
         int endOfPicture = jpegContent.length;
         while ( pointer < endOfPicture - 1 )
         {

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hdgf/dev/TestVSDDumper.java Fri May 14 00:37:50 2021
@@ -26,7 +26,7 @@ import java.io.File;
 import java.io.PrintStream;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.Test;
 
 public class TestVSDDumper {

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java Fri May 14 00:37:50 2021
@@ -26,7 +26,6 @@ import static org.junit.jupiter.api.Asse
 
 import java.awt.geom.Point2D;
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -34,6 +33,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hemf.record.emf.HemfComment;
 import org.apache.poi.hemf.record.emf.HemfComment.EmfComment;
@@ -52,7 +52,6 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.RecordFormatException;
 import org.junit.jupiter.api.Test;
 
-@SuppressWarnings("StatementWithEmptyBody")
 public class TestHemfPicture {
 
     private static final POIDataSamples ss_samples = POIDataSamples.getSpreadSheetInstance();
@@ -286,10 +285,10 @@ public class TestHemfPicture {
     @Test
     void testInfiniteLoopOnByteArray() throws Exception {
         try (InputStream is = ss_samples.openResourceAsStream("61294.emf")) {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
             IOUtils.copy(is, bos);
 
-            HemfPicture pic = new HemfPicture(new ByteArrayInputStream(bos.toByteArray()));
+            HemfPicture pic = new HemfPicture(bos.toInputStream());
             assertThrows(RecordFormatException.class, () -> pic.forEach(r -> {}));
         }
     }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/TestHMEFMessage.java Fri May 14 00:37:50 2021
@@ -21,15 +21,16 @@ import static org.junit.jupiter.api.Asse
 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 static org.junit.jupiter.api.Assertions.assertThrows;
 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.nio.charset.StandardCharsets;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hmef.attribute.MAPIAttribute;
 import org.apache.poi.hmef.attribute.MAPIRtfAttribute;
@@ -83,10 +84,10 @@ public final class TestHMEFMessage {
         assertNotNull(msg.getMessageAttribute(TNEFProperty.ID_MAPIPROPERTIES));
 
         // Check the order
-        assertEquals(TNEFProperty.ID_TNEFVERSION, msg.getMessageAttributes().get(0).getProperty());
-        assertEquals(TNEFProperty.ID_OEMCODEPAGE, msg.getMessageAttributes().get(1).getProperty());
-        assertEquals(TNEFProperty.ID_MESSAGECLASS, msg.getMessageAttributes().get(2).getProperty());
-        assertEquals(TNEFProperty.ID_MAPIPROPERTIES, msg.getMessageAttributes().get(3).getProperty());
+        assertSame(TNEFProperty.ID_TNEFVERSION, msg.getMessageAttributes().get(0).getProperty());
+        assertSame(TNEFProperty.ID_OEMCODEPAGE, msg.getMessageAttributes().get(1).getProperty());
+        assertSame(TNEFProperty.ID_MESSAGECLASS, msg.getMessageAttributes().get(2).getProperty());
+        assertSame(TNEFProperty.ID_MAPIPROPERTIES, msg.getMessageAttributes().get(3).getProperty());
 
         // Check some that aren't there
         assertNull(msg.getMessageAttribute(TNEFProperty.ID_AIDOWNER));
@@ -168,7 +169,7 @@ public final class TestHMEFMessage {
 
     @Test
     void testNoData() throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
 
         // Header
         LittleEndian.putInt(HMEFMessage.HEADER_SIGNATURE, out);
@@ -176,16 +177,14 @@ public final class TestHMEFMessage {
         // field
         LittleEndian.putUShort(0, out);
 
-        byte[] bytes = out.toByteArray();
-        InputStream str = new ByteArrayInputStream(bytes);
-        HMEFMessage msg = new HMEFMessage(str);
+        HMEFMessage msg = new HMEFMessage(out.toInputStream());
         assertNull(msg.getSubject());
         assertNull(msg.getBody());
     }
 
     @Test
     void testInvalidLevel() throws Exception {
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
 
         // Header
         LittleEndian.putInt(HMEFMessage.HEADER_SIGNATURE, out);
@@ -196,10 +195,9 @@ public final class TestHMEFMessage {
         // invalid level
         LittleEndian.putUShort(90, out);
 
-        InputStream str = new ByteArrayInputStream(out.toByteArray());
         IllegalStateException ex = assertThrows(
             IllegalStateException.class,
-            () -> new HMEFMessage(str)
+            () -> new HMEFMessage(out.toInputStream())
         );
         assertEquals("Unhandled level 90", ex.getMessage());
     }
@@ -226,7 +224,7 @@ public final class TestHMEFMessage {
 
         MAPIStringAttribute propE28b = (MAPIStringAttribute)msg.getMessageMAPIAttribute(propE28);
         assertNotNull(propE28b);
-        assertEquals(MAPIStringAttribute.class, propE28b.getClass());
+        assertSame(MAPIStringAttribute.class, propE28b.getClass());
         assertEquals("Zimbra - Mark Rogers", propE28b.getDataString().substring(10));
     }
 

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/dev/TestHMEFDumper.java Fri May 14 00:37:50 2021
@@ -28,7 +28,7 @@ import java.io.File;
 import java.io.PrintStream;
 
 import org.apache.poi.POIDataSamples;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.Test;
 
 public class TestHMEFDumper {
@@ -38,13 +38,13 @@ public class TestHMEFDumper {
     }
 
     @Test
-    void main() throws Exception {
+    void main() {
         File file = POIDataSamples.getHMEFInstance().getFile("quick-winmail.dat");
         assertDoesNotThrow(() -> doMain(file.getAbsolutePath()));
     }
 
     @Test
-    void mainFull() throws Exception {
+    void mainFull() {
         File file = POIDataSamples.getHMEFInstance().getFile("quick-winmail.dat");
         assertDoesNotThrow(() -> doMain("--full", file.getAbsolutePath()));
     }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hmef/extractor/TestHMEFContentsExtractor.java Fri May 14 00:37:50 2021
@@ -22,11 +22,11 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.util.TempFile;
 import org.junit.jupiter.api.Test;
@@ -62,13 +62,13 @@ public class TestHMEFContentsExtractor {
         POIDataSamples samples = POIDataSamples.getHMEFInstance();
         File winmailTNEFFile = samples.getFile("quick-winmail.dat");
         HMEFContentsExtractor extractor = new HMEFContentsExtractor(winmailTNEFFile);
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        extractor.extractMessageBody(out);
-        assertTrue(out.size() > 0);
-        byte[] expectedMagic = new byte[] { '{', '\\', 'r', 't', 'f' };
-        byte[] magic = Arrays.copyOf(out.toByteArray(), 5);
-        assertArrayEquals(expectedMagic, magic, "RTF magic number");
-        out.close();
+        try (UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream()) {
+            extractor.extractMessageBody(out);
+            assertTrue(out.size() > 0);
+            byte[] expectedMagic = new byte[]{'{', '\\', 'r', 't', 'f'};
+            byte[] magic = Arrays.copyOf(out.toByteArray(), 5);
+            assertArrayEquals(expectedMagic, magic, "RTF magic number");
+        }
     }
 
     @Test

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/HSLFTestDataSamples.java Fri May 14 00:37:50 2021
@@ -17,12 +17,11 @@
 
 package org.apache.poi.hslf;
 
-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.hslf.usermodel.HSLFSlideShow;
 import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
@@ -50,32 +49,30 @@ public class HSLFTestDataSamples {
 	}
 
 	/**
-	 * Writes a slideshow to a {@code ByteArrayOutputStream} and reads it back
+	 * Writes a slideshow to a {@code UnsynchronizedByteArrayOutputStream} and reads it back
 	 * from a {@code ByteArrayInputStream}.<p>
 	 * Useful for verifying that the serialisation round trip
 	 */
 	public static HSLFSlideShowImpl writeOutAndReadBack(HSLFSlideShowImpl original) {
-		try {
-			ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+		try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {
 			original.write(baos);
-			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-			return new HSLFSlideShowImpl(bais);
+			try (InputStream is = baos.toInputStream()) {
+				return new HSLFSlideShowImpl(is);
+			}
 		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}
 	}
 
 	/**
-	 * Writes a slideshow to a {@code ByteArrayOutputStream} and reads it back
+	 * Writes a slideshow to a {@code UnsynchronizedByteArrayOutputStream} and reads it back
 	 * from a {@code ByteArrayInputStream}.<p>
 	 * Useful for verifying that the serialisation round trip
 	 */
 	public static HSLFSlideShow writeOutAndReadBack(HSLFSlideShow original) {
-		try {
-			ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+		try (UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream(4096)) {
 			original.write(baos);
-			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-			return new HSLFSlideShow(bais);
+			return new HSLFSlideShow(baos.toInputStream());
 		} catch (IOException e) {
 			throw new RuntimeException(e);
 		}

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestPOIDocumentScratchpad.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestPOIDocumentScratchpad.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestPOIDocumentScratchpad.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestPOIDocumentScratchpad.java Fri May 14 00:37:50 2021
@@ -21,22 +21,18 @@
 package org.apache.poi.hslf;
 
 
+import static org.apache.poi.POIDataSamples.writeOutAndReadBack;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
-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.SummaryInformation;
-import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -47,23 +43,11 @@ import org.junit.jupiter.api.Test;
  *  which are part of the scratchpad (not main)
  */
 public final class TestPOIDocumentScratchpad {
-	// The POI Documents to work on
-	private POIDocument doc;
-	private POIDocument doc2;
-
-	/**
-	 * Set things up, using a PowerPoint document and
-	 *  a Word Document for our testing
-	 */
-	@BeforeEach
-    void setUp() throws IOException {
-		doc = new HSLFSlideShowImpl(POIDataSamples.getSlideShowInstance().openResourceAsStream("basic_test_ppt_file.ppt"));
-		doc2 = HWPFTestDataSamples.openSampleFile("test2.doc");
-	}
-
 	@Test
-	void testReadProperties() {
-	    testReadPropertiesHelper(doc);
+	void testReadProperties() throws IOException {
+		try (POIDocument doc = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt")) {
+			testReadPropertiesHelper(doc);
+		}
 	}
 
 	private void testReadPropertiesHelper(POIDocument docPH) {
@@ -77,49 +61,46 @@ public final class TestPOIDocumentScratc
 	}
 
 	@Test
-	void testReadProperties2() {
-		// Check again on the word one
-		assertNotNull(doc2.getDocumentSummaryInformation());
-		assertNotNull(doc2.getSummaryInformation());
-
-		assertEquals("Hogwarts", doc2.getSummaryInformation().getAuthor());
-		assertEquals("", doc2.getSummaryInformation().getKeywords());
-		assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
+	void testReadProperties2() throws IOException {
+		try (POIDocument doc2 = HWPFTestDataSamples.openSampleFile("test2.doc")) {
+			// Check again on the word one
+			assertNotNull(doc2.getDocumentSummaryInformation());
+			assertNotNull(doc2.getSummaryInformation());
+
+			assertEquals("Hogwarts", doc2.getSummaryInformation().getAuthor());
+			assertEquals("", doc2.getSummaryInformation().getKeywords());
+			assertEquals(0, doc2.getDocumentSummaryInformation().getByteCount());
+		}
 	}
 
 	@Test
 	void testWriteProperties() throws IOException {
 		// Just check we can write them back out into a filesystem
-		POIFSFileSystem outFS = new POIFSFileSystem();
-		doc.writeProperties(outFS);
-
-		// Should now hold them
-		assertNotNull(outFS.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
-		assertNotNull(outFS.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME));
-		outFS.close();
+		try (POIDocument doc = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
+			 POIFSFileSystem outFS = new POIFSFileSystem()) {
+			doc.writeProperties(outFS);
+
+			// Should now hold them
+			assertNotNull(outFS.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME));
+			assertNotNull(outFS.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME));
+		}
 	}
 
 	@Test
     void testWriteReadProperties() throws IOException {
-		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-
     	// Write them out
-    	POIFSFileSystem outFS = new POIFSFileSystem();
-    	doc.writeProperties(outFS);
-    	outFS.writeFilesystem(baos);
-
-    	// Create a new version
-    	ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-    	POIFSFileSystem inFS = new POIFSFileSystem(bais);
-
-    	// Check they're still there
-    	POIDocument ppt = new HPSFPropertiesOnlyDocument(inFS);
-    	ppt.readProperties();
-
-    	// Delegate test
-    	testReadPropertiesHelper(ppt);
-
-    	ppt.close();
-    	inFS.close();
+		try (POIDocument doc = HSLFTestDataSamples.getSlideShow("basic_test_ppt_file.ppt");
+    		POIFSFileSystem outFS = new POIFSFileSystem()) {
+			doc.writeProperties(outFS);
+
+			// Check they're still there
+			try (POIFSFileSystem inFS = writeOutAndReadBack(outFS);
+				 POIDocument ppt = new HPSFPropertiesOnlyDocument(inFS)) {
+				ppt.readProperties();
+
+				// Delegate test
+				testReadPropertiesHelper(ppt);
+			}
+		}
     }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWrite.java Fri May 14 00:37:50 2021
@@ -25,12 +25,11 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 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.io.InputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.usermodel.HSLFSlideShow;
 import org.apache.poi.hslf.usermodel.HSLFSlideShowImpl;
@@ -56,7 +55,7 @@ public final class TestReWrite {
              HSLFSlideShowImpl hss = new HSLFSlideShowImpl(pfs)) {
 
             // Write out to a byte array, and to a temp file
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
             hss.write(baos);
 
             final File file = TempFile.createTempFile("TestHSLF", ".ppt");
@@ -66,8 +65,7 @@ public final class TestReWrite {
 
 
             // Build an input stream of it, and read back as a POIFS from the stream
-            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-            try (POIFSFileSystem npfS = new POIFSFileSystem(bais);
+            try (POIFSFileSystem npfS = new POIFSFileSystem(baos.toInputStream());
                 // And the same on the temp file
                 POIFSFileSystem npfF = new POIFSFileSystem(file)) {
 
@@ -97,18 +95,16 @@ public final class TestReWrite {
             assertNotNull(pfsC.getRoot().getEntry("Macros"));
 
             // Write out normally, will loose the macro stream
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
             hssC.write(baos);
-            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-            try (POIFSFileSystem pfsNew = new POIFSFileSystem(bais)) {
+            try (POIFSFileSystem pfsNew = new POIFSFileSystem(baos.toInputStream())) {
                 assertFalse(pfsNew.getRoot().hasEntry("Macros"));
             }
 
             // But if we write out with nodes preserved, will be there
             baos.reset();
             hssC.write(baos, true);
-            bais = new ByteArrayInputStream(baos.toByteArray());
-            try (POIFSFileSystem pfsNew = new POIFSFileSystem(bais)) {
+            try (POIFSFileSystem pfsNew = new POIFSFileSystem(baos.toInputStream())) {
                 assertTrue(pfsNew.getRoot().hasEntry("Macros"));
             }
         }
@@ -138,14 +134,11 @@ public final class TestReWrite {
         assertDoesNotThrow(ss::getNotes);
 
         // Now write out to a byte array
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
         hss.write(baos);
 
-        // Build an input stream of it
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
         // Use POIFS to query that lot
-        try (POIFSFileSystem npfs = new POIFSFileSystem(bais)) {
+        try (POIFSFileSystem npfs = new POIFSFileSystem(baos.toInputStream())) {
             assertSame(pfs, npfs);
         }
     }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/TestReWriteSanity.java Fri May 14 00:37:50 2021
@@ -18,14 +18,15 @@
 package org.apache.poi.hslf;
 
 
+import static org.apache.commons.io.output.NullOutputStream.NULL_OUTPUT_STREAM;
 import static org.apache.poi.POITestCase.assertContains;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.io.output.CountingOutputStream;
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.record.CurrentUserAtom;
 import org.apache.poi.hslf.record.PersistPtrHolder;
@@ -63,55 +64,50 @@ public final class TestReWriteSanity {
     @Test
     void testUserEditAtomsRight() throws Exception {
         // Write out to a byte array
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
         ss.write(baos);
 
-        // Build an input stream of it
-        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
-
         // Create a new one from that
-        HSLFSlideShowImpl wss = new HSLFSlideShowImpl(bais);
+        try (HSLFSlideShowImpl wss = new HSLFSlideShowImpl(baos.toInputStream())) {
 
-        // Find the location of the PersistPtrIncrementalBlocks and
-        // UserEditAtoms
-        Record[] r = wss.getRecords();
-        Map<Integer,Record> pp = new HashMap<>();
-        Map<Integer,Object> ue = new HashMap<>();
-        ue.put(Integer.valueOf(0),Integer.valueOf(0)); // Will show 0 if first
-        int pos = 0;
-        int lastUEPos = -1;
-
-        for (final Record rec : r) {
-            if(rec instanceof PersistPtrHolder) {
-                pp.put(Integer.valueOf(pos), rec);
-            }
-            if(rec instanceof UserEditAtom) {
-                ue.put(Integer.valueOf(pos), rec);
-                lastUEPos = pos;
-            }
-
-            ByteArrayOutputStream bc = new ByteArrayOutputStream();
-            rec.writeOut(bc);
-            pos += bc.size();
-        }
+            // Find the location of the PersistPtrIncrementalBlocks and
+            // UserEditAtoms
+            Record[] r = wss.getRecords();
+            Map<Integer, Record> pp = new HashMap<>();
+            Map<Integer, Object> ue = new HashMap<>();
+            ue.put(0, 0); // Will show 0 if first
+            int lastUEPos = -1;
+
+            CountingOutputStream cos = new CountingOutputStream(NULL_OUTPUT_STREAM);
+            for (final Record rec : r) {
+                int pos = cos.getCount();
+                if (rec instanceof PersistPtrHolder) {
+                    pp.put(pos, rec);
+                }
+                if (rec instanceof UserEditAtom) {
+                    ue.put(pos, rec);
+                    lastUEPos = pos;
+                }
 
-        // Check that the UserEditAtom's point to right stuff
-        for (final Record rec : r) {
-            if(rec instanceof UserEditAtom) {
-                UserEditAtom uea = (UserEditAtom)rec;
-                int luPos = uea.getLastUserEditAtomOffset();
-                int ppPos = uea.getPersistPointersOffset();
-
-                assertContains(ue, Integer.valueOf(luPos));
-                assertContains(pp, Integer.valueOf(ppPos));
+                rec.writeOut(cos);
             }
-        }
 
-        // Check that the CurrentUserAtom points to the right UserEditAtom
-        CurrentUserAtom cua = wss.getCurrentUserAtom();
-        int listedUEPos = (int)cua.getCurrentEditOffset();
-        assertEquals(lastUEPos,listedUEPos);
+            // Check that the UserEditAtom's point to right stuff
+            for (final Record rec : r) {
+                if (rec instanceof UserEditAtom) {
+                    UserEditAtom uea = (UserEditAtom) rec;
+                    int luPos = uea.getLastUserEditAtomOffset();
+                    int ppPos = uea.getPersistPointersOffset();
+
+                    assertContains(ue, luPos);
+                    assertContains(pp, ppPos);
+                }
+            }
 
-        wss.close();
+            // Check that the CurrentUserAtom points to the right UserEditAtom
+            CurrentUserAtom cua = wss.getCurrentUserAtom();
+            int listedUEPos = (int) cua.getCurrentEditOffset();
+            assertEquals(lastUEPos, listedUEPos);
+        }
     }
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/BaseTestPPTIterating.java Fri May 14 00:37:50 2021
@@ -34,7 +34,7 @@ import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.exceptions.EncryptedPowerPointFileException;
 import org.apache.poi.hslf.exceptions.OldPowerPointFormatException;
 import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.parallel.Isolated;

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/dev/TestSLWTListing.java Fri May 14 00:37:50 2021
@@ -23,7 +23,7 @@ import java.io.IOException;
 import java.io.PrintStream;
 
 import org.apache.poi.EmptyFileException;
-import org.apache.poi.util.NullPrintStream;
+import org.apache.commons.io.output.NullPrintStream;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java Fri May 14 00:37:50 2021
@@ -25,7 +25,6 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -35,7 +34,6 @@ import java.util.List;
 
 import com.zaxxer.sparsebits.SparseBitSet;
 import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.codec.binary.Hex;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.usermodel.HSLFObjectShape;
 import org.apache.poi.hslf.usermodel.HSLFSlideShow;
@@ -50,7 +48,6 @@ import org.apache.poi.sl.usermodel.Objec
 import org.apache.poi.sl.usermodel.SlideShow;
 import org.apache.poi.sl.usermodel.SlideShowFactory;
 import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.NullOutputStream;
 import org.junit.jupiter.api.Test;
 
 /**

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestMovieShape.java Fri May 14 00:37:50 2021
@@ -22,9 +22,8 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.awt.geom.Rectangle2D;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.usermodel.HSLFPictureData;
 import org.apache.poi.hslf.usermodel.HSLFSlide;
@@ -33,11 +32,11 @@ import org.apache.poi.sl.usermodel.Pictu
 import org.junit.jupiter.api.Test;
 
 /**
- * Test <code>MovieShape</code> object.
+ * Test {@code MovieShape} object.
  */
 public final class TestMovieShape {
 
-    private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
+    private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
 
     @Test
     void testCreate() throws Exception {
@@ -58,10 +57,10 @@ public final class TestMovieShape {
         shape.setAutoPlay(false);
         assertFalse(shape.isAutoPlay());
 
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
         ppt.write(out);
 
-        ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
+        ppt = new HSLFSlideShow(out.toInputStream());
         slide = ppt.getSlides().get(0);
         shape = (MovieShape)slide.getShapes().get(0);
         assertEquals(path, shape.getPath());

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestOleEmbedding.java Fri May 14 00:37:50 2021
@@ -21,13 +21,12 @@ import static org.junit.jupiter.api.Asse
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.awt.geom.Rectangle2D;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
 
+import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.hslf.usermodel.HSLFObjectData;
 import org.apache.poi.hslf.usermodel.HSLFObjectShape;
@@ -146,10 +145,10 @@ public final class TestOleEmbedding {
         slide2.addShape(oleShape2);
         oleShape2.setAnchor(new Rectangle2D.Double(100,100,100,100));
 
-    	ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    	UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream();
     	ppt.write(bos);
 
-    	ppt = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
+    	ppt = new HSLFSlideShow(bos.toInputStream());
     	HSLFObjectShape comp = (HSLFObjectShape)ppt.getSlides().get(0).getShapes().get(0);
         byte[] compData = IOUtils.toByteArray(comp.getObjectData().getInputStream());
 

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestSetBoldItalic.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestSetBoldItalic.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestSetBoldItalic.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestSetBoldItalic.java Fri May 14 00:37:50 2021
@@ -17,12 +17,16 @@
 
 package org.apache.poi.hslf.model;
 
-import static org.junit.jupiter.api.Assertions.*;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-
-import org.apache.poi.hslf.usermodel.*;
+import static org.apache.poi.hslf.HSLFTestDataSamples.writeOutAndReadBack;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.poi.hslf.usermodel.HSLFSlide;
+import org.apache.poi.hslf.usermodel.HSLFSlideShow;
+import org.apache.poi.hslf.usermodel.HSLFTextBox;
+import org.apache.poi.hslf.usermodel.HSLFTextRun;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -35,46 +39,46 @@ public final class TestSetBoldItalic {
      */
     @Test
     void testTextBoxWrite() throws Exception {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-        HSLFSlide sl = ppt.createSlide();
-        HSLFTextRun rt;
-
-        String val = "Hello, World!";
-
-        // Create a new textbox, and give it lots of properties
-        HSLFTextBox txtbox = new HSLFTextBox();
-        rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-        txtbox.setText(val);
-        rt.setFontSize(42d);
-        rt.setBold(true);
-        rt.setItalic(true);
-        rt.setUnderlined(false);
-        sl.addShape(txtbox);
-
-        // Check it before save
-        rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-        assertEquals(val, rt.getRawText());
-        assertEquals(42, rt.getFontSize(), 0);
-        assertTrue(rt.isBold());
-        assertTrue(rt.isItalic());
-
-        // Serialize and read again
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ppt.write(out);
-        out.close();
-
-        ppt = new HSLFSlideShow(new HSLFSlideShowImpl(new ByteArrayInputStream(out.toByteArray())));
-        sl = ppt.getSlides().get(0);
-
-        txtbox = (HSLFTextBox)sl.getShapes().get(0);
-        rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-
-        // Check after save
-        assertEquals(val, rt.getRawText());
-        assertEquals(42, rt.getFontSize(), 0);
-        assertTrue(rt.isBold());
-        assertTrue(rt.isItalic());
-        assertFalse(rt.isUnderlined());
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
+            HSLFSlide sl = ppt.createSlide();
+            HSLFTextRun rt;
+
+            String val = "Hello, World!";
+
+            // Create a new textbox, and give it lots of properties
+            HSLFTextBox txtbox = new HSLFTextBox();
+            rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+            txtbox.setText(val);
+            rt.setFontSize(42d);
+            rt.setBold(true);
+            rt.setItalic(true);
+            rt.setUnderlined(false);
+            sl.addShape(txtbox);
+
+            // Check it before save
+            rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+            assertEquals(val, rt.getRawText());
+            assertNotNull(rt.getFontSize());
+            assertEquals(42, rt.getFontSize(), 0);
+            assertTrue(rt.isBold());
+            assertTrue(rt.isItalic());
+
+            // Serialize and read again
+            try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt)) {
+                sl = ppt2.getSlides().get(0);
+
+                txtbox = (HSLFTextBox) sl.getShapes().get(0);
+                rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+
+                // Check after save
+                assertEquals(val, rt.getRawText());
+                assertNotNull(rt.getFontSize());
+                assertEquals(42, rt.getFontSize(), 0);
+                assertTrue(rt.isBold());
+                assertTrue(rt.isItalic());
+                assertFalse(rt.isUnderlined());
+            }
+        }
     }
 
 }

Modified: poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java?rev=1889871&r1=1889870&r2=1889871&view=diff
==============================================================================
--- poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java (original)
+++ poi/trunk/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java Fri May 14 00:37:50 2021
@@ -17,6 +17,9 @@
 
 package org.apache.poi.hslf.model;
 
+import static org.apache.poi.hslf.HSLFTestDataSamples.getSlideShow;
+import static org.apache.poi.hslf.HSLFTestDataSamples.openSampleFileStream;
+import static org.apache.poi.hslf.HSLFTestDataSamples.writeOutAndReadBack;
 import static org.apache.poi.sl.usermodel.BaseTestSlideShow.getColor;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -27,14 +30,10 @@ import static org.junit.jupiter.api.Asse
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.geom.Rectangle2D;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.poi.POIDataSamples;
 import org.apache.poi.ddf.AbstractEscherOptRecord;
 import org.apache.poi.ddf.EscherDgRecord;
 import org.apache.poi.ddf.EscherDggRecord;
@@ -56,68 +55,52 @@ import org.apache.poi.hslf.usermodel.HSL
 import org.apache.poi.sl.usermodel.PictureData.PictureType;
 import org.apache.poi.sl.usermodel.ShapeType;
 import org.apache.poi.sl.usermodel.StrokeStyle.LineDash;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
 /**
  * Test drawing shapes via Graphics2D
  */
 public final class TestShapes {
-    private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
-
-    private HSLFSlideShow ppt;
-    private HSLFSlideShow pptB;
-
-    @BeforeEach
-    void setUp() throws Exception {
-        try (InputStream is1 = _slTests.openResourceAsStream("empty.ppt");
-             InputStream is2 = _slTests.openResourceAsStream("empty_textbox.ppt")) {
-            ppt = new HSLFSlideShow(is1);
-            pptB = new HSLFSlideShow(is2);
-        }
-    }
-
     @Test
     void graphics() throws IOException {
-        HSLFSlide slide = ppt.createSlide();
+        try (HSLFSlideShow ppt = getSlideShow("empty.ppt")) {
+            HSLFSlide slide = ppt.createSlide();
 
-        HSLFLine line = new HSLFLine();
-        java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
-        line.setAnchor(lineAnchor);
-        line.setLineWidth(3);
-        line.setLineDash(LineDash.DASH);
-        line.setLineColor(Color.red);
-        slide.addShape(line);
-
-        HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
-        Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
-        ellipse.setAnchor(ellipseAnchor);
-        ellipse.setLineWidth(2);
-        ellipse.setLineDash(LineDash.SOLID);
-        ellipse.setLineColor(Color.green);
-        ellipse.setFillColor(Color.lightGray);
-        slide.addShape(ellipse);
-
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ppt.write(out);
-        out.close();
-
-        //read ppt from byte array
-
-        HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
-        assertEquals(1, ppt2.getSlides().size());
-
-        slide = ppt2.getSlides().get(0);
-        List<HSLFShape> shape = slide.getShapes();
-        assertEquals(2, shape.size());
+            HSLFLine line = new HSLFLine();
+            java.awt.Rectangle lineAnchor = new java.awt.Rectangle(100, 200, 50, 60);
+            line.setAnchor(lineAnchor);
+            line.setLineWidth(3);
+            line.setLineDash(LineDash.DASH);
+            line.setLineColor(Color.red);
+            slide.addShape(line);
+
+            HSLFAutoShape ellipse = new HSLFAutoShape(ShapeType.ELLIPSE);
+            Rectangle2D ellipseAnchor = new Rectangle2D.Double(320, 154, 55, 111);
+            ellipse.setAnchor(ellipseAnchor);
+            ellipse.setLineWidth(2);
+            ellipse.setLineDash(LineDash.SOLID);
+            ellipse.setLineColor(Color.green);
+            ellipse.setFillColor(Color.lightGray);
+            slide.addShape(ellipse);
+
+            //read ppt from byte array
+            try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt)) {
+                assertEquals(1, ppt2.getSlides().size());
+
+                slide = ppt2.getSlides().get(0);
+                List<HSLFShape> shape = slide.getShapes();
+                assertEquals(2, shape.size());
 
-        assertTrue(shape.get(0) instanceof HSLFLine); //group shape
-        assertEquals(lineAnchor, shape.get(0).getAnchor()); //group shape
+                assertTrue(shape.get(0) instanceof HSLFLine); //group shape
+                assertEquals(lineAnchor, shape.get(0).getAnchor()); //group shape
 
-        assertTrue(shape.get(1) instanceof HSLFAutoShape); //group shape
-        assertEquals(ellipseAnchor, shape.get(1).getAnchor()); //group shape
+                assertTrue(shape.get(1) instanceof HSLFAutoShape); //group shape
+                assertEquals(ellipseAnchor, shape.get(1).getAnchor()); //group shape
 
-        ppt2.close();
+            }
+        }
     }
 
     /**
@@ -125,40 +108,41 @@ public final class TestShapes {
      */
     @Test
     void textBoxRead() throws IOException {
-        ppt = new HSLFSlideShow(_slTests.openResourceAsStream("with_textbox.ppt"));
-        HSLFSlide sl = ppt.getSlides().get(0);
-        for (HSLFShape sh : sl.getShapes()) {
-            assertTrue(sh instanceof HSLFTextBox);
-            HSLFTextBox txtbox = (HSLFTextBox)sh;
-            String text = txtbox.getText();
-            assertNotNull(text);
-
-            assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
-            HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-
-            switch (text) {
-                case "Hello, World!!!":
-                    assertNotNull(rt.getFontSize());
-                    assertEquals(32, rt.getFontSize(), 0);
-                    assertTrue(rt.isBold());
-                    assertTrue(rt.isItalic());
-                    break;
-                case "I am just a poor boy":
-                    assertNotNull(rt.getFontSize());
-                    assertEquals(44, rt.getFontSize(), 0);
-                    assertTrue(rt.isBold());
-                    break;
-                case "This is Times New Roman":
-                    assertNotNull(rt.getFontSize());
-                    assertEquals(16, rt.getFontSize(), 0);
-                    assertTrue(rt.isBold());
-                    assertTrue(rt.isItalic());
-                    assertTrue(rt.isUnderlined());
-                    break;
-                case "Plain Text":
-                    assertNotNull(rt.getFontSize());
-                    assertEquals(18, rt.getFontSize(), 0);
-                    break;
+        try (HSLFSlideShow ppt = getSlideShow("with_textbox.ppt")) {
+            HSLFSlide sl = ppt.getSlides().get(0);
+            for (HSLFShape sh : sl.getShapes()) {
+                assertTrue(sh instanceof HSLFTextBox);
+                HSLFTextBox txtbox = (HSLFTextBox) sh;
+                String text = txtbox.getText();
+                assertNotNull(text);
+
+                assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1);
+                HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+
+                switch (text) {
+                    case "Hello, World!!!":
+                        assertNotNull(rt.getFontSize());
+                        assertEquals(32, rt.getFontSize(), 0);
+                        assertTrue(rt.isBold());
+                        assertTrue(rt.isItalic());
+                        break;
+                    case "I am just a poor boy":
+                        assertNotNull(rt.getFontSize());
+                        assertEquals(44, rt.getFontSize(), 0);
+                        assertTrue(rt.isBold());
+                        break;
+                    case "This is Times New Roman":
+                        assertNotNull(rt.getFontSize());
+                        assertEquals(16, rt.getFontSize(), 0);
+                        assertTrue(rt.isBold());
+                        assertTrue(rt.isItalic());
+                        assertTrue(rt.isUnderlined());
+                        break;
+                    case "Plain Text":
+                        assertNotNull(rt.getFontSize());
+                        assertEquals(18, rt.getFontSize(), 0);
+                        break;
+                }
             }
         }
     }
@@ -166,43 +150,42 @@ public final class TestShapes {
     @SuppressWarnings("unused")
     @Test
     void testParagraphs() throws IOException {
-        HSLFSlideShow ss = new HSLFSlideShow();
-        HSLFSlide slide = ss.createSlide();
-        HSLFTextBox shape = new HSLFTextBox();
-        HSLFTextRun p1r1 = shape.setText("para 1 run 1. ");
-        HSLFTextRun p1r2 = shape.appendText("para 1 run 2.", false);
-        HSLFTextRun p2r1 = shape.appendText("para 2 run 1. ", true);
-        HSLFTextRun p2r2 = shape.appendText("para 2 run 2. ", false);
-        p1r1.setFontColor(Color.black);
-        p1r2.setFontColor(Color.red);
-        p2r1.setFontColor(Color.yellow);
-        p2r2.setStrikethrough(true);
-        // run 3 has same text properties as run 2 and will be merged when saving
-        HSLFTextRun p2r3 = shape.appendText("para 2 run 3.", false);
-        shape.setAnchor(new Rectangle2D.Double(100,100,100,10));
-        slide.addShape(shape);
-        shape.resizeToFitText();
-
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        ss.write(bos);
-
-        ss = new HSLFSlideShow(new ByteArrayInputStream(bos.toByteArray()));
-        slide = ss.getSlides().get(0);
-        HSLFTextBox tb = (HSLFTextBox)slide.getShapes().get(0);
-        List<HSLFTextParagraph> para = tb.getTextParagraphs();
-        HSLFTextRun tr = para.get(0).getTextRuns().get(0);
-        assertEquals("para 1 run 1. ", tr.getRawText());
-        assertEquals(Color.black, getColor(tr.getFontColor()));
-        tr = para.get(0).getTextRuns().get(1);
-        assertEquals("para 1 run 2.\r",  tr.getRawText());
-        assertEquals(Color.red, getColor(tr.getFontColor()));
-        tr = para.get(1).getTextRuns().get(0);
-        assertEquals("para 2 run 1. ", tr.getRawText());
-        assertEquals(Color.yellow, getColor(tr.getFontColor()));
-        tr = para.get(1).getTextRuns().get(1);
-        assertEquals("para 2 run 2. para 2 run 3.", tr.getRawText());
-        assertEquals(Color.black, getColor(tr.getFontColor()));
-        assertTrue(tr.isStrikethrough());
+        try (HSLFSlideShow ppt1 = new HSLFSlideShow()) {
+            HSLFSlide slide = ppt1.createSlide();
+            HSLFTextBox shape = new HSLFTextBox();
+            HSLFTextRun p1r1 = shape.setText("para 1 run 1. ");
+            HSLFTextRun p1r2 = shape.appendText("para 1 run 2.", false);
+            HSLFTextRun p2r1 = shape.appendText("para 2 run 1. ", true);
+            HSLFTextRun p2r2 = shape.appendText("para 2 run 2. ", false);
+            p1r1.setFontColor(Color.black);
+            p1r2.setFontColor(Color.red);
+            p2r1.setFontColor(Color.yellow);
+            p2r2.setStrikethrough(true);
+            // run 3 has same text properties as run 2 and will be merged when saving
+            HSLFTextRun p2r3 = shape.appendText("para 2 run 3.", false);
+            shape.setAnchor(new Rectangle2D.Double(100, 100, 100, 10));
+            slide.addShape(shape);
+            shape.resizeToFitText();
+
+            try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
+                slide = ppt2.getSlides().get(0);
+                HSLFTextBox tb = (HSLFTextBox) slide.getShapes().get(0);
+                List<HSLFTextParagraph> para = tb.getTextParagraphs();
+                HSLFTextRun tr = para.get(0).getTextRuns().get(0);
+                assertEquals("para 1 run 1. ", tr.getRawText());
+                assertEquals(Color.black, getColor(tr.getFontColor()));
+                tr = para.get(0).getTextRuns().get(1);
+                assertEquals("para 1 run 2.\r", tr.getRawText());
+                assertEquals(Color.red, getColor(tr.getFontColor()));
+                tr = para.get(1).getTextRuns().get(0);
+                assertEquals("para 2 run 1. ", tr.getRawText());
+                assertEquals(Color.yellow, getColor(tr.getFontColor()));
+                tr = para.get(1).getTextRuns().get(1);
+                assertEquals("para 2 run 2. para 2 run 3.", tr.getRawText());
+                assertEquals(Color.black, getColor(tr.getFontColor()));
+                assertTrue(tr.isStrikethrough());
+            }
+        }
     }
 
 
@@ -212,169 +195,158 @@ public final class TestShapes {
      */
     @Test
     void textBoxWriteBytes() throws IOException {
-        ppt = new HSLFSlideShow();
-        HSLFSlide sl = ppt.createSlide();
-        HSLFTextRun rt;
-
-        String val = "Hello, World!";
-
-        // Create a new textbox, and give it lots of properties
-        HSLFTextBox txtbox = new HSLFTextBox();
-        rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-        txtbox.setText(val);
-        rt.setFontFamily("Arial");
-        rt.setFontSize(42d);
-        rt.setBold(true);
-        rt.setItalic(true);
-        rt.setUnderlined(false);
-        rt.setFontColor(Color.red);
-        sl.addShape(txtbox);
-
-        // Check it before save
-        rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-        assertEquals(val, rt.getRawText());
-        assertNotNull(rt.getFontSize());
-        assertEquals(42, rt.getFontSize(), 0);
-        assertTrue(rt.isBold());
-        assertTrue(rt.isItalic());
-        assertFalse(rt.isUnderlined());
-        assertEquals("Arial", rt.getFontFamily());
-        assertEquals(Color.red, getColor(rt.getFontColor()));
-
-        // Serialize and read again
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ppt.write(out);
-        out.close();
-
-        HSLFSlideShow ppt2 = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
-        sl = ppt2.getSlides().get(0);
-
-        txtbox = (HSLFTextBox)sl.getShapes().get(0);
-        rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
-
-        // Check after save
-        assertEquals(val, rt.getRawText());
-        assertNotNull(rt.getFontSize());
-        assertEquals(42, rt.getFontSize(), 0);
-        assertTrue(rt.isBold());
-        assertTrue(rt.isItalic());
-        assertFalse(rt.isUnderlined());
-        assertEquals("Arial", rt.getFontFamily());
-        assertEquals(Color.red, getColor(rt.getFontColor()));
+        try (HSLFSlideShow ppt1 = new HSLFSlideShow()) {
+            HSLFSlide sl = ppt1.createSlide();
+
+            String val = "Hello, World!";
 
-        ppt2.close();
+            // Create a new textbox, and give it lots of properties
+            HSLFTextBox txtbox = new HSLFTextBox();
+            HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+            txtbox.setText(val);
+            rt.setFontFamily("Arial");
+            rt.setFontSize(42d);
+            rt.setBold(true);
+            rt.setItalic(true);
+            rt.setUnderlined(false);
+            rt.setFontColor(Color.red);
+            sl.addShape(txtbox);
+
+            // Check it before save
+            rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+            assertEquals(val, rt.getRawText());
+            assertNotNull(rt.getFontSize());
+            assertEquals(42, rt.getFontSize(), 0);
+            assertTrue(rt.isBold());
+            assertTrue(rt.isItalic());
+            assertFalse(rt.isUnderlined());
+            assertEquals("Arial", rt.getFontFamily());
+            assertEquals(Color.red, getColor(rt.getFontColor()));
+
+            // Serialize and read again
+            try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
+                sl = ppt2.getSlides().get(0);
+
+                txtbox = (HSLFTextBox) sl.getShapes().get(0);
+                rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0);
+
+                // Check after save
+                assertEquals(val, rt.getRawText());
+                assertNotNull(rt.getFontSize());
+                assertEquals(42, rt.getFontSize(), 0);
+                assertTrue(rt.isBold());
+                assertTrue(rt.isItalic());
+                assertFalse(rt.isUnderlined());
+                assertEquals("Arial", rt.getFontFamily());
+                assertEquals(Color.red, getColor(rt.getFontColor()));
+            }
+        }
     }
 
     /**
      * Test with an empty text box
      */
     @Test
-    void emptyTextBox() {
-    	assertEquals(2, pptB.getSlides().size());
-    	HSLFSlide s1 = pptB.getSlides().get(0);
-    	HSLFSlide s2 = pptB.getSlides().get(1);
-
-    	// Check we can get the shapes count
-    	assertEquals(2, s1.getShapes().size());
-    	assertEquals(2, s2.getShapes().size());
+    void emptyTextBox() throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow("empty_textbox.ppt")) {
+            assertEquals(2, ppt.getSlides().size());
+            HSLFSlide s1 = ppt.getSlides().get(0);
+            HSLFSlide s2 = ppt.getSlides().get(1);
+
+            // Check we can get the shapes count
+            assertEquals(2, s1.getShapes().size());
+            assertEquals(2, s2.getShapes().size());
+        }
     }
 
     /**
      * If you iterate over text shapes in a slide and collect them in a set
      * it must be the same as returned by Slide.getTextRuns().
      */
-    @Test
-    void textBoxSet() throws IOException {
-        textBoxSet("with_textbox.ppt");
-        textBoxSet("basic_test_ppt_file.ppt");
-        textBoxSet("next_test_ppt_file.ppt");
-        textBoxSet("Single_Coloured_Page.ppt");
-        textBoxSet("Single_Coloured_Page_With_Fonts_and_Alignments.ppt");
-        textBoxSet("incorrect_slide_order.ppt");
-    }
-
-    private void textBoxSet(String filename) throws IOException {
-        HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream(filename));
-        for (HSLFSlide sld : ss.getSlides()) {
-            ArrayList<String> lst1 = new ArrayList<>();
-            for (List<HSLFTextParagraph> txt : sld.getTextParagraphs()) {
-                for (HSLFTextParagraph p : txt) {
-                    for (HSLFTextRun r : p) {
-                        lst1.add(r.getRawText());
+    @ParameterizedTest
+    @ValueSource(strings = {
+        "with_textbox.ppt",
+        "basic_test_ppt_file.ppt",
+        "next_test_ppt_file.ppt",
+        "Single_Coloured_Page.ppt",
+        "Single_Coloured_Page_With_Fonts_and_Alignments.ppt",
+        "incorrect_slide_order.ppt"
+    })
+    void textBoxSet(String filename) throws IOException {
+        try (HSLFSlideShow ppt = getSlideShow(filename)) {
+            for (HSLFSlide sld : ppt.getSlides()) {
+                ArrayList<String> lst1 = new ArrayList<>();
+                for (List<HSLFTextParagraph> txt : sld.getTextParagraphs()) {
+                    for (HSLFTextParagraph p : txt) {
+                        for (HSLFTextRun r : p) {
+                            lst1.add(r.getRawText());
+                        }
                     }
                 }
-            }
 
-            ArrayList<String> lst2 = new ArrayList<>();
-            for (HSLFShape sh : sld.getShapes()) {
-                if (sh instanceof HSLFTextShape){
-                    HSLFTextShape tbox = (HSLFTextShape)sh;
-                    for (HSLFTextParagraph p : tbox.getTextParagraphs()) {
-                        for (HSLFTextRun r : p) {
-                            lst2.add(r.getRawText());
+                ArrayList<String> lst2 = new ArrayList<>();
+                for (HSLFShape sh : sld.getShapes()) {
+                    if (sh instanceof HSLFTextShape) {
+                        HSLFTextShape tbox = (HSLFTextShape) sh;
+                        for (HSLFTextParagraph p : tbox.getTextParagraphs()) {
+                            for (HSLFTextRun r : p) {
+                                lst2.add(r.getRawText());
+                            }
                         }
                     }
                 }
+                assertTrue(lst1.containsAll(lst2));
+                assertTrue(lst2.containsAll(lst1));
             }
-            assertTrue(lst1.containsAll(lst2));
-            assertTrue(lst2.containsAll(lst1));
         }
-        ss.close();
     }
 
     /**
-     * Test adding shapes to <code>ShapeGroup</code>
+     * Test adding shapes to {@code ShapeGroup}
      */
     @Test
     void shapeGroup() throws IOException {
-        HSLFSlideShow ss = new HSLFSlideShow();
-
-        HSLFSlide slide = ss.createSlide();
-        Dimension pgsize = ss.getPageSize();
+        try (HSLFSlideShow ppt1 = new HSLFSlideShow()) {
 
-        HSLFGroupShape group = new HSLFGroupShape();
+            HSLFSlide slide = ppt1.createSlide();
+            Dimension pgsize = ppt1.getPageSize();
 
-        group.setAnchor(new Rectangle2D.Double(0, 0, pgsize.getWidth(), pgsize.getHeight()));
-        slide.addShape(group);
+            HSLFGroupShape group = new HSLFGroupShape();
 
-        HSLFPictureData data = ss.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
-        HSLFPictureShape pict = new HSLFPictureShape(data, group);
-        pict.setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
-        group.addShape(pict);
+            group.setAnchor(new Rectangle2D.Double(0, 0, pgsize.getWidth(), pgsize.getHeight()));
+            slide.addShape(group);
 
-        HSLFLine line = new HSLFLine(group);
-        line.setAnchor(new Rectangle2D.Double(300, 300, 500, 0));
-        group.addShape(line);
+            HSLFPictureData data = ppt1.addPicture(openSampleFileStream("clock.jpg"), PictureType.JPEG);
+            HSLFPictureShape pict = new HSLFPictureShape(data, group);
+            pict.setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
+            group.addShape(pict);
 
-        //serialize and read again.
-        ByteArrayOutputStream  out = new ByteArrayOutputStream();
-        ss.write(out);
-        out.close();
-        ss.close();
+            HSLFLine line = new HSLFLine(group);
+            line.setAnchor(new Rectangle2D.Double(300, 300, 500, 0));
+            group.addShape(line);
 
-        ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
-        ss = new HSLFSlideShow(is);
-        is.close();
+            //serialize and read again.
+            try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
 
-        slide = ss.getSlides().get(0);
+                slide = ppt2.getSlides().get(0);
 
-        List<HSLFShape> shape = slide.getShapes();
-        assertEquals(1, shape.size());
-        assertTrue(shape.get(0) instanceof HSLFGroupShape);
+                List<HSLFShape> shape = slide.getShapes();
+                assertEquals(1, shape.size());
+                assertTrue(shape.get(0) instanceof HSLFGroupShape);
 
-        group = (HSLFGroupShape)shape.get(0);
-        List<HSLFShape> grshape = group.getShapes();
-        assertEquals(2, grshape.size());
-        assertTrue(grshape.get(0) instanceof HSLFPictureShape);
-        assertTrue(grshape.get(1) instanceof HSLFLine);
+                group = (HSLFGroupShape) shape.get(0);
+                List<HSLFShape> grshape = group.getShapes();
+                assertEquals(2, grshape.size());
+                assertTrue(grshape.get(0) instanceof HSLFPictureShape);
+                assertTrue(grshape.get(1) instanceof HSLFLine);
 
-        pict = (HSLFPictureShape)grshape.get(0);
-        assertEquals(new Rectangle2D.Double(0, 0, 200, 200), pict.getAnchor());
+                pict = (HSLFPictureShape) grshape.get(0);
+                assertEquals(new Rectangle2D.Double(0, 0, 200, 200), pict.getAnchor());
 
-        line = (HSLFLine)grshape.get(1);
-        assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
-
-        ss.close();
+                line = (HSLFLine) grshape.get(1);
+                assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
+            }
+        }
     }
 
     /**
@@ -382,29 +354,24 @@ public final class TestShapes {
      */
     @Test
     void removeShapes() throws IOException {
-        String file = "with_textbox.ppt";
-        HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream(file));
-        HSLFSlide sl = ss.getSlides().get(0);
-        List<HSLFShape> sh = sl.getShapes();
-        assertEquals(4, sh.size(), "expected four shaped in " + file);
-        //remove all
-        for (int i = 0; i < sh.size(); i++) {
-            boolean ok = sl.removeShape(sh.get(i));
-            assertTrue(ok, "Failed to delete shape #" + i);
-        }
-        //now Slide.getShapes() should return an empty array
-        assertEquals(0, sl.getShapes().size(), "expected 0 shaped in " + file);
+        try (HSLFSlideShow ppt1 = getSlideShow("with_textbox.ppt")) {
+            HSLFSlide sl = ppt1.getSlides().get(0);
+            List<HSLFShape> sh = sl.getShapes();
+            assertEquals(4, sh.size());
+            //remove all
+            for (int i = 0; i < sh.size(); i++) {
+                boolean ok = sl.removeShape(sh.get(i));
+                assertTrue(ok, "Failed to delete shape #" + i);
+            }
+            //now Slide.getShapes() should return an empty array
+            assertEquals(0, sl.getShapes().size());
 
-        //serialize and read again. The file should be readable and contain no shapes
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        ss.write(out);
-        out.close();
-        ss.close();
-
-        ss = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
-        sl = ss.getSlides().get(0);
-        assertEquals(0, sl.getShapes().size(), "expected 0 shaped in " + file);
-        ss.close();
+            //serialize and read again. The file should be readable and contain no shapes
+            try (HSLFSlideShow ppt2 = writeOutAndReadBack(ppt1)) {
+                sl = ppt2.getSlides().get(0);
+                assertEquals(0, sl.getShapes().size());
+            }
+        }
     }
 
     @Test
@@ -424,79 +391,78 @@ public final class TestShapes {
 
     @Test
     void shapeId() throws IOException {
-        HSLFSlideShow ss = new HSLFSlideShow();
-        HSLFSlide slide = ss.createSlide();
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
+            HSLFSlide slide = ppt.createSlide();
 
-        //EscherDgg is a document-level record which keeps track of the drawing groups
-        EscherDggRecord dgg = ss.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
-        EscherDgRecord dg = slide.getSheetContainer().getPPDrawing().getEscherDgRecord();
-
-        int dggShapesUsed = dgg.getNumShapesSaved();   //total number of shapes in the ppt
-        int dggMaxId = dgg.getShapeIdMax();            //max number of shapeId
-
-        int dgMaxId = dg.getLastMSOSPID();   //max shapeId in the slide
-        int dgShapesUsed = dg.getNumShapes();          // number of shapes in the slide
-        //insert 3 shapes and make sure the Ids are properly incremented
-        for (int i = 0; i < 3; i++) {
-            HSLFShape shape = new HSLFLine();
-            assertEquals(0, shape.getShapeId());
-            slide.addShape(shape);
-            assertTrue(shape.getShapeId() > 0);
-
-            //check that EscherDgRecord is updated
-            assertEquals(shape.getShapeId(), dg.getLastMSOSPID());
-            assertEquals(dgMaxId + 1, dg.getLastMSOSPID());
-            assertEquals(dgShapesUsed + 1, dg.getNumShapes());
-
-            //check that EscherDggRecord is updated
-            assertEquals(shape.getShapeId() + 1, dgg.getShapeIdMax(), "mismatch @"+i);
-            assertEquals(dggMaxId + 1, dgg.getShapeIdMax(), "mismatch @"+i);
-            assertEquals(dggShapesUsed + 1, dgg.getNumShapesSaved(), "mismatch @"+i);
-
-            dggShapesUsed = dgg.getNumShapesSaved();
-            dggMaxId = dgg.getShapeIdMax();
-            dgMaxId = dg.getLastMSOSPID();
-            dgShapesUsed = dg.getNumShapes();
-        }
+            //EscherDgg is a document-level record which keeps track of the drawing groups
+            EscherDggRecord dgg = ppt.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
+            EscherDgRecord dg = slide.getSheetContainer().getPPDrawing().getEscherDgRecord();
+
+            int dggShapesUsed = dgg.getNumShapesSaved();   //total number of shapes in the ppt
+            int dggMaxId = dgg.getShapeIdMax();            //max number of shapeId
+
+            int dgMaxId = dg.getLastMSOSPID();   //max shapeId in the slide
+            int dgShapesUsed = dg.getNumShapes();          // number of shapes in the slide
+            //insert 3 shapes and make sure the Ids are properly incremented
+            for (int i = 0; i < 3; i++) {
+                HSLFShape shape = new HSLFLine();
+                assertEquals(0, shape.getShapeId());
+                slide.addShape(shape);
+                assertTrue(shape.getShapeId() > 0);
+
+                //check that EscherDgRecord is updated
+                assertEquals(shape.getShapeId(), dg.getLastMSOSPID());
+                assertEquals(dgMaxId + 1, dg.getLastMSOSPID());
+                assertEquals(dgShapesUsed + 1, dg.getNumShapes());
+
+                //check that EscherDggRecord is updated
+                assertEquals(shape.getShapeId() + 1, dgg.getShapeIdMax(), "mismatch @" + i);
+                assertEquals(dggMaxId + 1, dgg.getShapeIdMax(), "mismatch @" + i);
+                assertEquals(dggShapesUsed + 1, dgg.getNumShapesSaved(), "mismatch @" + i);
+
+                dggShapesUsed = dgg.getNumShapesSaved();
+                dggMaxId = dgg.getShapeIdMax();
+                dgMaxId = dg.getLastMSOSPID();
+                dgShapesUsed = dg.getNumShapes();
+            }
 
 
-        //For each drawing group PPT allocates clusters with size=1024
-        //if the number of shapes is greater that 1024 a new cluster is allocated
-        //make sure it is so
-        int numClusters = dgg.getNumIdClusters();
-        for (int i = 0; i < 1025; i++) {
-            HSLFShape shape = new HSLFLine();
-            slide.addShape(shape);
+            //For each drawing group PPT allocates clusters with size=1024
+            //if the number of shapes is greater that 1024 a new cluster is allocated
+            //make sure it is so
+            int numClusters = dgg.getNumIdClusters();
+            for (int i = 0; i < 1025; i++) {
+                HSLFShape shape = new HSLFLine();
+                slide.addShape(shape);
+            }
+            assertEquals(numClusters + 1, dgg.getNumIdClusters());
         }
-        assertEquals(numClusters + 1, dgg.getNumIdClusters());
-        ss.close();
     }
 
     @Test
     void lineColor() throws IOException {
-        HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream("51731.ppt"));
-        List<HSLFShape> shape = ss.getSlides().get(0).getShapes();
+        try (HSLFSlideShow ss = getSlideShow("51731.ppt")) {
+            List<HSLFShape> shape = ss.getSlides().get(0).getShapes();
 
-        assertEquals(4, shape.size());
+            assertEquals(4, shape.size());
 
-        HSLFTextShape sh1 = (HSLFTextShape)shape.get(0);
-        assertEquals("Hello Apache POI", sh1.getText());
-        assertNull(sh1.getLineColor());
-
-        HSLFTextShape sh2 = (HSLFTextShape)shape.get(1);
-        assertEquals("Why are you showing this border?", sh2.getText());
-        assertNull(sh2.getLineColor());
-
-        HSLFTextShape sh3 = (HSLFTextShape)shape.get(2);
-        assertEquals("Text in a black border", sh3.getText());
-        assertEquals(Color.black, sh3.getLineColor());
-        assertEquals(0.75, sh3.getLineWidth(), 0);
-
-        HSLFTextShape sh4 = (HSLFTextShape)shape.get(3);
-        assertEquals("Border width is 5 pt", sh4.getText());
-        assertEquals(Color.black, sh4.getLineColor());
-        assertEquals(5.0, sh4.getLineWidth(), 0);
-
-        ss.close();
+            HSLFTextShape sh1 = (HSLFTextShape) shape.get(0);
+            assertEquals("Hello Apache POI", sh1.getText());
+            assertNull(sh1.getLineColor());
+
+            HSLFTextShape sh2 = (HSLFTextShape) shape.get(1);
+            assertEquals("Why are you showing this border?", sh2.getText());
+            assertNull(sh2.getLineColor());
+
+            HSLFTextShape sh3 = (HSLFTextShape) shape.get(2);
+            assertEquals("Text in a black border", sh3.getText());
+            assertEquals(Color.black, sh3.getLineColor());
+            assertEquals(0.75, sh3.getLineWidth(), 0);
+
+            HSLFTextShape sh4 = (HSLFTextShape) shape.get(3);
+            assertEquals("Border width is 5 pt", sh4.getText());
+            assertEquals(Color.black, sh4.getLineColor());
+            assertEquals(5.0, sh4.getLineWidth(), 0);
+        }
     }
 }



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