@Override
    public ClickHouseByteBuffer readCustom(ClickHouseDataUpdater reader) throws IOException {
        if (reader == null) {
            return byteBuffer.reset();
        }
        ensureOpen();

        LinkedList<byte[]> list = new LinkedList<>();
        int length = 0;
        boolean more = true;
        while (more) {
            int remain = buffer.remaining();
            if (remain < 1) {
                closeQuietly();
                more = false;
            } else {
                int position = buffer.position();
                int limit = buffer.limit();
                byte[] bytes = ClickHouseByteUtils.getOrCopy(buffer, remain);
                int read = reader.update(bytes, 0, remain);
                if (read == -1) {
                    list.add(bytes);
                    length += remain;
                    ((Buffer) buffer).position(limit);
                    if (updateBuffer() < 1) {
                        closeQuietly();
                        more = false;
                    }
                } else {
                    if (read > 0) {
                        list.add(Arrays.copyOfRange(bytes, 0, read));
                        length += read;
                        ((Buffer) buffer).position(position + read);
                    }
                    more = false;
                }
            }
        }
        return byteBuffer.update(list, 0, length);
    }
Update inner buffer as needed.

@return remaining bytes in buffer
@throws IOException when failed to update buffer
clickhouse-data/src/main/java/com/clickhouse/data/stream/AbstractByteBufferInputStream.java