Here you can find the source of readAll(InputStream stream)
Parameter | Description |
---|---|
stream | the stream to read |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] readAll(InputStream stream) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /**/*from w ww. j ava 2 s . c o m*/ * Reads all the available bytes in the provided stream to a byte array. * <p> * The implementation of this method will cause a temporary memory use * of up to the equivalent of three times the size of the resulting array. * @param stream the stream to read * @return the read bytes * @throws IOException */ public static byte[] readAll(InputStream stream) throws IOException { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[100]; int len = 0; while ((len = stream.read(buffer)) != -1) outStream.write(buffer, 0, len); return outStream.toByteArray(); } }