From 11b5950be66bcc9d6f0bb28d3fc9d211bc70f4d9 Mon Sep 17 00:00:00 2001 From: tknall Date: Tue, 16 Mar 2010 12:07:29 +0000 Subject: Catching OutOfMemory exceptions, returning appropriate error message/code Binary signature: bug concerning indirect pdf objects fixed SignaturePositioning improved (Signature position can be declared by String which is parsed) Some more error codes (Out of memory, Invalid signature position) iText utility for creation of pdf files added ConfigUtils updated (destination of configuration to be extracted can now be chosen) PDFASUtils updated (more tools) WebApplication: Freetext pdf creation implemented WebApplication: XSS security updates git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@580 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../java/at/gv/egiz/pdfas/utils/PDFASUtils.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java') diff --git a/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java b/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java index b26cc9b..9841779 100644 --- a/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java +++ b/src/main/java/at/gv/egiz/pdfas/utils/PDFASUtils.java @@ -1,5 +1,12 @@ package at.gv.egiz.pdfas.utils; +import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; + import at.gv.egiz.pdfas.exceptions.ErrorCode; import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException; @@ -26,5 +33,28 @@ public class PDFASUtils { throw new PDFDocumentException(ErrorCode.DOCUMENT_IS_PROTECTED, "Document is protected."); } } + + public static boolean toFile(byte[] data, File file) throws IOException { + return PDFASUtils.toFile(new ByteArrayInputStream(data), file); + } + + public static boolean toFile(InputStream inputStream, File file) throws IOException { + boolean result = false; + BufferedOutputStream bufferedOutputStream = null; + try { + bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file)); + ConfigUtils.writeInputStreamToOutputStream(inputStream, bufferedOutputStream); + } finally { + if (bufferedOutputStream != null) { + try { + bufferedOutputStream.close(); + result = true; + } catch (IOException e) { + result = false; + } + } + } + return result; + } } -- cgit v1.2.3