@Override
    public ClickHouseOutputStream writeCustom(ClickHouseDataUpdater writer) throws IOException {
        ensureOpen();

        int position = 0;
        int written = 0;
        do {
            position = buffer.position();
            int limit = buffer.limit();
            byte[] bytes;
            if (buffer.hasArray()) {
                bytes = buffer.array();
            } else {
                bytes = new byte[limit - position];
                buffer.get(bytes);
            }
            written = writer.update(bytes, position, limit);
            if (written < 0) {
                ((Buffer) buffer).position(limit);
                updateBuffer(true);
            }
        } while (written < 0);
        ((Buffer) buffer).position(position + written);
        return this;
    }
A combination of {@link java.io.PipedOutputStream} and
{@link java.io.PipedInputStream} for streaming data between server and
client. To avoid dead lock and high memory usage, please make sure writer and
reader are on two separate threads.
clickhouse-data/src/main/java/com/clickhouse/data/stream/BlockingPipedOutputStream.java