All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickhouse.data.stream.ByteArrayQueueInputStream Maven / Gradle / Ivy

There is a newer version: 0.7.2
Show newest version
package com.clickhouse.data.stream;

import com.clickhouse.data.ClickHouseByteBuffer;
import com.clickhouse.data.ClickHouseChecker;

import java.io.IOException;
import java.util.Queue;

public class ByteArrayQueueInputStream extends AbstractByteArrayInputStream {

    private final Queue queue;

    public ByteArrayQueueInputStream(Queue queue, Runnable postCloseAction) {
        super(null, null, postCloseAction);
        this.queue =  ClickHouseChecker.nonNull(queue, "queue");;
    }

    @Override
    protected int updateBuffer() throws IOException {
        position = 0;

        while (!queue.isEmpty()) {
            byte[] bytes = queue.poll();
            int len = bytes != null ? bytes.length : 0;
            if (len > 0) {
                buffer = bytes;
                if (copyTo != null) {
                    copyTo.write(bytes);
                }
                return limit = len;
            }
        }

        buffer = ClickHouseByteBuffer.EMPTY_BYTES;
        return limit = 0;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy