pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1558705 - in /pdfbox/branches/1.8: ./ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ pdfbox/src/main/java/org/apache/pdfbox/util/ pdfbox/src/test/java/org/apache/pdfbox/
Date Thu, 16 Jan 2014 07:11:30 GMT
Author: lehmi
Date: Thu Jan 16 07:11:30 2014
New Revision: 1558705

URL: http://svn.apache.org/r1558705
Log:
PDFBOX-1808: release used resources

Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/XrefTrailerResolver.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
    pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestTextToPdf.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1553175,1553220,1557374

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/BaseParser.java Thu
Jan 16 07:11:30 2014
@@ -38,6 +38,7 @@ import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.exceptions.WrappedIOException;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.io.PushBackInputStream;
 import org.apache.pdfbox.io.RandomAccess;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
@@ -556,6 +557,10 @@ public abstract class BaseParser
                                                           PROP_PUSHBACK_SIZE, ioe );
                         }
                         // create new filtered stream
+                        if (out != null)
+                        {
+                        	IOUtils.closeQuietly(out);
+                        }
                         out = stream.createFilteredStream( streamLength );
                         // scan until we find endstream:
                         readUntilEndStream( out );
@@ -1705,4 +1710,16 @@ public abstract class BaseParser
         return buffer;
     }
 
+    /**
+     * Release all used resources.
+     */
+    public void clearResources()
+    {
+    	document = null;
+    	if (pdfSource != null)
+    	{
+    		IOUtils.closeQuietly(pdfSource);
+    		pdfSource = null;
+    	}
+    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFParser.java Thu
Jan 16 07:11:30 2014
@@ -442,7 +442,7 @@ public class PDFParser extends BaseParse
      */
     public PDDocument getPDDocument() throws IOException
     {
-        return new PDDocument( getDocument() );
+        return new PDDocument( getDocument(), this );
     }
 
     /**
@@ -981,4 +981,22 @@ public class PDFParser extends BaseParse
         }
         return false;
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void clearResources() {
+    	super.clearResources();
+    	if (conflictList != null)
+    	{
+    		conflictList.clear();
+    		conflictList = null;
+    	}
+    	if (xrefTrailerResolver != null)
+    	{
+    		xrefTrailerResolver.clearResources();
+    		xrefTrailerResolver = null;
+    	}
+    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
Thu Jan 16 07:11:30 2014
@@ -489,4 +489,16 @@ public class PDFStreamParser extends Bas
         return isSpaceOrReturn( pdfSource.peek() );
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void clearResources() {
+    	super.clearResources();
+    	if (streamObjects != null)
+    	{
+    		streamObjects.clear();
+    		streamObjects = null;
+    	}
+    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/XrefTrailerResolver.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/XrefTrailerResolver.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/XrefTrailerResolver.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/XrefTrailerResolver.java
Thu Jan 16 07:11:30 2014
@@ -65,11 +65,27 @@ public class XrefTrailerResolver
         private final Map<COSObjectKey, Long> xrefTable = new HashMap<COSObjectKey,
Long>();
         
         /**
-         *  Default cosntructor.
+         *  Default constructor.
          */
         private XrefTrailerObj()
         {
         }
+        
+        /**
+         * Release all used resources.
+         */
+        public void clearResources()
+        {
+        	if (trailer != null)
+        	{
+        		trailer.clear();
+        		trailer = null;
+        	}
+        	if (xrefTable != null)
+        	{
+        		xrefTable.clear();
+        	}
+        }
     }
 
     private final Map<Long, XrefTrailerObj> bytePosToXrefMap = new HashMap<Long,
XrefTrailerObj>();
@@ -283,4 +299,26 @@ public class XrefTrailerResolver
         }
         return refObjNrs;
     }
