com.clickhouse.data.stream.IterableByteArrayInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of clickhouse-data Show documentation
Show all versions of clickhouse-data Show documentation
Data processing utilities for ClickHouse
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;
}
}