From cfbd5f9d8af638aa830aa535feadb094109e6455 Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 15 Oct 2014 14:23:04 +0200 Subject: Rebuild API to support Java DataSource and Streams for in and output --- .../src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java | 2 +- .../java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'pdf-as-legacy/src/main/java/at/gv/egiz') diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java index bef3b01f..ac76a56b 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/PdfAsObject.java @@ -101,7 +101,7 @@ public class PdfAsObject implements PdfAs { request = (StatusRequestImpl) this.pdfas4.process(request); if(request.isReady()) { at.gv.egiz.pdfas.lib.api.sign.SignResult result = this.pdfas4.finishSign(request); - sdi.wrapper.syncNewToOld(); + sdi.wrapper.syncNewToOld(result); SignResultImpl oldresult = new SignResultImpl(sdi.wrapper.getSignParameters().getOutput(), sdi.getX509Certificate(), new at.gv.egiz.pdfas.wrapper.SignaturePositionImpl( result.getSignaturePosition())); diff --git a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java index 7043baaa..12395bde 100644 --- a/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java +++ b/pdf-as-legacy/src/main/java/at/gv/egiz/pdfas/wrapper/SignParameterWrapper.java @@ -26,14 +26,15 @@ package at.gv.egiz.pdfas.wrapper; import java.io.OutputStream; import java.util.Enumeration; +import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.pdfas.api.exceptions.ErrorCode; import at.gv.egiz.pdfas.api.exceptions.PdfAsException; import at.gv.egiz.pdfas.api.sign.SignParameters; -import at.gv.egiz.pdfas.lib.api.ByteArrayDataSink; import at.gv.egiz.pdfas.lib.api.sign.SignParameter; +import at.gv.egiz.pdfas.lib.api.sign.SignResult; import at.gv.egiz.pdfas.moa.MOAConnector; import at.gv.egiz.pdfas.sigs.pades.PAdESSigner; import at.gv.egiz.sl.util.BKUSLConnector; @@ -45,7 +46,6 @@ public class SignParameterWrapper { private SignParameter signParameter4; private SignParameters signParameters; - private ByteArrayDataSink output; public SignParameterWrapper(SignParameters signParameters, SignParameter signParameter4) { @@ -54,9 +54,7 @@ public class SignParameterWrapper { } public void syncOldToNew() throws PdfAsException { - output = new ByteArrayDataSink(); - this.signParameter4.setOutput(output); - + if (this.signParameters.getSignaturePositioning() != null) { // Create positioning string String posString = this.signParameters.getSignaturePositioning() @@ -106,11 +104,11 @@ public class SignParameterWrapper { } } - public void syncNewToOld() throws PdfAsException { + public void syncNewToOld(SignResult result) throws PdfAsException { try { OutputStream os = this.signParameters.getOutput() .createOutputStream("application/pdf"); - os.write(output.getData()); + IOUtils.copy(result.getOutputDocument(), os); os.close(); } catch (Exception e) { throw new PdfAsException(ErrorCode.SIGNATURE_COULDNT_BE_CREATED, -- cgit v1.2.3