Here you can find the source of readBytes(InputStream inputStream)
InputStream
.
Parameter | Description |
---|---|
inputStream | The <code>InputStream</code> to be read. |
Parameter | Description |
---|---|
IOException | In case of exception during reading of <code>InputStream</code>. |
InpuStream
.
public static byte[] readBytes(InputStream inputStream) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /**// w w w. ja va2s. co m * Reads all bytes from given <code>InputStream</code>. This method does not close underlying * <code>InputStream</code> and end of proccess. * * @param inputStream The <code>InputStream</code> to be read. * * @return All bytes read from <code>InpuStream</code>. * @throws IOException In case of exception during reading of <code>InputStream</code>. */ public static byte[] readBytes(InputStream inputStream) throws IOException { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); byte[] buff = new byte[1024]; int r = 0; while ((r = inputStream.read(buff)) >= 0) { arrayOutputStream.write(buff, 0, r); } return arrayOutputStream.toByteArray(); } }