From fc44d4bcad00192f0df8f6086737b9b126094dcd Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Thu, 26 Sep 2013 15:48:43 +0200 Subject: initial code commit --- .../at/gv/egiz/pdfas/common/utils/StreamUtils.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java (limited to 'pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java') diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java new file mode 100644 index 00000000..0b15d700 --- /dev/null +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/utils/StreamUtils.java @@ -0,0 +1,28 @@ +package at.gv.egiz.pdfas.common.utils; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * Created with IntelliJ IDEA. + * User: afitzek + * Date: 8/29/13 + * Time: 9:54 AM + * To change this template use File | Settings | File Templates. + */ +public class StreamUtils { + + public static byte[] inputStreamToByteArray(InputStream stream) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] buffer = new byte[4096]; + int readBytes = 0; + + while((readBytes = stream.read(buffer)) != -1) { + bos.write(buffer, 0, readBytes); + } + stream.close(); + bos.close(); + return bos.toByteArray(); + } +} -- cgit v1.2.3