aliocrlib/src/main/java/com/lib/aliocr/utils/io/IOUtils.java
/**
     * Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
     * Use this method instead of <code>toByteArray(InputStream)</code>
     * when <code>InputStream</code> size is known
     *
     * @param input the <code>InputStream</code> to read from
     * @param size  the size of <code>InputStream</code>
     * @return the requested byte array
     * @throws IOException              if an I/O error occurs or <code>InputStream</code> size differ from parameter size
     * @throws IllegalArgumentException if size is less than zero
     * @since 2.1
     */
Get the contents of an InputStream as a byte[].
Use this method instead of toByteArray(InputStream)
when InputStream size is known


Get the contents of an InputStream as a byte [] . Use this method instead of toByteArray ( InputStream ) when InputStream size is known
public static byte[] toByteArray(InputStream input, int size) throws IOException {
        if (size < 0) {
            throw new IllegalArgumentException("Size must be equal or greater than zero: " + size);
        }
        if (size == 0) {
            return new byte[0];
        }
        byte[] data = new byte[size];
        int offset = 0;
        int read;
        while (offset < size && (read = input.read(data, offset, size - offset)) != EOF) {
            offset += read;
        }
        if (offset != size) {
            throw new IOException("Unexpected read size. current: " + offset + ", excepted: " + size);
        }
        return data;
    }
public static byte [ ] toByteArray ( InputStream input , int size ) throws IOException { if ( size < 0 ) { throw new IllegalArgumentException ( "Size must be equal or greater than zero: " + size ) ; } if ( size == 0 ) { return new byte [ 0 ] ; } byte [ ] data = new byte [ size ] ; int offset = 0 ; int read ; while ( offset < size && ( read = input . read ( data , offset , size - offset ) ) != EOF ) { offset += read ; } if ( offset != size ) { throw new IOException ( "Unexpected read size. current: " + offset + ", excepted: " + size ) ; } return data ; }
Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
Get the contents of an <code > InputStream< / code > as a <code > byte [] < / code > .