+    
+    /**
+     * Release all used resources.
+     */
+    public void clearResources()
+    {
+    	if (curXrefTrailerObj != null)
+    	{
+    		curXrefTrailerObj.clearResources();
+    		curXrefTrailerObj = null;
+    	}
+    	if (resolvedXrefTrailer != null)
+    	{
+    		resolvedXrefTrailer.clearResources();
+    		resolvedXrefTrailer = null;
+    	}
+    	if (bytePosToXrefMap != null)
+    	{
+    		bytePosToXrefMap.clear();
+    	}
+    }
+
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Thu
Jan 16 07:11:30 2014
@@ -48,6 +48,7 @@ import org.apache.pdfbox.exceptions.Cryp
 import org.apache.pdfbox.exceptions.InvalidPasswordException;
 import org.apache.pdfbox.exceptions.SignatureException;
 import org.apache.pdfbox.io.RandomAccess;
+import org.apache.pdfbox.pdfparser.BaseParser;
 import org.apache.pdfbox.pdfparser.NonSequentialPDFParser;
 import org.apache.pdfbox.pdfparser.PDFParser;
 import org.apache.pdfbox.pdfwriter.COSWriter;
@@ -124,7 +125,8 @@ public class PDDocument implements Pagea
      */
     private Long documentId;
 
-    
+    private BaseParser parser; 
+
     /**
      * Constructor, creates a new PDF Document with no pages.  You need to add
      * at least one page for the document to be valid.
@@ -694,7 +696,19 @@ public class PDDocument implements Pagea
      */
     public PDDocument( COSDocument doc )
     {
+        this(doc, null);
+    }
+
+    /**
+     * Constructor that uses an existing document. The COSDocument that is passed in must
be valid.
+     * 
+     * @param doc The COSDocument that this document wraps.
+     * @param usedParser the parser which is used to read the pdf
+     */
+    public PDDocument(COSDocument doc, BaseParser usedParser)
+    {
         document = doc;
+        parser = usedParser;
     }
 
     /**
@@ -1525,7 +1539,25 @@ public class PDDocument implements Pagea
      */
     public void close() throws IOException
     {
-        document.close();
+    	documentCatalog = null;
+    	documentInformation = null;
+    	encParameters = null;
+    	if (pageMap != null)
+    	{
+    		pageMap.clear();
+    		pageMap = null;
+    	}
+    	securityHandler = null;
+    	if (document != null)
+    	{
+	        document.close();
+	        document = null;
+    	}
+        if (parser != null)
+        {
+        	parser.clearResources();
+        	parser = null;
+        }
     }
 
 

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/util/PDFTextStripper.java Thu
Jan 16 07:11:30 2014
@@ -281,6 +281,17 @@ public class PDFTextStripper extends PDF
     {
         super.resetEngine();
         currentPageNo = 0;
+        document = null;
+        if (charactersByArticle != null)
+        {
+        	charactersByArticle.clear();
+        }
+        if (characterListMapping != null)
+        {
+        	characterListMapping.clear();
+        }
+        startBookmark = null;
+        endBookmark = null;
     }
     
     /**
@@ -1803,7 +1814,7 @@ public class PDFTextStripper extends PDF
      */
     protected void setListItemPatterns(List<Pattern> patterns)
     {
-            listOfPatterns = patterns;
+    	listOfPatterns = patterns;
     }
 
     /**

Modified: pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestTextToPdf.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestTextToPdf.java?rev=1558705&r1=1558704&r2=1558705&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestTextToPdf.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/test/java/org/apache/pdfbox/TestTextToPdf.java Thu Jan
16 07:11:30 2014
@@ -54,7 +54,6 @@ public class TestTextToPdf extends TestC
         StringReader reader = new StringReader("");
         PDDocument pdfDoc = pdfCreator.createPDFFromText(reader);
         reader.close();
-        pdfDoc.close();
 
         // In order for the PDF document to be openable by Adobe Reader, it needs
         // to have some pages in it. So we'll check that.
@@ -62,6 +61,7 @@ public class TestTextToPdf extends TestC
         List allPages = docCatalog.getAllPages();
         assertNotNull("All Pages was unexpectedly null.", allPages);
         assertEquals("Wrong number of pages.", 1, allPages.size());
+        pdfDoc.close();
     }
 
     /**



Mime
View raw message