@Override
    public void write(byte[] b, int off, int len) throws IOException {
        if (closed) {
            throw new IllegalStateException("Already closed");
        }
        final int remaining = buffer.writableBytes();
        if (remaining >= len) {
            buffer.writeBytes(b, off, len);
        } else {
            buffer.writeBytes(b, off, remaining);
            flush();
            write(b, off + remaining, len - remaining);
        }
    }
An {@link OutputStream} that uses {@link ByteBuf} to accumulate stream data before flushing to the
designated {@link Consumer}.
resteasy/src/main/java/com/linecorp/armeria/internal/common/resteasy/ByteBufferBackedOutputStream.java