Source:
<code>public Firehose connect(final InputRowParser<ByteBuffer> firehoseParser, File temporaryDirectory) throws IOException { Set<String> newDimExclus = Sets.union( firehoseParser.getParseSpec().getDimensionsSpec().getDimensionExclusions(), Sets.newHashSet("feed") ); final InputRowParser<ByteBuffer> theParser = firehoseParser.withParseSpec( firehoseParser.getParseSpec() .withDimensionsSpec( firehoseParser.getParseSpec() .getDimensionsSpec() .withDimensionExclusions( newDimExclus ) ) ); final ConsumerConnector connector = Consumer.createJavaConsumerConnector(new ConsumerConfig(consumerProps)); final Map<String, List<KafkaStream<byte[], byte[]>>> streams = connector.createMessageStreams( ImmutableMap.of( feed, 1 ) ); final List<KafkaStream<byte[], byte[]>> streamList = streams.get(feed); if (streamList == null || streamList.size() != 1) { return null; } final KafkaStream<byte[], byte[]> stream = streamList.get(0); final ConsumerIterator<byte[], byte[]> iter = stream.iterator(); return new Firehose() { Iterator<InputRow> nextIterator = Iterators.emptyIterator(); @Override public boolean hasMore() { <START> return iter.hasNext() || nextIterator.hasNext(); <END> } @Nullable @Override public InputRow nextRow() { try { if (!nextIterator.hasNext()) { final byte[] message = iter.next().message(); if (message == null) { return null; } nextIterator = theParser.parseBatch(ByteBuffer.wrap(message)).iterator(); } return nextIterator.next(); } catch (InvalidMessageException e) { log.error(e, "Message failed its checksum and it is corrupt, will skip it"); return null; } } @Override public Runnable commit() { return new Runnable() { @Override public void run() { log.info("committing offsets"); connector.commitOffsets(); } }; } @Override public void close() throws IOException { connector.shutdown(); } }; }</code><technical_language>check nextIterator.hasNext() ConsumerIterator.hasNext() in case implementation is blocking, for example in implementations: <LINK_0></technical_language>

Target:
public Firehose connect(final InputRowParser<ByteBuffer> firehoseParser, File temporaryDirectory) throws IOException { Set<String> newDimExclus = Sets.union( firehoseParser.getParseSpec().getDimensionsSpec().getDimensionExclusions(), Sets.newHashSet("feed") ); final InputRowParser<ByteBuffer> theParser = firehoseParser.withParseSpec( firehoseParser.getParseSpec() .withDimensionsSpec( firehoseParser.getParseSpec() .getDimensionsSpec() .withDimensionExclusions( newDimExclus ) ) ); final ConsumerConnector connector = Consumer.createJavaConsumerConnector(new ConsumerConfig(consumerProps)); final Map<String, List<KafkaStream<byte[], byte[]>>> streams = connector.createMessageStreams( ImmutableMap.of( feed, 1 ) ); final List<KafkaStream<byte[], byte[]>> streamList = streams.get(feed); if (streamList == null || streamList.size() != 1) { return null; } final KafkaStream<byte[], byte[]> stream = streamList.get(0); final ConsumerIterator<byte[], byte[]> iter = stream.iterator(); return new Firehose() { Iterator<InputRow> nextIterator = Iterators.emptyIterator(); @Override public boolean hasMore() { return nextIterator.hasNext() || iter.hasNext(); } @Nullable @Override public InputRow nextRow() { try { if (!nextIterator.hasNext()) { final byte[] message = iter.next().message(); if (message == null) { return null; } nextIterator = theParser.parseBatch(ByteBuffer.wrap(message)).iterator(); } return nextIterator.next(); } catch (InvalidMessageException e) { log.error(e, "Message failed its checksum and it is corrupt, will skip it"); return null; } } @Override public Runnable commit() { return new Runnable() { @Override public void run() { log.info("committing offsets"); connector.commitOffsets(); } }; } @Override public void close() throws IOException { connector.shutdown(); } }; }