com.spredfast.kafka.connect.s3.RecordReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kafka-connect-s3 Show documentation
Show all versions of kafka-connect-s3 Show documentation
S3 Source and Sink Connectors for Kafka Connect
package com.spredfast.kafka.connect.s3;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.connect.errors.DataException;
/**
* Record oriented version of RecordsReader. Can be used to simplify your implementation.
*/
public interface RecordReader extends S3RecordsReader {
ConsumerRecord read(String topic, int partition, long offset, BufferedInputStream data) throws IOException;
static RecordReader of(RecordReader r) { return r; }
@Override
default Iterator> readAll(final String topic, final int partition, final InputStream inputStream, final long startOffset) {
return new Iterator>() {
ConsumerRecord next;
final BufferedInputStream buffered = new BufferedInputStream(inputStream);
long offset = startOffset;
@Override
public boolean hasNext() {
try {
if (next == null) {
next = read(topic, partition, offset++, buffered);
}
} catch (IOException e) {
throw new DataException(e);
}
return next != null;
}
@Override
public ConsumerRecord next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
final ConsumerRecord record = this.next;
next = null;
return record;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}