From 85e574618b04a34d5e41444d17ce7e6d5a93cc5b Mon Sep 17 00:00:00 2001 From: netconomy Date: Thu, 6 Sep 2007 12:18:45 +0000 Subject: =?UTF-8?q?Streaming=20R=C3=BCckbau?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@210 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../egiz/pdfas/web/helper/SignServletHelper.java | 22 ++++++-- .../at/gv/egiz/pdfas/web/helper/TempDirHelper.java | 63 +++++++++++++++------- 2 files changed, 60 insertions(+), 25 deletions(-) (limited to 'src/main/java/at/gv/egiz/pdfas/web/helper') diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java index af1d0ae..9826500 100644 --- a/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java +++ b/src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java @@ -18,6 +18,8 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.pdfas.framework.SignatorFactory; import at.gv.egiz.pdfas.framework.signator.Signator; +import at.gv.egiz.pdfas.impl.output.ByteArrayDataSink; +import at.gv.egiz.pdfas.impl.output.FileBasedDataSink; import at.gv.egiz.pdfas.web.SignSessionInformation; import at.knowcenter.wag.egov.egiz.PdfASID; import at.knowcenter.wag.egov.egiz.exceptions.PresentableException; @@ -185,10 +187,21 @@ public class SignServletHelper else { // TODO @tzefferer: what is this code? - byte[] signed_pdf = new byte [(int)si.output.getFile().length()]; - FileInputStream fis = new FileInputStream(si.output.getFile()); - fis.read(signed_pdf); - fis.close(); + byte [] signed_pdf = null; + if (si.output instanceof FileBasedDataSink) + { + FileBasedDataSink fbds = (FileBasedDataSink)si.output; + signed_pdf = new byte [(int)fbds.getFile().length()]; + FileInputStream fis = new FileInputStream(fbds.getFile()); + fis.read(signed_pdf); + fis.close(); + } + else + { + ByteArrayDataSink bads = (ByteArrayDataSink)si.output; + signed_pdf = bads.getByteArray(); + } + PDFContainer entry = new PDFContainer(signed_pdf, si.exappinf.pdf_id); ProvidePDFServlet.signedDocuments.add(entry); @@ -205,7 +218,6 @@ public class SignServletHelper + "=" + pdf_id + "&" + FormFields.FIELD_FILE_LENGTH + "=" + signed_pdf.length; response.sendRedirect(query); - } } diff --git a/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java b/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java index 0745bcc..23c01fd 100644 --- a/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java +++ b/src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java @@ -21,12 +21,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.pdfas.framework.input.DataSource; +import at.gv.egiz.pdfas.framework.input.PdfDataSource; import at.gv.egiz.pdfas.framework.input.TextDataSource; import at.gv.egiz.pdfas.framework.output.DataSink; +import at.gv.egiz.pdfas.impl.input.ByteArrayPdfDataSourceImpl; import at.gv.egiz.pdfas.impl.input.FileBased; import at.gv.egiz.pdfas.impl.input.FileBasedPdfDataSourceImpl; import at.gv.egiz.pdfas.impl.input.FileBasedTextDataSourceImpl; import at.gv.egiz.pdfas.impl.input.TextDataSourceImpl; +import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper; +import at.gv.egiz.pdfas.impl.output.ByteArrayDataSink; import at.gv.egiz.pdfas.impl.output.FileBasedDataSink; import at.knowcenter.wag.egov.egiz.cfg.SettingsReader; import at.knowcenter.wag.egov.egiz.pdf.SignatureHolder; @@ -119,11 +123,16 @@ public class TempDirHelper return textLength >= 10000; } - public static FileBasedPdfDataSourceImpl placePdfIntoTempDir(InputStream pdfInput, String fileNameSuffix) throws IOException + public static PdfDataSource placePdfIntoTempDir(InputStream pdfInput, String fileNameSuffix) throws IOException { - File pdfFile = placeInputIntoTempDirFile(pdfInput, fileNameSuffix); - - FileBasedPdfDataSourceImpl pdfDataSource = new FileBasedPdfDataSourceImpl(pdfFile, (int) pdfFile.length()); + log.debug("PERF: placing pdf into memory cache"); + + byte [] pdfData = DataSourceHelper.convertInputStreamToByteArray(pdfInput); + PdfDataSource pdfDataSource = new ByteArrayPdfDataSourceImpl(pdfData); + +// File pdfFile = placeInputIntoTempDirFile(pdfInput, fileNameSuffix); +// +// FileBasedPdfDataSourceImpl pdfDataSource = new FileBasedPdfDataSourceImpl(pdfFile, (int) pdfFile.length()); return pdfDataSource; } @@ -177,35 +186,49 @@ public class TempDirHelper return tmpFile; } - public static FileBasedDataSink createTempDataSink(String fileNameSuffix) throws IOException + public static DataSink createTempDataSink(String fileNameSuffix) throws IOException { - String fileName = formatFileName(fileNameSuffix); - - File tmpFile = createTempFileInDir(fileName); + log.debug("PERF: placing pdf into memory cache"); - FileBasedDataSink fbds = new FileBasedDataSink(tmpFile); + DataSink ds = new ByteArrayDataSink(); + +// String fileName = formatFileName(fileNameSuffix); +// +// File tmpFile = createTempFileInDir(fileName); +// +// FileBasedDataSink ds = new FileBasedDataSink(tmpFile); - return fbds; + return ds; } - public static void writeDataSinkToHttpResponse(FileBasedDataSink fbds, HttpServletResponse response) throws IOException + public static void writeDataSinkToHttpResponse(DataSink ds, HttpServletResponse response) throws IOException { - response.setContentType(fbds.getMimeType()); - response.setCharacterEncoding(fbds.getCharacterEncoding()); + response.setContentType(ds.getMimeType()); + response.setCharacterEncoding(ds.getCharacterEncoding()); OutputStream os = response.getOutputStream(); - byte[] buffer = new byte[2048]; - FileInputStream fis = new FileInputStream(fbds.getFile()); - int n = -1; - while ((n = fis.read(buffer)) > 0) + if (ds instanceof FileBasedDataSink) { - os.write(buffer, 0, n); + FileBasedDataSink fbds = (FileBasedDataSink)ds; + byte[] buffer = new byte[2048]; + FileInputStream fis = new FileInputStream(fbds.getFile()); + int n = -1; + while ((n = fis.read(buffer)) > 0) + { + os.write(buffer, 0, n); + } + fis.close(); } - fis.close(); + else + { + ByteArrayDataSink bads = (ByteArrayDataSink)ds; + os.write(bads.getByteArray()); + } + os.close(); - } +} /** * Deletes the underlying file of the FileBased DataSource. -- cgit v1.2.3