aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/web/helper
diff options
context:
space:
mode:
authornetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-09-06 12:18:45 +0000
committernetconomy <netconomy@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-09-06 12:18:45 +0000
commit85e574618b04a34d5e41444d17ce7e6d5a93cc5b (patch)
tree1720e8a11493b8175a927e7462687f8ec6848609 /src/main/java/at/gv/egiz/pdfas/web/helper
parent148948fa82b26a78b5c2b7d0a79777474b64e581 (diff)
downloadpdf-as-3-85e574618b04a34d5e41444d17ce7e6d5a93cc5b.tar.gz
pdf-as-3-85e574618b04a34d5e41444d17ce7e6d5a93cc5b.tar.bz2
pdf-as-3-85e574618b04a34d5e41444d17ce7e6d5a93cc5b.zip
Streaming Rückbau
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@210 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/web/helper')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/helper/SignServletHelper.java22
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/helper/TempDirHelper.java63
2 files changed, 60 insertions, 25 deletions
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.