Here you can find the source of getStreamData(InputStream is)
Parameter | Description |
---|---|
is | input stream to be read |
Parameter | Description |
---|---|
IOException | on stream access error |
private static byte[] getStreamData(InputStream is) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { private static final int COPY_BUFFER_SIZE = 1024; /**//from w ww .j a v a 2 s .c om * Read contents of stream into byte array. * * @param is input stream to be read * @return array of bytes containing all data from stream * @throws IOException on stream access error */ private static byte[] getStreamData(InputStream is) throws IOException { byte[] buff = new byte[COPY_BUFFER_SIZE]; ByteArrayOutputStream os = new ByteArrayOutputStream(); int count; while ((count = is.read(buff)) >= 0) { os.write(buff, 0, count); } return os.toByteArray(); } }