From 9494d9d2bf6dad8f5cb4237164546baac8c56c9d Mon Sep 17 00:00:00 2001 From: Yannik Hampe Date: Tue, 23 May 2017 13:43:06 +0200 Subject: [PATCH] Do not catch IOExceptions, so that users of the libraries can handle the exceptions --- .../ZUGFeRD/ZUGFeRDExporter.java | 66 ++++--------------- 1 file changed, 11 insertions(+), 55 deletions(-) diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java index c5020294..737c7f76 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java @@ -355,7 +355,7 @@ public class ZUGFeRDExporter implements Closeable { ignoreA1Errors = true; } - private boolean getA1ParserValidationResult(PreflightParser parser) { + private boolean getA1ParserValidationResult(PreflightParser parser) throws IOException { ValidationResult result = null; try { @@ -387,27 +387,14 @@ public class ZUGFeRDExporter implements Closeable { * instance of ValidationResult */ return false; - } catch (IOException e) { - return false; } - // display validation result return result.isValid(); } - public boolean isValidA1(String filename) { - FileDataSource fd = new FileDataSource(filename); - PreflightParser parser; - try { - parser = new PreflightParser(fd); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } - - return getA1ParserValidationResult(parser); + public boolean isValidA1(String filename) throws IOException { + return getA1ParserValidationResult(new PreflightParser(new FileDataSource(filename))); } /*** @@ -415,43 +402,16 @@ public class ZUGFeRDExporter implements Closeable { * @param file * @return boolean */ - public boolean isValidA1(InputStream file) { - - ByteArrayDataSource fd; - try { - fd = new ByteArrayDataSource(file); - PreflightParser parser = new PreflightParser(fd); - return getA1ParserValidationResult(parser); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return false; - } - } - - public void loadPDFA3(String filename) { - - try { - - doc = PDDocument.load(new File(filename)); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - + public boolean isValidA1(InputStream file) throws IOException { + return getA1ParserValidationResult(new PreflightParser(new ByteArrayDataSource(file))); } - public void loadPDFA3(InputStream file) { + public void loadPDFA3(String filename) throws IOException { + doc = PDDocument.load(new File(filename)); + } - try { + public void loadPDFA3(InputStream file) throws IOException { doc = PDDocument.load(file); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } /** @@ -1450,12 +1410,8 @@ public class ZUGFeRDExporter implements Closeable { "text/xml", zugferdData); } - public void export(String ZUGFeRDfilename) { - try { - doc.save(ZUGFeRDfilename); - } catch (IOException ex) { - ex.printStackTrace(); - } + public void export(String ZUGFeRDfilename) throws IOException { + doc.save(ZUGFeRDfilename); } /**