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

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

There is a newer version: 0.7.1-patch1
Show newest version
package com.clickhouse.data.stream;

import java.io.IOException;
import java.util.Iterator;

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

public class IterableByteArrayInputStream extends AbstractByteArrayInputStream {
    private final Iterator it;

    public IterableByteArrayInputStream(Iterable source, Runnable postCloseAction) {
        super(null, null, postCloseAction);

        it = ClickHouseChecker.nonNull(source, "Source").iterator();
    }

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

        while (it.hasNext()) {
            byte[] bytes = it.next();
            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 - 2024 Weber Informatics LLC | Privacy Policy