From 78020825e9edfee1842e3d642ef762e5be1ab4bd Mon Sep 17 00:00:00 2001 From: Bryan Bende Date: Thu, 29 Sep 2016 13:49:27 -0400 Subject: [PATCH] NIFI-2841 Refactoring logic in SplitAvro RecordSplitter to avoid making two calls in a row to reader.hasNext() This closes #1088 --- .../java/org/apache/nifi/processors/avro/SplitAvro.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java index e3eb6ec577..83964fa720 100644 --- a/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java +++ b/nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/main/java/org/apache/nifi/processors/avro/SplitAvro.java @@ -267,7 +267,8 @@ public class SplitAvro extends AbstractProcessor { } // while records are left, start a new split by spawning a FlowFile - while (reader.hasNext()) { + final AtomicReference hasNextHolder = new AtomicReference(reader.hasNext()); + while (hasNextHolder.get()) { FlowFile childFlowFile = session.create(originalFlowFile); childFlowFile = session.write(childFlowFile, new OutputStreamCallback() { @Override @@ -277,11 +278,13 @@ public class SplitAvro extends AbstractProcessor { // append to the current FlowFile until no more records, or splitSize is reached int recordCount = 0; - while (reader.hasNext() && recordCount < splitSize) { + while (hasNextHolder.get() && recordCount < splitSize) { recordHolder.set(reader.next(recordHolder.get())); splitWriter.write(recordHolder.get()); recordCount++; + hasNextHolder.set(reader.hasNext()); } + splitWriter.flush(); } finally { splitWriter.close();