You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2013/12/20 09:35:21 UTC
svn commit: r1552535 - in /pdfbox/branches/1.8: ./
pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
Author: lehmi
Date: Fri Dec 20 08:35:20 2013
New Revision: 1552535
URL: http://svn.apache.org/r1552535
Log:
PDFBOX-1815: close streams to release resources as proposed by Tilman Hausherr
Modified:
pdfbox/branches/1.8/ (props changed)
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
Merged /pdfbox/trunk:r1552533
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java?rev=1552535&r1=1552534&r2=1552535&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java Fri Dec 20 08:35:20 2013
@@ -22,16 +22,13 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
-
import java.util.List;
import org.apache.pdfbox.filter.Filter;
import org.apache.pdfbox.filter.FilterManager;
-
import org.apache.pdfbox.pdfparser.PDFStreamParser;
-
import org.apache.pdfbox.exceptions.COSVisitorException;
-
+import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccess;
import org.apache.pdfbox.io.RandomAccessFileInputStream;
import org.apache.pdfbox.io.RandomAccessFileOutputStream;
@@ -40,7 +37,7 @@ import org.apache.pdfbox.io.RandomAccess
* This class represents a stream object in a PDF document.
*
* @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.41 $
+ *
*/
public class COSStream extends COSDictionary
{
@@ -263,7 +260,6 @@ public class COSStream extends COSDictio
{
FilterManager manager = getFilterManager();
Filter filter = manager.getFilter( filterName );
- InputStream input;
boolean done = false;
IOException exception = null;
@@ -287,6 +283,7 @@ public class COSStream extends COSDictio
//try again with one less byte.
for( int tryCount=0; !done && tryCount<5; tryCount++ )
{
+ InputStream input = null;
try
{
input = new BufferedInputStream(
@@ -300,6 +297,10 @@ public class COSStream extends COSDictio
length--;
exception = io;
}
+ finally
+ {
+ IOUtils.closeQuietly(input);
+ }
}
if( !done )
{
@@ -309,6 +310,7 @@ public class COSStream extends COSDictio
length = writtenLength;
for( int tryCount=0; !done && tryCount<5; tryCount++ )
{
+ InputStream input = null;
try
{
input = new BufferedInputStream(
@@ -322,6 +324,10 @@ public class COSStream extends COSDictio
length--;
exception = io;
}
+ finally
+ {
+ IOUtils.closeQuietly(input);
+ }
}
}
}
@@ -373,13 +379,13 @@ public class COSStream extends COSDictio
{
FilterManager manager = getFilterManager();
Filter filter = manager.getFilter( filterName );
- InputStream input;
- input = new BufferedInputStream(
+ InputStream input = new BufferedInputStream(
new RandomAccessFileInputStream( file, filteredStream.getPosition(),
filteredStream.getLength() ), BUFFER_SIZE );
filteredStream = new RandomAccessFileOutputStream( file );
filter.encode( input, filteredStream, this, filterIndex );
+ IOUtils.closeQuietly(input);
}
/**