public static File save(ClickHouseDataConfig config, InputStream input, File file) {
        final File tmp;
        if (file != null) {
            tmp = file;
        } else {
            try {
                tmp = ClickHouseUtils.createTempFile();
            } catch (IOException e) {
                throw new UncheckedIOException("Failed to create temp file", e);
            }
        }

        final int bufferSize;
        final long timeout;
        if (config != null) {
            bufferSize = config.getWriteBufferSize();
            timeout = config.getWriteTimeout();
        } else {
            bufferSize = ClickHouseDataConfig.DEFAULT_WRITE_BUFFER_SIZE;
            timeout = ClickHouseDataConfig.DEFAULT_TIMEOUT;
        }

        if (timeout <= 0L) {
            try {
                try (OutputStream out = new FileOutputStream(tmp)) {
                    pipe(input, out, bufferSize);
                }
                return tmp;
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        } else {
            CompletableFuture<File> data = ClickHouseDataStreamFactory.getInstance().runBlockingTask(() -> {
                try {
                    try (OutputStream out = new FileOutputStream(tmp)) {
                        pipe(input, out, bufferSize);
                    }
                    return tmp;
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            });

            try {
                return data.get(timeout, TimeUnit.MILLISECONDS);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new IllegalStateException(e);
            } catch (TimeoutException e) {
                throw new IllegalStateException(e);
            } catch (ExecutionException e) {
                Throwable cause = e.getCause();
                if (cause instanceof UncheckedIOException) {
                    throw ((UncheckedIOException) cause);
                } else if (cause instanceof IOException) {
                    throw new UncheckedIOException((IOException) cause);
                }
                throw new IllegalStateException(cause);
            }
        }
    }
Saves data from the given input stream to the specified file.

@param config config, could be null
@param input  non-null input stream
@param file   target file, could be null
@return non-null file
clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseInputStream.java