Permalink
Browse files

Improve pdf text extraction resource handling.

For sort pdf <= 3 pages use already extracted content,
only for long pdf > 3 pages reassign content and close internal writer (to direct free buffers)
  • Loading branch information...
reger24 committed Mar 9, 2017
1 parent 52c9d0c commit de1c1c16db6f98fdf9f14860934f99938bc7b962
Showing with 4 additions and 3 deletions.
  1. +4 −3 source/net/yacy/document/parser/pdfParser.java
@@ -63,6 +63,7 @@
import net.yacy.kelondro.io.CharBuffer;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.MemoryControl;
import org.apache.pdfbox.pdmodel.PDPageTree;
public class pdfParser extends AbstractParser implements Parser {
@@ -219,9 +220,10 @@ public void run() {
t.start();
t.join(3000); // pdfbox likes to forget to terminate ... (quite often)
if (t.isAlive()) t.interrupt();
contentBytes = writer.getBytes(); // get final text before closing writer
writer.close(); // free writer resources
}
contentBytes = writer.getBytes(); // get final text before closing writer
Collection<AnchorURL> pdflinksCombined = new HashSet<AnchorURL>();
for (Collection<AnchorURL> pdflinksx: pdflinks) if (pdflinksx != null) pdflinksCombined.addAll(pdflinksx);
result = new Document[]{new Document(
@@ -245,7 +247,6 @@ public void run() {
docDate)};
}
} catch (final Throwable e) {
//close the writer (in finally)
//throw new Parser.Failure(e.getMessage(), location);
} finally {
try {pdfDoc.close();} catch (final Throwable e) {}

0 comments on commit de1c1c1

Please sign in to comment.