Here you can find the source of getStreamAsBytes(final InputStream is)
Parameter | Description |
---|---|
is | the input stream |
public static byte[] getStreamAsBytes(final InputStream is) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { /**/*from ww w . jav a 2 s. c o m*/ * Converst input stream into the byte array. * * @param is the input stream * @return the byte array */ public static byte[] getStreamAsBytes(final InputStream is) throws IOException { final BufferedInputStream bis = new BufferedInputStream(is); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final byte[] buffer = new byte[2048]; while (true) { final int n = bis.read(buffer); if (n == -1) { break; } baos.write(buffer, 0, n); } bis.close(); baos.close(); return baos.toByteArray(); } }