private static byte [ ] _toByteArray ( InputStream stream ) throws AlgoliaException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; int read ; byte [ ] buffer = new byte [ 1024 ] ; try { while ( ( read = stream . read ( buffer , 0 , buffer . length ) ) != - 1 ) { out . write ( buffer , 0 , read ) ; } out . flush ( ) ; return out . toByteArray ( ) ; } catch ( IOException e ) { throw new AlgoliaException ( "Error while reading stream: " + e . getMessage ( ) ) ; } }
Reads the InputStream into a byte array