public static byte [ ] toByteArray ( InputStream source , int bufferSize ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; copy ( source , baos , bufferSize ) ; source . close ( ) ; return baos . toByteArray ( ) ; }
Reads the given input stream into a byte array and closes the input stream