aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/commandline/Main.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/commandline/Main.java23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
index c4895c0..2e0e674 100644
--- a/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
+++ b/src/main/java/at/gv/egiz/pdfas/commandline/Main.java
@@ -519,9 +519,10 @@ public abstract class Main
}
DataSink dataSink = null;
+ File outputFile = null;
try
{
- File outputFile = new File(output);
+ outputFile = new File(output);
dataSink = new FileBasedDataSink(outputFile);
}
@@ -530,7 +531,25 @@ public abstract class Main
throw new PDFDocumentException(ErrorCode.CANNOT_WRITE_PDF, e);
}
- processSign(dataSource, connector, signature_mode, signature_type, pos_string, dataSink);
+ try {
+ processSign(dataSource, connector, signature_mode, signature_type, pos_string, dataSink);
+ } catch (Exception e) {
+ // Exception caught in order to delete file based datasink
+ if (outputFile != null && outputFile.exists())
+ {
+ logger_.debug("Deleting output file on error.");
+ boolean deleted = outputFile.delete();
+ if (!deleted)
+ {
+ logger_.error("Couldn't delete output file " + output);
+ }
+ }
+ if (e instanceof PresentableException) {
+ throw (PresentableException)e;
+ } else {
+ throw new PresentableException(ErrorCode.UNKNOWN_ERROR, e);
+ }
+ }
// for performance measurement
if (logger_.isInfoEnabled())