aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-cli/src
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-10-15 14:23:04 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-10-15 14:23:04 +0200
commitcfbd5f9d8af638aa830aa535feadb094109e6455 (patch)
tree5d65bb93b64314f7e3f3455002b4c909242e5bc5 /pdf-as-cli/src
parent0e31e524b419cd898139d1b8afa92cb794a3f821 (diff)
downloadpdf-as-4-cfbd5f9d8af638aa830aa535feadb094109e6455.tar.gz
pdf-as-4-cfbd5f9d8af638aa830aa535feadb094109e6455.tar.bz2
pdf-as-4-cfbd5f9d8af638aa830aa535feadb094109e6455.zip
Rebuild API to support Java DataSource and Streams for in and output
Diffstat (limited to 'pdf-as-cli/src')
-rw-r--r--pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java14
-rw-r--r--pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturProfileTest.java12
2 files changed, 11 insertions, 15 deletions
diff --git a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java
index 13bf87d3..222fd33a 100644
--- a/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java
+++ b/pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java
@@ -30,6 +30,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.UUID;
+import javax.activation.DataSource;
+
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
@@ -37,16 +39,16 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.apache.commons.io.IOUtils;
import at.gv.egiz.pdfas.common.utils.StreamUtils;
-import at.gv.egiz.pdfas.lib.api.ByteArrayDataSink;
import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource;
import at.gv.egiz.pdfas.lib.api.Configuration;
-import at.gv.egiz.pdfas.lib.api.DataSource;
import at.gv.egiz.pdfas.lib.api.PdfAs;
import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner;
import at.gv.egiz.pdfas.lib.api.sign.SignParameter;
+import at.gv.egiz.pdfas.lib.api.sign.SignResult;
import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter;
import at.gv.egiz.pdfas.lib.api.verify.VerifyResult;
import at.gv.egiz.pdfas.lib.api.verify.VerifyParameter.SignatureVerificationLevel;
@@ -322,8 +324,6 @@ public class Main {
StreamUtils.inputStreamToByteArray(new FileInputStream(
inputFile)));
- ByteArrayDataSink dataSink = new ByteArrayDataSink();
-
PdfAs pdfAs = null;
pdfAs = PdfAsFactory.createPdfAs(new File(configurationFile));
@@ -404,17 +404,17 @@ public class Main {
slConnector = new PAdESSigner(new BKUSLConnector(configuration));
}
- signParameter.setOutput(dataSink);
signParameter.setPlainSigner(slConnector);
signParameter.setDataSource(dataSource);
signParameter.setSignaturePosition(positionString);
signParameter.setSignatureProfileId(profilID);
System.out.println("Starting signature for " + pdfFile);
System.out.println("Selected signature Profile " + profilID);
- /*SignResult result = */pdfAs.sign(signParameter);
+ SignResult result = pdfAs.sign(signParameter);
FileOutputStream fos = new FileOutputStream(outputPdfFile, false);
- fos.write(dataSink.getData());
+ IOUtils.copy(result.getOutputDocument(), fos);
+
fos.close();
System.out.println("Signed document " + outputFile);
}
diff --git a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturProfileTest.java b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturProfileTest.java
index e14b8ca0..6b1eeaa9 100644
--- a/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturProfileTest.java
+++ b/pdf-as-cli/src/test/java/at/gv/egiz/pdfas/cli/test/SignaturProfileTest.java
@@ -30,13 +30,13 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import javax.activation.DataSource;
+
import org.apache.commons.io.IOUtils;
import at.gv.egiz.pdfas.common.settings.ISettings;
-import at.gv.egiz.pdfas.lib.api.ByteArrayDataSink;
import at.gv.egiz.pdfas.lib.api.ByteArrayDataSource;
import at.gv.egiz.pdfas.lib.api.Configuration;
-import at.gv.egiz.pdfas.lib.api.DataSource;
import at.gv.egiz.pdfas.lib.api.PdfAs;
import at.gv.egiz.pdfas.lib.api.PdfAsFactory;
import at.gv.egiz.pdfas.lib.api.sign.IPlainSigner;
@@ -98,19 +98,17 @@ public class SignaturProfileTest {
System.out.println("Testing " + profile);
DataSource source = new ByteArrayDataSource(input);
- ByteArrayDataSink sink = new ByteArrayDataSink();
SignParameter signParameter = PdfAsFactory.createSignParameter(
config, source);
signParameter.setPlainSigner(signer);
- signParameter.setOutput(sink);
signParameter.setSignatureProfileId(profile);
SignResult result = pdfas.sign(signParameter);
FileOutputStream fos = new FileOutputStream(targetFolder + profile + ".pdf");
- fos.write(sink.getData());
+ IOUtils.copy(result.getOutputDocument(), fos);
fos.close();
}
@@ -122,19 +120,17 @@ public class SignaturProfileTest {
System.out.println("Testing " + profile);
DataSource source = new ByteArrayDataSource(inputPDFA);
- ByteArrayDataSink sink = new ByteArrayDataSink();
SignParameter signParameter = PdfAsFactory.createSignParameter(
config, source);
signParameter.setPlainSigner(signer);
- signParameter.setOutput(sink);
signParameter.setSignatureProfileId(profile);
SignResult result = pdfas.sign(signParameter);
FileOutputStream fos = new FileOutputStream(targetFolder + "PDFA_" + profile + ".pdf");
- fos.write(sink.getData());
+ IOUtils.copy(result.getOutputDocument(), fos);
fos.close();
}
} catch (Throwable e) {