goja-core/src/main/java/goja/core/kits/stream/StreamUtil.java
public static byte[] readAvailableBytes(InputStream in) throws IOException {
        int l = in.available();
        byte byteArray[] = new byte[l];
        int i = 0, j;
        while ((i < l) && (j = in.read(byteArray, i, l - i)) >= 0) {
            i += j;
        }
        if (i < l) {
            throw new IOException("Failed to completely read input stream");
        }
        return byteArray;
    }
public static byte[] readAvailableBytes(InputStream in) throws IOException {
        int l = in.available();
        byte byteArray[] = new byte[l];
        int i = 0, j;
        while ((i < l) && (j = in.read(byteArray, i, l - i)) >= 0) {
            i += j;
        }
        if (i < l) {
            throw new IOException("Failed to completely read input stream");
        }
        return byteArray;
    }
Reads all available bytes from InputStream as a byte array.
Uses <code>in.available()</code> to determine the size of input stream.
This is the fastest method for reading input stream to byte array, but
depends on stream implementation of <code>available()</code>.
Buffered internally.