aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz
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
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')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java15
-rw-r--r--src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java4
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/ByteArrayPdfDataSourceImpl.java23
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/CompoundPdfDataSourceImpl.java18
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/DelimitedPdfDataSource.java18
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedPdfDataSourceImpl.java30
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedTextDataSourceImpl.java18
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/TextDataSourceImpl.java16
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/input/helper/DataSourceHelper.java49
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/output/ByteArrayDataSink.java3
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/signator/textual/TextualSignator_1_0_0.java2
-rw-r--r--src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java19
-rw-r--r--src/main/java/at/gv/egiz/pdfas/web/SignSessionInformation.java13
-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
15 files changed, 260 insertions, 53 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java b/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java
index 265cb0c..fcf55b8 100644
--- a/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java
+++ b/src/main/java/at/gv/egiz/pdfas/framework/input/DataSource.java
@@ -32,4 +32,19 @@ public interface DataSource
*/
public int getLength();
+ /**
+ * Returns the data of this DataSource as a byte array.
+ *
+ * <p>
+ * Calling this method indicates that you need a byte array for random <strong>read</strong> access.
+ * The DataSource implementation should of course cache this byte array to avoid too much memory usage.
+ * </p>
+ * <p>
+ * Performance analysis has shown that the libraries internally convert the streams to byte arrays and
+ * that file system access is very slow.
+ * </p>
+ *
+ * @return
+ */
+ public byte [] getAsByteArray();
}
diff --git a/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java b/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java
index d7d0cc4..595df52 100644
--- a/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java
+++ b/src/main/java/at/gv/egiz/pdfas/framework/output/DataSink.java
@@ -12,4 +12,8 @@ public interface DataSink
public OutputStream createOutputStream(String mimeType);
public OutputStream createOutputStream(String mimeType, String characterEncoding);
+
+ public String getMimeType();
+
+ public String getCharacterEncoding();
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/ByteArrayPdfDataSourceImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/input/ByteArrayPdfDataSourceImpl.java
index 0d27781..e4a5649 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/ByteArrayPdfDataSourceImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/ByteArrayPdfDataSourceImpl.java
@@ -23,34 +23,43 @@ public class ByteArrayPdfDataSourceImpl implements PdfDataSource
{
protected byte[] pdf = null;
- protected int length = -1;
-
public ByteArrayPdfDataSourceImpl(byte[] pdf)
{
PerformanceCounters.byteArrays.increment();
this.pdf = pdf;
- this.length = pdf.length;
}
public ByteArrayPdfDataSourceImpl(byte[] pdf, int length)
{
PerformanceCounters.byteArrays.increment();
- this.pdf = pdf;
- this.length = length;
+ if (pdf.length == length)
+ {
+ this.pdf = pdf;
+ }
+ else
+ {
+ this.pdf = new byte [length];
+ System.arraycopy(pdf, 0, this.pdf, 0, length);
+ }
}
public InputStream createInputStream()
{
- ByteArrayInputStream bais = new ByteArrayInputStream(this.pdf, 0, this.length);
+ ByteArrayInputStream bais = new ByteArrayInputStream(this.pdf);
return bais;
}
public int getLength()
{
- return this.length;
+ return this.pdf.length;
}
+ public byte[] getAsByteArray()
+ {
+ return this.pdf;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/CompoundPdfDataSourceImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/input/CompoundPdfDataSourceImpl.java
index f77d6be..4f00bb5 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/CompoundPdfDataSourceImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/CompoundPdfDataSourceImpl.java
@@ -43,5 +43,23 @@ public class CompoundPdfDataSourceImpl implements PdfDataSource
{
return this.originalDataSource.getLength() + this.appendix.length;
}
+
+ byte [] cache = null;
+ /**
+ * @see at.gv.egiz.pdfas.framework.input.DataSource#getAsByteArray()
+ */
+ public byte[] getAsByteArray()
+ {
+ if (cache != null)
+ {
+ return cache;
+ }
+
+ cache = new byte [getLength()];
+ System.arraycopy(originalDataSource.getAsByteArray(), 0, cache, 0, originalDataSource.getLength());
+ System.arraycopy(appendix, 0, cache, originalDataSource.getLength(), appendix.length);
+
+ return cache;
+ }
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/DelimitedPdfDataSource.java b/src/main/java/at/gv/egiz/pdfas/impl/input/DelimitedPdfDataSource.java
index 6c67be2..63874c7 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/DelimitedPdfDataSource.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/DelimitedPdfDataSource.java
@@ -41,4 +41,22 @@ public class DelimitedPdfDataSource implements PdfDataSource
return this.len;
}
+ byte [] cache = null;
+
+ /**
+ * @see at.gv.egiz.pdfas.framework.input.DataSource#getAsByteArray()
+ */
+ public byte[] getAsByteArray()
+ {
+ if (cache != null)
+ {
+ return cache;
+ }
+
+ cache = new byte [getLength()];
+ System.arraycopy(dataSource.getAsByteArray(), 0, cache, 0, getLength());
+
+ return cache;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedPdfDataSourceImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedPdfDataSourceImpl.java
index 8453192..a3a0803 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedPdfDataSourceImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedPdfDataSourceImpl.java
@@ -3,6 +3,7 @@
*/
package at.gv.egiz.pdfas.impl.input;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -13,6 +14,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
/**
* @author wprinz
@@ -78,6 +80,15 @@ public class FileBasedPdfDataSourceImpl implements PdfDataSource, FileBased
*/
public InputStream createInputStream()
{
+ if (cache == null)
+ {
+ getAsByteArray();
+ }
+ return new ByteArrayInputStream(cache);
+ }
+
+ protected InputStream createFileInputStream()
+ {
try
{
FileInputStream fis = new FileInputStream(getFile());
@@ -92,7 +103,6 @@ public class FileBasedPdfDataSourceImpl implements PdfDataSource, FileBased
return null;
}
}
-
/**
* @see at.gv.egiz.pdfas.framework.input.PdfDataSource#getLength()
*/
@@ -100,4 +110,22 @@ public class FileBasedPdfDataSourceImpl implements PdfDataSource, FileBased
{
return this.length;
}
+
+ byte [] cache = null;
+
+ /**
+ * @see at.gv.egiz.pdfas.framework.input.DataSource#getAsByteArray()
+ */
+ public byte[] getAsByteArray()
+ {
+ if (cache != null)
+ {
+ return cache;
+ }
+
+ cache = DataSourceHelper.convertInputStreamToByteArray(createFileInputStream());
+
+ return cache;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedTextDataSourceImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedTextDataSourceImpl.java
index 6f6c7b4..1988519 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedTextDataSourceImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/FileBasedTextDataSourceImpl.java
@@ -13,6 +13,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.gv.egiz.pdfas.framework.input.TextDataSource;
+import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
/**
* @author wprinz
@@ -121,4 +122,21 @@ public class FileBasedTextDataSourceImpl implements TextDataSource, FileBased
return (int) getFile().length();
}
+ byte [] cache = null;
+
+ /**
+ * @see at.gv.egiz.pdfas.framework.input.DataSource#getAsByteArray()
+ */
+ public byte[] getAsByteArray()
+ {
+ if (cache != null)
+ {
+ return cache;
+ }
+
+ cache = DataSourceHelper.convertInputStreamToByteArray(createInputStream());
+
+ return cache;
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/TextDataSourceImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/input/TextDataSourceImpl.java
index b259a3e..c983a8a 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/TextDataSourceImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/TextDataSourceImpl.java
@@ -79,4 +79,20 @@ public class TextDataSourceImpl implements TextDataSource
}
}
+ /**
+ * @see at.gv.egiz.pdfas.framework.input.DataSource#getAsByteArray()
+ */
+ public byte[] getAsByteArray()
+ {
+ try
+ {
+ byte[] data = getText().getBytes("UTF-8");
+ return data;
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
}
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/input/helper/DataSourceHelper.java b/src/main/java/at/gv/egiz/pdfas/impl/input/helper/DataSourceHelper.java
index 1e2ffdc..138b269 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/input/helper/DataSourceHelper.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/input/helper/DataSourceHelper.java
@@ -3,6 +3,7 @@
*/
package at.gv.egiz.pdfas.impl.input.helper;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -42,24 +43,54 @@ public class DataSourceHelper
*/
public static byte[] convertDataSourceToByteArray(DataSource pdfDataSource)
{
+ return pdfDataSource.getAsByteArray();
+// try
+// {
+// PerformanceCounters.byteArrays.increment();
+//
+// byte[] data = new byte[pdfDataSource.getLength()];
+//
+// int bytes_written = 0;
+//
+// InputStream is = pdfDataSource.createInputStream();
+// int n = 0;
+// while ((n = is.read(data, bytes_written, data.length - bytes_written)) > 0)
+// {
+// bytes_written += n;
+// }
+// is.close();
+//
+// assert bytes_written == data.length;
+//
+// return data;
+// }
+// catch (IOException e)
+// {
+// log.error(e);
+// throw new RuntimeException(e);
+// }
+ }
+
+ public static byte [] convertInputStreamToByteArray(InputStream inputStream)
+ {
try
{
PerformanceCounters.byteArrays.increment();
- byte[] data = new byte[pdfDataSource.getLength()];
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
+
+ byte[] temp = new byte[4096];
- int bytes_written = 0;
-
- InputStream is = pdfDataSource.createInputStream();
int n = 0;
- while ((n = is.read(data, bytes_written, data.length - bytes_written)) > 0)
+ while ((n = inputStream.read(temp)) > 0)
{
- bytes_written += n;
+ baos.write(temp, 0, n);
}
- is.close();
-
- assert bytes_written == data.length;
+ inputStream.close();
+ baos.close();
+ byte [] data = baos.toByteArray();
+
return data;
}
catch (IOException e)
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/output/ByteArrayDataSink.java b/src/main/java/at/gv/egiz/pdfas/impl/output/ByteArrayDataSink.java
index f3d1283..3a3aeca 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/output/ByteArrayDataSink.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/output/ByteArrayDataSink.java
@@ -47,6 +47,9 @@ public class ByteArrayDataSink implements DataSink
*/
public OutputStream createOutputStream(String mimeType, String characterEncoding)
{
+ this.mimeType = mimeType;
+ this.characterEncoding = characterEncoding;
+
if (this.baos != null)
{
log.warn("An output stream is created twice. The old one will be rendered useless.");
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/signator/textual/TextualSignator_1_0_0.java b/src/main/java/at/gv/egiz/pdfas/impl/signator/textual/TextualSignator_1_0_0.java
index b0494c8..1714afc 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/signator/textual/TextualSignator_1_0_0.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/signator/textual/TextualSignator_1_0_0.java
@@ -91,7 +91,7 @@ public class TextualSignator_1_0_0 implements Signator
tsi.profile = profile;
tsi.pos = pos;
- String document_text = PdfAS.extractNormalizedTextTextual(pdfDataSource.createInputStream());
+ String document_text = PdfAS.extractNormalizedTextTextual(pdfDataSource);
// logger_.debug("signed_text = " + document_text);
DataSource ds = new TextDataSourceImpl(document_text);
diff --git a/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java b/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java
index 981b868..0c9e1f2 100644
--- a/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java
+++ b/src/main/java/at/gv/egiz/pdfas/impl/vfilter/VerificationFilterImpl.java
@@ -18,7 +18,7 @@ import at.gv.egiz.pdfas.framework.input.TextDataSource;
import at.gv.egiz.pdfas.framework.verificator.Verificator;
import at.gv.egiz.pdfas.framework.vfilter.VerificationFilter;
import at.gv.egiz.pdfas.framework.vfilter.VerificationFilterParameters;
-import at.gv.egiz.pdfas.impl.input.DelimitedInputStream;
+import at.gv.egiz.pdfas.impl.input.DelimitedPdfDataSource;
import at.gv.egiz.pdfas.impl.input.helper.DataSourceHelper;
import at.gv.egiz.pdfas.impl.vfilter.helper.VerificationFilterBinaryHelper;
import at.gv.egiz.pdfas.impl.vfilter.helper.VerificationFilterHelper;
@@ -285,8 +285,9 @@ public class VerificationFilterImpl implements VerificationFilter
protected String extractText(PdfDataSource pdf, int endOfDocument) throws PresentableException
{
- DelimitedInputStream dis = new DelimitedInputStream(pdf.createInputStream(), endOfDocument);
- return PdfAS.extractNormalizedTextTextual(dis);
+ DelimitedPdfDataSource dds = new DelimitedPdfDataSource(pdf, endOfDocument);
+ //DelimitedInputStream dis = new DelimitedInputStream(pdf.createInputStream(), endOfDocument);
+ return PdfAS.extractNormalizedTextTextual(dds);
}
protected List extractNewSignaturesFromText(String text) throws VerificationFilterException
@@ -453,6 +454,18 @@ public class VerificationFilterImpl implements VerificationFilter
log.debug("Extracting signatures:");
List extractedSignatures = extractNewSignaturesFromText(extractedText);
log.debug("Extracting signatures finished.");
+
+ if (log.isDebugEnabled())
+ {
+ log.debug("extracted signatures:");
+ for (int i = 0; i < extractedSignatures.size(); i++)
+ {
+ SignatureHolder sh = (SignatureHolder)extractedSignatures.get(i);
+ String dateStr = sh.getSignatureObject().getSignationDate();
+ EGIZDate ed = EGIZDate.parseFromString(dateStr);
+ log.debug("#" + i + ": dateStr = " + dateStr + ", egizDate = " + ed.toString());
+ }
+ }
return extractedSignatures;
}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/SignSessionInformation.java b/src/main/java/at/gv/egiz/pdfas/web/SignSessionInformation.java
index 459a104..1ed0cab 100644
--- a/src/main/java/at/gv/egiz/pdfas/web/SignSessionInformation.java
+++ b/src/main/java/at/gv/egiz/pdfas/web/SignSessionInformation.java
@@ -9,14 +9,13 @@ import java.util.Properties;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
-import at.gv.egiz.pdfas.impl.input.FileBasedPdfDataSourceImpl;
-import at.gv.egiz.pdfas.impl.output.FileBasedDataSink;
-import at.gv.egiz.pdfas.web.helper.TempDirHelper;
-import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import at.gv.egiz.pdfas.framework.input.PdfDataSource;
+import at.gv.egiz.pdfas.framework.output.DataSink;
+import at.gv.egiz.pdfas.framework.signator.SignatorInformation;
+import at.gv.egiz.pdfas.web.helper.TempDirHelper;
import at.knowcenter.wag.egov.egiz.pdf.TablePos;
import at.knowcenter.wag.egov.egiz.web.ExternAppInformation;
import at.knowcenter.wag.egov.egiz.web.LocalRequest;
@@ -55,7 +54,7 @@ public class SignSessionInformation implements HttpSessionBindingListener, Seria
/**
* The original, uploaded pdf.
*/
- public FileBasedPdfDataSourceImpl pdfDataSource = null;
+ public PdfDataSource pdfDataSource = null;
/**
* The type/profile of the signature.
@@ -94,7 +93,7 @@ public class SignSessionInformation implements HttpSessionBindingListener, Seria
/**
* The DataSink to write the output data to.
*/
- public FileBasedDataSink output = null;
+ public DataSink output = null;
/**
* The local request to be sent to the device.
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.