Here you can find the source of InputStreamToByteArray(InputStream inputStream)
Parameter | Description |
---|---|
inputStream | Input stream to be read. |
public static byte[] InputStreamToByteArray(InputStream inputStream)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { /**/* w w w. j av a 2 s . c o m*/ * Blocking read of an entire input stream into a byte array. * @param inputStream Input stream to be read. * @return Byte array contents of an input stream. */ public static byte[] InputStreamToByteArray(InputStream inputStream) { try { int i; ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); while ((i = inputStream.read()) != -1) { byteArrayOutputStream.write(i); } return byteArrayOutputStream.toByteArray(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } finally { try { inputStream.close(); } catch (Exception exception) { exception.printStackTrace(); } } } }