mayi-common/mayi-common-core/src/main/java/com/zf1976/mayi/common/core/util/IOUtil.java
public static byte[] readRange(final ReadableByteChannel input, final int len) throws IOException {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        final ByteBuffer b = ByteBuffer.allocate(Math.min(len, COPY_BUF_SIZE));
        int read = 0;
        while (read < len) {
            final int readNow = input.read(b);
            if (readNow <= 0) {
                break;
            }
            output.write(b.array(), 0, readNow);
            b.rewind();
            read += readNow;
        }
        return output.toByteArray();
    }
/**
     * Gets part of the contents of an <code>ReadableByteChannel</code> as a <code>byte[]</code>.
     *
     * @param input the <code>ReadableByteChannel</code> to read from
     * @param len   maximum amount of bytes to copy
     * @return the requested byte array
     * @throws NullPointerException if the input is null
     * @throws IOException          if an I/O error occurs
     * @since 1.21
     */
Gets part of the contents of an ReadableByteChannel as a byte[].
Gets part of the contents of an ReadableByteChannel as a byte [] .
public static byte[] readRange(final ReadableByteChannel input, final int len) throws IOException {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        final ByteBuffer b = ByteBuffer.allocate(Math.min(len, COPY_BUF_SIZE));
        int read = 0;
        while (read < len) {
            final int readNow = input.read(b);
            if (readNow <= 0) {
                break;
            }
            output.write(b.array(), 0, readNow);
            b.rewind();
            read += readNow;
        }
        return output.toByteArray();
    }
public static byte [ ] readRange ( final ReadableByteChannel input , final int len ) throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream ( ) ; final ByteBuffer b = ByteBuffer . allocate ( Math . min ( len , COPY_BUF_SIZE ) ) ; int read = 0 ; while ( read < len ) { final int readNow = input . read ( b ) ; if ( readNow <= 0 ) { break ; } output . write ( b . array ( ) , 0 , readNow ) ; b . rewind ( ) ; read += readNow ; } return output . toByteArray ( ) ; }
Gets part of the contents of an <code>ReadableByteChannel</code> as a <code>byte[]</code>.
Gets part of the contents of an <code > ReadableByteChannel< / code > as a <code > byte [] < / code > .