1 /*
2 * Created on Sep 28, 2003
3 * Copyright (c) 2003. All rights reserved.
4 */
5 package portaview.util;
6
7 import java.io.ByteArrayOutputStream;
8 import java.io.InputStream;
9
10 /***
11 * Utility to read in streams.
12 * @author <a href="mailto:wwlee1@uiuc.edu">William Lee</a>
13 * @version $Id: StreamUtils.java,v 1.2 2003/12/10 06:18:56 wlee Exp $
14 */
15 public class StreamUtils
16 {
17 /***
18 * Reads a stream into a byte array.
19 * @param in The input stream
20 * @return a newly allocated byte array
21 * @throws Exception if there is anything wrong during the read.
22 */
23 public static byte[] getBytesFromStream(InputStream in)
24 throws Exception
25 {
26 int chunkSize = 2048;
27 byte[] buf = new byte[chunkSize];
28 ByteArrayOutputStream byteStream =
29 new ByteArrayOutputStream(chunkSize);
30 int count;
31
32 while ((count = in.read(buf)) != -1)
33 byteStream.write(buf, 0, count);
34
35 return byteStream.toByteArray();
36 }
37 }
This page was automatically generated by Maven