Here you can find the source of inputStreamToByteArray(InputStream is)
Parameter | Description |
---|---|
is | input stream for converting |
Parameter | Description |
---|---|
IOException | If the first byte cannot be read for any reasonother than end of file, or if the input stream has been closed, or ifsome other I/O error occurs. |
public static byte[] inputStreamToByteArray(InputStream is) 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 w w .ja va 2 s . c om*/ * Generates byte array with contents of a stream * * @param is input stream for converting * @return byte array with contents of a stream * @throws IOException If the first byte cannot be read for any reason * other than end of file, or if the input stream has been closed, or if * some other I/O error occurs. */ public static byte[] inputStreamToByteArray(InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) != -1) { baos.write(bytes, 0, length); } return baos.toByteArray(); } }