goja-core/src/main/java/goja/core/kits/stream/StreamUtil.java
public static int copy(Reader input, Writer output, int charCount) throws IOException {
        char buffer[] = new char[ioBufferSize];
        int count = 0;
        int read;
        while (charCount > 0) {
            if (charCount < ioBufferSize) {
                read = input.read(buffer, 0, charCount);
            } else {
                read = input.read(buffer, 0, ioBufferSize);
            }
            if (read == -1) {
                break;
            }
            charCount -= read;
            count += read;
            output.write(buffer, 0, read);
        }
        return count;
    }
public static int copy(Reader input, Writer output, int charCount) throws IOException {
        char buffer[] = new char[ioBufferSize];
        int count = 0;
        int read;
        while (charCount > 0) {
            if (charCount < ioBufferSize) {
                read = input.read(buffer, 0, charCount);
            } else {
                read = input.read(buffer, 0, ioBufferSize);
            }
            if (read == -1) {
                break;
            }
            charCount -= read;
            count += read;
            output.write(buffer, 0, read);
        }
        return count;
    }
Copies specified number of characters from reader to writer using buffer.