public long pipe(ClickHouseOutputStream output) throws IOException {
        long count = 0L;
        if (output == null || output.isClosed()) {
            return count;
        }
        ensureOpen();

        try (ClickHouseInputStream in = this) {
            for (ClickHouseByteBuffer buf : in) {
                count += buf.length();
                output.writeBuffer(buf);
            }
        }
        return count;
    }
Reads all remaining bytes and write into given output stream. Current input
stream will be closed automatically at the end of writing, but {@code output}
will remain open.

@param output non-null output stream
@return bytes being written into output stream
@throws IOException when failed to read value from input stream or reached
                    end of the stream
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseInputStream.java