poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1721468 - in /poi/trunk/src: java/org/apache/poi/hssf/dev/ ooxml/testcases/org/apache/poi/openxml4j/opc/ ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/ ooxml/testcases/org/apache/poi/ss/ ooxml/testcases/org/apache/poi/xssf/stream...
Date Tue, 22 Dec 2015 22:36:00 GMT
Author: centic
Date: Tue Dec 22 22:35:59 2015
New Revision: 1721468

URL: http://svn.apache.org/viewvc?rev=1721468&view=rev
Log:
Fix freeing resources in some tests and dev-tools so we can run unit-tests with enabled file-leak-detector

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java
    poi/trunk/src/java/org/apache/poi/hssf/dev/RecordLister.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFFormulaEvaluation.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
    poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java
    poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
    poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
    poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/dev/EFBiffViewer.java Tue Dec 22 22:35:59 2015
@@ -44,21 +44,27 @@ public class EFBiffViewer
 
     public void run() throws IOException {
         NPOIFSFileSystem fs   = new NPOIFSFileSystem(new File(file), true);
-        InputStream     din   = BiffViewer.getPOIFSInputStream(fs);
-        HSSFRequest     req   = new HSSFRequest();
-
-        req.addListenerForAllRecords(new HSSFListener()
-        {
-            public void processRecord(Record rec)
-            {
-                System.out.println(rec.toString());
+        try {
+            InputStream     din   = BiffViewer.getPOIFSInputStream(fs);
+            try {
+                HSSFRequest     req   = new HSSFRequest();
+        
+                req.addListenerForAllRecords(new HSSFListener()
+                {
+                    public void processRecord(Record rec)
+                    {
+                        System.out.println(rec.toString());
+                    }
+                });
+                HSSFEventFactory factory = new HSSFEventFactory();
+        
+                factory.processEvents(req, din);
+            } finally {
+                din.close();
             }
-        });
-        HSSFEventFactory factory = new HSSFEventFactory();
-
-        factory.processEvents(req, din);
-        din.close();
-        fs.close();
+        } finally {
+            fs.close();
+        }
     }
 
     public void setFile(String file)

Modified: poi/trunk/src/java/org/apache/poi/hssf/dev/RecordLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/dev/RecordLister.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/dev/RecordLister.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/dev/RecordLister.java Tue Dec 22 22:35:59 2015
@@ -51,37 +51,42 @@ public class RecordLister
         throws IOException
     {
         NPOIFSFileSystem  fs    = new NPOIFSFileSystem(new File(file), true);
-        InputStream       din   = BiffViewer.getPOIFSInputStream(fs);
-        RecordInputStream rinp  = new RecordInputStream(din);
-
-        while(rinp.hasNextRecord()) {
-           int sid  = rinp.getNextSid();
-           rinp.nextRecord();
-           
-           int size = rinp.available();
-           Class<? extends Record> clz = RecordFactory.getRecordClass(sid);
-           
-           System.out.print(
-                 formatSID(sid) +
-                 " - " +
-                 formatSize(size) +
-                 " bytes"
-           );
-           if(clz != null) {
-              System.out.print("  \t");
-              System.out.print(clz.getName().replace("org.apache.poi.hssf.record.", ""));
-           }
-           System.out.println();
-           
-           byte[] data = rinp.readRemainder();
-           if(data.length > 0) {
-              System.out.print("   ");
-              System.out.println( formatData(data) );
-           }
-        }
+        try {
+            InputStream       din   = BiffViewer.getPOIFSInputStream(fs);
+            try {
+                RecordInputStream rinp  = new RecordInputStream(din);
         
-        din.close();
-        fs.close();
+                while(rinp.hasNextRecord()) {
+                   int sid  = rinp.getNextSid();
+                   rinp.nextRecord();
+                   
+                   int size = rinp.available();
+                   Class<? extends Record> clz = RecordFactory.getRecordClass(sid);
+                   
+                   System.out.print(
+                         formatSID(sid) +
+                         " - " +
+                         formatSize(size) +
+                         " bytes"
+                   );
+                   if(clz != null) {
+                      System.out.print("  \t");
+                      System.out.print(clz.getName().replace("org.apache.poi.hssf.record.",
""));
+                   }
+                   System.out.println();
+                   
+                   byte[] data = rinp.readRemainder();
+                   if(data.length > 0) {
+                      System.out.print("   ");
+                      System.out.println( formatData(data) );
+                   }
+                }
+            } finally {
+                din.close();
+            }
+        } finally {
+            fs.close();
+        }
     }
     
     private static String formatSID(int sid) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java Tue Dec 22
22:35:59 2015
@@ -716,6 +716,7 @@ public final class TestPackage {
         Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(buf));
         wb.getSheetAt(0);
         wb.close();
+        zipFile.close();
     }
     
     @Test

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/openxml4j/opc/compliance/TestOPCComplianceCoreProperties.java
Tue Dec 22 22:35:59 2015
@@ -26,9 +26,6 @@ import java.io.InputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
@@ -41,6 +38,9 @@ import org.apache.poi.openxml4j.opc.Targ
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.TempFile;
 
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+
 /**
  * Test core properties Open Packaging Convention compliance.
  * 
@@ -249,6 +249,7 @@ public final class TestOPCComplianceCore
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pkg.save(baos);
         ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        pkg.revert();
 
         pkg = OPCPackage.open(bais);
 
@@ -257,7 +258,7 @@ public final class TestOPCComplianceCore
         assertNotNull(pkg.getPackageProperties());
         assertNotNull(pkg.getPackageProperties().getLanguageProperty());
         assertNull(pkg.getPackageProperties().getLanguageProperty().getValue());
-        
+        pkg.close();
         
         // Open a new copy of it
         pkg = OPCPackage.open(POIDataSamples.getOpenXML4JInstance().getFile(sampleFileName).getPath());
@@ -265,6 +266,8 @@ public final class TestOPCComplianceCore
         // Save and re-load, without having touched the properties yet
         baos = new ByteArrayOutputStream();
         pkg.save(baos);
+        pkg.revert();
+
         bais = new ByteArrayInputStream(baos.toByteArray());
         pkg = OPCPackage.open(bais);
         
@@ -285,10 +288,12 @@ public final class TestOPCComplianceCore
         // Copy this into a temp file, so we can play with it
         File tmp = TempFile.createTempFile("poi-test", ".opc");
         FileOutputStream out = new FileOutputStream(tmp);
+        InputStream in = POIDataSamples.getOpenXML4JInstance().openResourceAsStream(sampleFileName);
         IOUtils.copy(
-                POIDataSamples.getOpenXML4JInstance().openResourceAsStream(sampleFileName),
+                in,
                 out);
         out.close();
+        in.close();
 
         // Open it from that temp file
         OPCPackage pkg = OPCPackage.open(tmp);
@@ -302,7 +307,6 @@ public final class TestOPCComplianceCore
         // Save and close
         pkg.close();
 
-
         // Re-open and check
         pkg = OPCPackage.open(tmp);
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/TestWorkbookFactory.java Tue Dec 22 22:35:59
2015
@@ -228,7 +228,7 @@ public final class TestWorkbookFactory e
         );
         assertNotNull(wb);
         assertTrue(wb instanceof XSSFWorkbook);
-
+        wb.close();
 
         // Unprotected, wrong password, opens normally
         wb = WorkbookFactory.create(
@@ -243,7 +243,7 @@ public final class TestWorkbookFactory e
         );
         assertNotNull(wb);
         assertTrue(wb instanceof XSSFWorkbook);
-
+        wb.close();
 
         // Protected, correct password, opens fine
         wb = WorkbookFactory.create(
@@ -258,7 +258,7 @@ public final class TestWorkbookFactory e
         );
         assertNotNull(wb);
         assertTrue(wb instanceof XSSFWorkbook);
-
+        wb.close();
 
         // Protected, wrong password, throws Exception
         try {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFFormulaEvaluation.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFFormulaEvaluation.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFFormulaEvaluation.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFFormulaEvaluation.java
Tue Dec 22 22:35:59 2015
@@ -71,7 +71,8 @@ public final class TestSXSSFFormulaEvalu
         XSSFWorkbook xwb = new XSSFWorkbook();
         xwb.createSheet("Open");
         xwb.createSheet("Closed");
-        
+
+        wb.close();
         wb = new SXSSFWorkbook(xwb, 5);
         s = wb.getSheet("Closed");
         s.flushRows();
@@ -83,10 +84,12 @@ public final class TestSXSSFFormulaEvalu
             eval.evaluateAll();
             fail("Evaluate All shouldn't work, as sheets flushed");
         } catch (SXSSFFormulaEvaluator.SheetsFlushedException e) {}
+        
+        wb.close();
     }
     
     @Test
-    public void testEvaluateRefOutsideWindowFails() {
+    public void testEvaluateRefOutsideWindowFails() throws IOException {
         SXSSFWorkbook wb = new SXSSFWorkbook(5);
         SXSSFSheet s = wb.createSheet();
         
@@ -108,14 +111,17 @@ public final class TestSXSSFFormulaEvalu
         } catch(SXSSFFormulaEvaluator.RowFlushedException e) {
             // Expected
         }
+        
+        wb.close();
     }
     
     /**
      * If all formula cells + their references are inside the window,
      *  then evaluation works
+     * @throws IOException 
      */
     @Test
