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 --- .../pdfas/impl/input/helper/DataSourceHelper.java | 49 ++++++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) (limited to 'src/main/java/at/gv/egiz/pdfas/impl/input/helper') 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; @@ -41,25 +42,55 @@ public class DataSourceHelper * @throws IOException */ 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) -- cgit v1.2.3