From 9ee3e690213a92434780059431f3e3b5fb8213e2 Mon Sep 17 00:00:00 2001 From: theli Date: Thu, 19 May 2005 11:16:02 +0000 Subject: [PATCH] *) Solving "Warning: You did not close the PDF Document" problem when an OutOfMemory Exception occured ... git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@140 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- .../de/anomic/plasma/parser/pdf/pdfParser.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source/de/anomic/plasma/parser/pdf/pdfParser.java b/source/de/anomic/plasma/parser/pdf/pdfParser.java index 40be8e264..553866a1d 100644 --- a/source/de/anomic/plasma/parser/pdf/pdfParser.java +++ b/source/de/anomic/plasma/parser/pdf/pdfParser.java @@ -89,6 +89,9 @@ public class pdfParser extends AbstractParser implements Parser { public plasmaParserDocument parse(URL location, String mimeType, InputStream source) throws ParserException { + + PDDocument theDocument = null; + OutputStreamWriter writer = null; try { // deactivating the logging for jMimeMagic @@ -101,7 +104,7 @@ public class pdfParser extends AbstractParser implements Parser { parser.parse(); PDFTextStripper stripper = new PDFTextStripper(); - PDDocument theDocument = parser.getPDDocument(); + theDocument = parser.getPDDocument(); PDDocumentInformation theDocInfo = theDocument.getDocumentInformation(); @@ -114,11 +117,11 @@ public class pdfParser extends AbstractParser implements Parser { } ByteArrayOutputStream out = new ByteArrayOutputStream(); - OutputStreamWriter writer = new OutputStreamWriter( out ); + writer = new OutputStreamWriter( out ); stripper.writeText(theDocument, writer ); - writer.close(); - theDocument.close(); + writer.close(); writer = null; + theDocument.close(); theDocument = null; byte[] contents = out.toByteArray(); @@ -145,7 +148,10 @@ public class pdfParser extends AbstractParser implements Parser { } catch (Exception e) { throw new ParserException("Unable to parse the pdf content. " + e.getMessage()); - } + } finally { + if (theDocument != null) try { theDocument.close(); } catch (Exception e) {} + if (writer != null) try { writer.close(); } catch (Exception e) {} + } } public void reset() {