-    public void testEvaluateAllInWindow() {
+    public void testEvaluateAllInWindow() throws IOException {
         SXSSFWorkbook wb = new SXSSFWorkbook(5);
         SXSSFSheet s = wb.createSheet();
         s.createRow(0).createCell(0).setCellFormula("1+2");
@@ -128,10 +134,12 @@ public final class TestSXSSFFormulaEvalu
         assertEquals(3, (int)s.getRow(0).getCell(0).getNumericCellValue());
         assertEquals(13, (int)s.getRow(1).getCell(1).getNumericCellValue());
         assertEquals(113, (int)s.getRow(2).getCell(2).getNumericCellValue());
+        
+        wb.close();
     }
     
     @Test
-    public void testEvaluateRefInsideWindow() {
+    public void testEvaluateRefInsideWindow() throws IOException {
         SXSSFWorkbook wb = new SXSSFWorkbook(5);
         SXSSFSheet s = wb.createSheet();
         
@@ -146,10 +154,12 @@ public final class TestSXSSFFormulaEvalu
         assertEquals(0, (int)c.getNumericCellValue());
         eval.evaluateFormulaCell(c);
         assertEquals(3, (int)c.getNumericCellValue());
+        
+        wb.close();
     }
     
     @Test
-    public void testEvaluateSimple() {
+    public void testEvaluateSimple() throws IOException {
         SXSSFWorkbook wb = new SXSSFWorkbook(5);
         SXSSFSheet s = wb.createSheet();
         
@@ -165,5 +175,7 @@ public final class TestSXSSFFormulaEvalu
         c.setCellFormula("CONCATENATE(\"hello\",\" \",\"world\")");
         eval.evaluateFormulaCell(c);
         assertEquals("hello world", c.getStringCellValue());
+        
+        wb.close();
     }
 }

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/extractor/TestExtractor.java Tue
Dec 22 22:35:59 2015
@@ -129,6 +129,7 @@ public final class TestExtractor {
 	 */
     @Test
 	public void testMissingCoreRecords() throws Exception {
+        ppe.close();
 		ppe = new PowerPointExtractor(slTests.openResourceAsStream("missing_core_records.ppt"));
 
 		String text = ppe.getText(true, false);
@@ -171,6 +172,7 @@ public final class TestExtractor {
 
          // Check the first file
          ss = new HSLFSlideShowImpl(dirA);
+         ppe.close();
          ppe = new PowerPointExtractor(ss);
          assertEquals("Sample PowerPoint file\nThis is the 1st file\nNot much too it\n",
                  ppe.getText(true, false)
@@ -178,6 +180,7 @@ public final class TestExtractor {
 
          // And the second
          ss = new HSLFSlideShowImpl(dirB);
+         ppe.close();
          ppe = new PowerPointExtractor(ss);
          assertEquals("Sample PowerPoint file\nThis is the 2nd file\nNot much too it either\n",
                  ppe.getText(true, false)
@@ -192,6 +195,7 @@ public final class TestExtractor {
      @Test
      public void testExtractFromOwnEmbeded() throws Exception {
          String path = "ppt_with_embeded.ppt";
+         ppe.close();
          ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
          List<OLEShape> shapes = ppe.getOLEShapes();
          assertEquals("Expected 6 ole shapes in " + path, 6, shapes.size());
@@ -209,6 +213,7 @@ public final class TestExtractor {
              } else if ("Presentation".equals(name)) {
                  num_ppt++;
                  HSLFSlideShow ppt = new HSLFSlideShow(data);
+                 ppt.close();
              }
              data.close();
          }
@@ -223,6 +228,7 @@ public final class TestExtractor {
     @Test
     public void test52991() throws Exception {
         String path = "badzip.ppt";
+        ppe.close();
         ppe = new PowerPointExtractor(POIDataSamples.getSlideShowInstance().openResourceAsStream(path));
         List<OLEShape> shapes = ppe.getOLEShapes();
         
@@ -236,6 +242,7 @@ public final class TestExtractor {
      */
     @Test
     public void testWithComments() throws Exception {
+        ppe.close();
 		ppe = new PowerPointExtractor(slTests.openResourceAsStream("WithComments.ppt"));
 
 		String text = ppe.getText();
@@ -248,6 +255,7 @@ public final class TestExtractor {
 
 		
 		// And another file
+        ppe.close();
 		ppe = new PowerPointExtractor(slTests.openResourceAsStream("45543.ppt"));
 
 		text = ppe.getText();
@@ -271,6 +279,7 @@ public final class TestExtractor {
        HSLFSlideShow ss = new HSLFSlideShow(hslf);
        assertNotNull(ss.getNotesHeadersFooters());
        assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getHeaderText());
+       ppe.close();
 
        ppe = new PowerPointExtractor(hslf);
 
@@ -282,13 +291,14 @@ public final class TestExtractor {
        text = ppe.getText();
        assertContains(text, "testdoc");
        assertContains(text, "test phrase");
-
+       ss.close();
 
        // And with a footer, also on notes
        hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("45537_Footer.ppt"));
        ss = new HSLFSlideShow(hslf);
        assertNotNull(ss.getNotesHeadersFooters());
        assertEquals("testdoc test phrase", ss.getNotesHeadersFooters().getFooterText());
+       ppe.close();
 
        ppe = new PowerPointExtractor(slTests.openResourceAsStream("45537_Footer.ppt"));
 
@@ -309,7 +319,8 @@ public final class TestExtractor {
       String masterRandomText = "This text comes from the Master Slide";
       String masterFooterText = "Footer from the master slide";
       HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithMaster.ppt"));
-      
+      ppe.close();
+
       ppe = new PowerPointExtractor(hslf);
       
       String text = ppe.getText();
@@ -320,6 +331,7 @@ public final class TestExtractor {
 
    @Test
    public void testMasterText() throws Exception {
+       ppe.close();
        ppe = new PowerPointExtractor(slTests.openResourceAsStream("master_text.ppt"));
        
        // Initially not there
@@ -338,7 +350,8 @@ public final class TestExtractor {
        // Will always show up
        String masterText = "Footer from the master slide";
        HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("WithMaster.ppt"));
-       
+       ppe.close();
+
        ppe = new PowerPointExtractor(hslf);
        
        text = ppe.getText();
@@ -352,6 +365,7 @@ public final class TestExtractor {
     @Test
     public void testChineseText() throws Exception {
        HSLFSlideShowImpl hslf = new HSLFSlideShowImpl(slTests.openResourceAsStream("54880_chinese.ppt"));
+       ppe.close();
        ppe = new PowerPointExtractor(hslf);
        
        String text = ppe.getText();
@@ -409,6 +423,7 @@ public final class TestExtractor {
 //                         "Row 4, Cell 1\tRow 4, Cell 2\tRow 4, Cell 3\tRow 4, Cell 4\n"+

 //                         "Row 5, Cell 1\tRow 5, Cell 2\tRow 5, Cell 3\tRow 5, Cell 4\n";
 //        assertTrue(text.contains(target));
+        ppe.close();
 
         ppe = new PowerPointExtractor(slTests.openResourceAsStream("54722.ppt"));
         String text = ppe.getText();

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/record/TestCurrentUserAtom.java
Tue Dec 22 22:35:59 2015
@@ -69,12 +69,14 @@ public final class TestCurrentUserAtom {
 	public void readEnc() throws Exception {
 		POIFSFileSystem fs = new POIFSFileSystem(_slTests.getFile(encFile));
 
-		new CurrentUserAtom(fs.getRoot());
-		assertTrue(true); // not yet failed
-		
-		new HSLFSlideShowImpl(fs);
-		
-		fs.close();
+		try {
+    		new CurrentUserAtom(fs.getRoot());
+    		assertTrue(true); // not yet failed
+    		
+    		new HSLFSlideShowImpl(fs).close();
+		} finally {
+		    fs.close();
+		}
 	}
 
 	@Test

Modified: poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ddf/TestEscherDump.java Tue Dec 22 22:35:59 2015
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTru
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
@@ -31,7 +32,6 @@ import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LocaleUtil;
 import org.junit.Test;
 
-@SuppressWarnings("resource")
 public class TestEscherDump {
     @Test
     public void testSimple() throws Exception {
@@ -56,10 +56,15 @@ public class TestEscherDump {
         //new EscherDump().dumpOld(data.length, new ByteArrayInputStream(data), System.out);
         
         data = new byte[2586114];
-        int bytes = IOUtils.readFully(HSSFTestDataSamples.openSampleFileStream("44593.xls"),
data);
-        assertTrue(bytes != -1);
-        //new EscherDump().dump(bytes, data, System.out);
-        //new EscherDump().dumpOld(bytes, new ByteArrayInputStream(data), System.out);
+        InputStream stream = HSSFTestDataSamples.openSampleFileStream("44593.xls");
+        try {
+            int bytes = IOUtils.readFully(stream, data);
+            assertTrue(bytes != -1);
+            //new EscherDump().dump(bytes, data, System.out);
+            //new EscherDump().dumpOld(bytes, new ByteArrayInputStream(data), System.out);
+        } finally {
+            stream.close();
+        }
     }
     
     /**

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/dev/TestBiffViewer.java Tue Dec 22 22:35:59
2015
@@ -48,15 +48,18 @@ public class TestBiffViewer extends Base
 	@Override
 	void runOneFile(File fileIn) throws IOException {
 	    NPOIFSFileSystem fs  = new NPOIFSFileSystem(fileIn, true);
-		InputStream is = BiffViewer.getPOIFSInputStream(fs);
-		try {
-			// use a NullOutputStream to not write the bytes anywhere for best runtime
-		    PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
-			BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
-		} finally {
-			is.close();
-			fs.close();
-		}
+	    try {
+    		InputStream is = BiffViewer.getPOIFSInputStream(fs);
+    		try {
+    			// use a NullOutputStream to not write the bytes anywhere for best runtime
+    		    PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM,
LocaleUtil.CHARSET_1252));
+    			BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
+    		} finally {
+    			is.close();
+    		}
+	    } finally {
+    		fs.close();
+	    }
 	}
 	
 //	@Test

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java Tue Dec
22 22:35:59 2015
@@ -45,13 +45,14 @@ public final class TestExcelExtractor {
         Biff8EncryptionKey.setCurrentUserPassword(null);
     }
 
-	@SuppressWarnings("resource")
     private static ExcelExtractor createExtractor(String sampleFileName) throws IOException
{
 		File file = HSSFTestDataSamples.getSampleFile(sampleFileName);
-        return new ExcelExtractor(new POIFSFileSystem(file));
+        POIFSFileSystem fs = new POIFSFileSystem(file);
+        ExcelExtractor extractor = new ExcelExtractor(fs);
+        extractor.setFilesystem(fs);
+        return extractor;
 	}
 
-
 	@Test
 	public void testSimple() throws IOException {
 		ExcelExtractor extractor = createExtractor("Simple.xls");

Modified: poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java Tue
Dec 22 22:35:59 2015
@@ -36,27 +36,38 @@ public class BaseTestSlideShowFactory {
         // from file
         ss = SlideShowFactory.create(fromFile(file));
         assertNotNull(ss);
+        ss.close();
+
         // from stream
         ss = SlideShowFactory.create(fromStream(file));
         assertNotNull(ss);
+        ss.close();
+
         // from NPOIFS
         if (!file.contains("pptx")) {
             NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(file));
             ss = SlideShowFactory.create(npoifs);
             assertNotNull(ss);
             npoifs.close();
+            ss.close();
         }
+
         // from protected file
         ss = SlideShowFactory.create(fromFile(protectedFile), password);
         assertNotNull(ss);
+        ss.close();
+
         // from protected stream
         ss = SlideShowFactory.create(fromStream(protectedFile), password);
         assertNotNull(ss);
+        ss.close();
+
         // from protected NPOIFS
         NPOIFSFileSystem npoifs = new NPOIFSFileSystem(fromFile(protectedFile));
         ss = SlideShowFactory.create(npoifs, password);
         assertNotNull(ss);
         npoifs.close();
+        ss.close();
     }
     
     private static File fromFile(String file) {

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1721468&r1=1721467&r2=1721468&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Tue Dec 22 22:35:59
2015
@@ -25,12 +25,15 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.List;
 
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.ITestDataProvider;
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.util.LocaleUtil;
+import org.junit.After;
 import org.junit.Test;
 
 import junit.framework.AssertionFailedError;
@@ -44,6 +47,16 @@ public abstract class BaseTestCell {
 
     protected final ITestDataProvider _testDataProvider;
 
+    private List<Workbook> workbooksToClose = new ArrayList<Workbook>(); 
+
+    @After
+    public void tearDown() throws IOException {
+        // free resources correctly
+        for(Workbook wb : workbooksToClose) {
+            wb.close();
+        }
+    }
+
     /**
      * @param testDataProvider an object that provides test data in HSSF / XSSF specific
way
      */
@@ -350,8 +363,11 @@ public abstract class BaseTestCell {
         wb.close();
 
     }
+
     private Cell createACell() {
-        return _testDataProvider.createWorkbook().createSheet("Sheet1").createRow(0).createCell(0);
+        Workbook wb = _testDataProvider.createWorkbook();
+        workbooksToClose.add(wb);
+        return wb.createSheet("Sheet1").createRow(0).createCell(0);
     }
     
     /**
@@ -953,5 +969,7 @@ public abstract class BaseTestCell {
 
         B1.setAsActiveCell();
         assertEquals(B1.getAddress(), sheet.getActiveCell());
+        
+        wb.close();
     }
 }



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


Mime
View raw message