From 016969d392fa4885b19cc041c3427b0d39f256c8 Mon Sep 17 00:00:00 2001 From: Viktor Ivanov Date: Wed, 1 Feb 2017 11:58:18 +0200 Subject: [PATCH] Add constructors for PreflightParser with scratch parameter --- .../preflight/parser/PreflightParser.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java b/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java index a68de023e40..bdb7a73c0c4 100644 --- a/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java +++ b/preflight/src/main/java/org/apache/pdfbox/preflight/parser/PreflightParser.java @@ -46,6 +46,7 @@ import org.apache.pdfbox.cos.COSString; import org.apache.pdfbox.io.IOUtils; import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; +import org.apache.pdfbox.io.ScratchFile; import org.apache.pdfbox.pdfparser.PDFObjectStreamParser; import org.apache.pdfbox.pdfparser.PDFParser; import org.apache.pdfbox.pdfparser.XrefTrailerResolver.XRefType; @@ -110,6 +111,21 @@ public PreflightParser(File file) throws IOException this.dataSource = new FileDataSource(file); } + /** + * Constructor. + * + * @param file + * @param scratch + * @throws IOException if there is a reading error. + */ + public PreflightParser(File file, ScratchFile scratch) throws IOException + { + // TODO move file handling outside of the parser + super(new RandomAccessBufferedFileInputStream(file), scratch); + this.setLenient(false); + this.dataSource = new FileDataSource(file); + } + /** * Constructor. * @@ -122,6 +138,19 @@ public PreflightParser(String filename) throws IOException this(new File(filename)); } + /** + * Constructor. + * + * @param filename + * @param scratch + * @throws IOException if there is a reading error. + */ + public PreflightParser(String filename, ScratchFile scratch) throws IOException + { + // TODO move file handling outside of the parser + this(new File(filename), scratch); + } + /** * Constructor. This one is slower than the file and the filename constructors, because * a temporary file will be created. @@ -137,6 +166,22 @@ public PreflightParser(DataSource dataSource) throws IOException this.dataSource = dataSource; } + /** + * Constructor. This one is slower than the file and the filename constructors, because + * a temporary file will be created. + * + * @param dataSource the datasource + * @param scratch + * @throws IOException if there is a reading error. + */ + public PreflightParser(DataSource dataSource, ScratchFile scratch) throws IOException + { + // TODO move file handling outside of the parser + super(new RandomAccessBufferedFileInputStream(dataSource.getInputStream()), scratch); + this.setLenient(false); + this.dataSource = dataSource; + } + /** * Create an instance of ValidationResult with a ValidationError(UNKNOWN_ERROR) *