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());
        }
    }
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());
        }
    }
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

@param stream the InputStream to read
@return the stream's content as a byte[]
@throws AlgoliaException if the stream can't be read or flushed
Reads the InputStream into a byte array