poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1749214 - in /poi/trunk/src: java/org/apache/poi/ java/org/apache/poi/hpsf/extractor/ java/org/apache/poi/hssf/extractor/ scratchpad/testcases/org/apache/poi/hsmf/ scratchpad/testcases/org/apache/poi/hwpf/usermodel/ testcases/org/apache/po...
Date Sun, 19 Jun 2016 22:13:41 GMT
Author: nick
Date: Sun Jun 19 22:13:41 2016
New Revision: 1749214

URL: http://svn.apache.org/viewvc?rev=1749214&view=rev
Log:
#59724 Take advantage of all POIDocument classes being Closeable to tidy the OLE2 text extractor
closing

Modified:
    poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java
    poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
    poi/trunk/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
    poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java

Modified: poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java?rev=1749214&r1=1749213&r2=1749214&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/POIOLE2TextExtractor.java Sun Jun 19 22:13:41 2016
@@ -44,6 +44,10 @@ public abstract class POIOLE2TextExtract
 	 */
 	public POIOLE2TextExtractor(POIDocument document) {
 		this.document = document;
+		
+		// Ensure any underlying resources, such as open files,
+		//  will get cleaned up if the user calls #close()
+		setFilesystem(document);
 	}
 
 	/**

Modified: poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1749214&r1=1749213&r2=1749214&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Sun Jun
19 22:13:41 2016
@@ -17,7 +17,6 @@
 
 package org.apache.poi.hpsf.extractor;
 
-import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
 import java.util.Iterator;
@@ -41,8 +40,6 @@ import org.apache.poi.poifs.filesystem.P
  *  textual form.
  */
 public class HPSFPropertiesExtractor extends POIOLE2TextExtractor {
-    private Closeable toClose;
-
     public HPSFPropertiesExtractor(POIOLE2TextExtractor mainExtractor) {
         super(mainExtractor);
     }
@@ -54,7 +51,6 @@ public class HPSFPropertiesExtractor ext
     }
     public HPSFPropertiesExtractor(NPOIFSFileSystem fs) {
         super(new HPSFPropertiesOnlyDocument(fs));
-        this.toClose = fs;
     }
 
     public String getDocumentSummaryInformationText() {
@@ -132,19 +128,6 @@ public class HPSFPropertiesExtractor ext
         throw new IllegalStateException("You already have the Metadata Text Extractor, not
recursing!");
     }
     
-    
-    
-    public void close() throws IOException {
-        super.close();
-        
-        if(toClose != null) {
-            toClose.close();
-            toClose = null;
-        }
-    }
-
-
-
     private static abstract class HelperPropertySet extends SpecialPropertySet {
         public HelperPropertySet() {
             super(null);

Modified: poi/trunk/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java?rev=1749214&r1=1749213&r2=1749214&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/extractor/EventBasedExcelExtractor.java Sun Jun
19 22:13:41 2016
@@ -73,6 +73,7 @@ public class EventBasedExcelExtractor ex
 
    public EventBasedExcelExtractor(POIFSFileSystem fs) {
       this(fs.getRoot());
+      super.setFilesystem(fs);
    }
 
    /**

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java?rev=1749214&r1=1749213&r2=1749214&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hsmf/TestFixedSizedProperties.java Sun
Jun 19 22:13:41 2016
@@ -144,6 +144,8 @@ public final class TestFixedSizedPropert
    // @Ignore("TODO Work out why the Fri 22nd vs Monday 25th problem is occurring and fix")
    public void testReadMessageDateSucceedsWithOutlookTextExtractor() throws Exception {
       OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageSucceeds);
+      ext.setFilesystem(null); // Don't close re-used test resources here
+      
       String text = ext.getText();
       assertContains(text, "Date: Fri, 22 Jun 2012 18:32:54 +0000\n");
       ext.close();
@@ -156,6 +158,8 @@ public final class TestFixedSizedPropert
    // @Ignore("TODO Work out why the Thu 21st vs Monday 25th problem is occurring and fix")
    public void testReadMessageDateFailsWithOutlookTextExtractor() throws Exception {
       OutlookTextExtactor ext = new OutlookTextExtactor(mapiMessageFails);
+      ext.setFilesystem(null); // Don't close re-used test resources here
+      
       String text = ext.getText();
       assertContains(text, "Date: Thu, 21 Jun 2012 14:14:04 +0000\n");
       ext.close();

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java?rev=1749214&r1=1749213&r2=1749214&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java Sun Jun
19 22:13:41 2016
@@ -49,10 +49,8 @@ import org.apache.poi.util.POILogger;
 import junit.framework.TestCase;
 
 /**
- * Test different problems reported in Apache Bugzilla
- * 
- * @author Nick Burch (nick at torchbox dot com)
- * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
+ * Test different problems reported in the Apache Bugzilla
+ *  against HWPF
  */
 public class TestBugs extends TestCase
 {
@@ -245,6 +243,7 @@ public class TestBugs extends TestCase
      */
     public void test45473() throws IOException
     {
+        // Fetch the current text
         HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug45473.doc");
         WordExtractor wordExtractor = new WordExtractor(doc1);
         final String text1;
@@ -254,6 +253,8 @@ public class TestBugs extends TestCase
             wordExtractor.close();
         }
 
+        // Re-load, then re-save and re-check
+        doc1 = HWPFTestDataSamples.openSampleFile("Bug45473.doc");
         HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
         WordExtractor wordExtractor2 = new WordExtractor(doc2);
         final String text2;
@@ -313,6 +314,7 @@ public class TestBugs extends TestCase
     @SuppressWarnings("deprecation")
     public void test47286() throws IOException
     {
+        // Fetch the current text
         HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug47286.doc");
         WordExtractor wordExtractor = new WordExtractor(doc1);
         final String text1;
@@ -322,6 +324,8 @@ public class TestBugs extends TestCase
             wordExtractor.close();
         }
 
+        // Re-load, then re-save and re-check
+        doc1 = HWPFTestDataSamples.openSampleFile("Bug47286.doc");
         HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
         WordExtractor wordExtractor2 = new WordExtractor(doc2);
         final String text2;

Modified: poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java?rev=1749214&r1=1749213&r2=1749214&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hpsf/extractor/TestHPSFPropertiesExtractor.java
Sun Jun 19 22:13:41 2016
@@ -115,6 +115,7 @@ public final class TestHPSFPropertiesExt
 
 		final String fsText;
 		HPSFPropertiesExtractor fsExt = new HPSFPropertiesExtractor(fs);
+		fsExt.setFilesystem(null); // Don't close re-used test resources!
 		try {
 		    fsText = fsExt.getText();
 		} finally {
@@ -123,6 +124,7 @@ public final class TestHPSFPropertiesExt
         
         final String hwText; 
 		HPSFPropertiesExtractor hwExt = new HPSFPropertiesExtractor(wb);
+		hwExt.setFilesystem(null); // Don't close re-used test resources!
 		try {
 		    hwText = hwExt.getText();
 		} finally {
@@ -131,6 +133,7 @@ public final class TestHPSFPropertiesExt
 		
         final String eeText;
         HPSFPropertiesExtractor eeExt = new HPSFPropertiesExtractor(excelExt);
+        eeExt.setFilesystem(null); // Don't close re-used test resources!
         try {
             eeText = eeExt.getText();
         } finally {
@@ -142,6 +145,9 @@ public final class TestHPSFPropertiesExt
 
 		assertTrue(fsText.indexOf("AUTHOR = marshall") > -1);
 		assertTrue(fsText.indexOf("TITLE = Titel: \u00c4h") > -1);
+		
+		// Finally tidy
+		wb.close();
 	}
 
 	public void test42726() throws IOException {



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


Mime
View raw message