Iterator<Event> eventsIter = events.iterator();
while (eventsIter.hasNext()) {
thriftFlumeEvents.clear();
for (int i = 0; i < batchSize && eventsIter.hasNext(); i++) {
Event event = eventsIter.next();
thriftFlumeEvents.add(new ThriftFlumeEvent(event.getHeaders(),
ByteBuffer.wrap(event.getBody())));
}
if (!thriftFlumeEvents.isEmpty()) {
doAppendBatch(client, thriftFlumeEvents).get(requestTimeout,
TimeUnit.MILLISECONDS);