public static long pipe(InputStream input, OutputStream output, byte[] buffer) throws IOException {
        if (buffer == null && input instanceof ClickHouseInputStream && output instanceof ClickHouseOutputStream) {
            return ((ClickHouseInputStream) input).pipe((ClickHouseOutputStream) output);
        } else if (input == null || output == null || buffer == null || buffer.length < 1) {
            throw new IllegalArgumentException("Non-null input, output, and write buffer are required");
        }

        int size = buffer.length;
        long count = 0L;
        int written = 0;
        try (InputStream in = input) {
            while ((written = in.read(buffer, 0, size)) >= 0) {
                output.write(buffer, 0, written);
                count += written;
            }
        }
        return count;
    }
Transfers data from input stream to output stream. Input stream will be
closed but output stream will remain open. Please pay attention that you need
to explictly call {@code output.flush()} before closing output stream.

@param input  non-null input stream, which will be closed
@param output non-null output stream, which will remain open
@param buffer non-empty buffer
@return written bytes
@throws IOException when error occured reading from input stream or writing
                    data to output stream
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseInputStream.java