src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java
branchJEP-349-branch
changeset 57374 41f0051285e0
parent 57372 50ca040843ea
child 57376 8e8a06a3059c
--- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java	Fri May 24 20:30:12 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventFileStream.java	Fri May 24 20:45:11 2019 +0200
@@ -42,8 +42,11 @@
  */
 final class EventFileStream implements EventStream {
 
-    final static class FileEventConsumer extends EventConsumer {
+    private final static class FileEventConsumer extends EventConsumer {
         private final RecordingInput input;
+        private ChunkParser chunkParser;
+        private RecordedEvent event;
+        private boolean moreEvents = true;
 
         public FileEventConsumer(AccessControlContext acc, RecordingInput input) throws IOException {
             super(acc);
@@ -52,11 +55,30 @@
 
         @Override
         public void process() throws Exception {
-            // TODO This need more work; filter, multiple chunk etc
-            ChunkParser cp = new ChunkParser(input);
-            while (true) {
-                RecordedEvent e = cp.readEvent();
-                dispatch(e);
+            chunkParser = new ChunkParser(input);
+            while (moreEvents) {
+                event = chunkParser.readEvent();
+                if (event == null) {
+                    findNext();
+                    if (!moreEvents) {
+                        return;
+                    }
+                }
+                dispatch(event);
+            }
+        }
+
+        private void findNext() throws IOException {
+            while (event == null) {
+                if (chunkParser == null) {
+                    chunkParser = new ChunkParser(input);
+                } else if (!chunkParser.isLastChunk()) {
+                    chunkParser = chunkParser.nextChunkParser();
+                } else {
+                    moreEvents = false;
+                    return;
+                }
+                event = chunkParser.readEvent();
             }
         }
     }