poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1592315 - in /poi/trunk/src: java/org/apache/poi/hpsf/MutablePropertySet.java testcases/org/apache/poi/hpsf/basic/TestWrite.java testcases/org/apache/poi/hpsf/basic/Util.java
Date Sun, 04 May 2014 08:05:32 GMT
Author: centic
Date: Sun May  4 08:05:32 2014
New Revision: 1592315

URL: http://svn.apache.org/r1592315
Log:
File leak detector: Close streams in some tests

Modified:
    poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
    poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
    poi/trunk/src/testcases/org/apache/poi/hpsf/basic/Util.java

Modified: poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java?rev=1592315&r1=1592314&r2=1592315&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java Sun May  4 08:05:32 2014
@@ -269,8 +269,11 @@ public class MutablePropertySet extends 
         throws IOException, WritingNotSupportedException
     {
         final ByteArrayOutputStream psStream = new ByteArrayOutputStream();
-        write(psStream);
-        psStream.close();
+        try {
+            write(psStream);
+        } finally {
+            psStream.close();
+        }
         final byte[] streamData = psStream.toByteArray();
         return new ByteArrayInputStream(streamData);
     }

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java?rev=1592315&r1=1592314&r2=1592315&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java Sun May  4 08:05:32 2014
@@ -189,7 +189,12 @@ public class TestWrite
         final POIFSReader r = new POIFSReader();
         r.registerListener(new MyPOIFSReaderListener(),
                            SummaryInformation.DEFAULT_STREAM_NAME);
-        r.read(new FileInputStream(filename));
+        FileInputStream stream = new FileInputStream(filename);
+        try {
+            r.read(stream);
+        } finally {
+            stream.close();
+        }
     }
 
 
@@ -251,7 +256,13 @@ public class TestWrite
 
             },
             SummaryInformation.DEFAULT_STREAM_NAME);
-        r.read(new FileInputStream(filename));
+        
+        InputStream stream = new FileInputStream(filename);
+        try {
+            r.read(stream);
+        } finally {
+            stream.close();
+        }
         assertNotNull(psa[0]);
         assertTrue(psa[0].isSummaryInformation());
 
@@ -329,7 +340,12 @@ public class TestWrite
                 }
             },
             STREAM_NAME);
-        r.read(new FileInputStream(filename));
+        FileInputStream stream = new FileInputStream(filename);
+        try {
+            r.read(stream);
+        } finally {
+            stream.close();
+        }
         assertNotNull(psa[0]);
         Section s = (Section) (psa[0].getSections().get(0));
         assertEquals(s.getFormatID(), formatID);
@@ -996,20 +1012,22 @@ public class TestWrite
     @Test
     public void dictionaryWithInvalidCodepage() throws IOException, HPSFException
     {
+        final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
+        copy.deleteOnExit();
+        
+        /* Write: */
+        final OutputStream out = new FileOutputStream(copy);
+        
+        final POIFSFileSystem poiFs = new POIFSFileSystem();
+        final MutablePropertySet ps1 = new MutablePropertySet();
+        final MutableSection s = (MutableSection) ps1.getSections().get(0);
+        final Map<Long,String> m = new HashMap<Long, String>(3, 1.0f);
+        m.put(Long.valueOf(1), "String 1");
+        m.put(Long.valueOf(2), "String 2");
+        m.put(Long.valueOf(3), "String 3");
+
         try
         {
-            final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
-            copy.deleteOnExit();
-
-            /* Write: */
-            final OutputStream out = new FileOutputStream(copy);
-            final POIFSFileSystem poiFs = new POIFSFileSystem();
-            final MutablePropertySet ps1 = new MutablePropertySet();
-            final MutableSection s = (MutableSection) ps1.getSections().get(0);
-            final Map<Long,String> m = new HashMap<Long, String>(3, 1.0f);
-            m.put(Long.valueOf(1), "String 1");
-            m.put(Long.valueOf(2), "String 2");
-            m.put(Long.valueOf(3), "String 3");
             s.setDictionary(m);
             s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]);
             int codepage = 12345;
@@ -1022,6 +1040,7 @@ public class TestWrite
         }
         catch (IllegalPropertySetDataException ex)
         {
+            out.close();
             assertTrue(true);
         }
     }

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/basic/Util.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/basic/Util.java?rev=1592315&r1=1592314&r2=1592315&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/basic/Util.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/basic/Util.java Sun May  4 08:05:32 2014
@@ -229,7 +229,13 @@ final class Util {
         r.registerListener(pfl);
 
         /* Read the POI filesystem. */
-        r.read(new FileInputStream(poiFs));
+        FileInputStream stream = new FileInputStream(poiFs);
+        try {
+            r.read(stream);
+        } finally {
+            stream.close();
+        }
+
         POIFile[] result = new POIFile[files.size()];
         for (int i = 0; i < result.length; i++)
             result[i] = (POIFile) files.get(i);



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


Mime
View raw message