src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java
branchJEP-349-branch
changeset 57386 acdd0dbe37ee
parent 57360 5d043a159d5c
child 57425 1da8552f0b59
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java	Fri May 31 20:44:28 2019 +0200
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java	Mon Jun 03 16:21:47 2019 +0200
@@ -30,6 +30,7 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.nio.file.Path;
 
 public final class RecordingInput implements DataInput, AutoCloseable {
 
@@ -57,6 +58,11 @@
         public byte get(long position) {
             return bytes[(int) (position - blockPosition)];
         }
+
+        public void reset() {
+           blockPosition = 0;
+           size = 0;
+        }
     }
 
     private final RandomAccessFile file;
@@ -79,6 +85,7 @@
     public RecordingInput(File f) throws IOException {
         this(f, DEFAULT_BLOCK_SIZE);
     }
+
     public void positionPhysical(long position) throws IOException {
         file.seek(position);
     }
@@ -326,4 +333,21 @@
         return filename;
     }
 
+    // Purpose of this method is to reuse block cache from a
+    // previous RecordingInput
+    public RecordingInput newFile(Path path) throws IOException  {
+        try {
+            close();
+        } catch (IOException e) {
+            // perhaps deleted
+        }
+        RecordingInput input = new RecordingInput(path.toFile(), this.blockSize);
+        input.currentBlock = this.currentBlock;
+        input.currentBlock.reset();
+        input.previousBlock = this.previousBlock;
+        input.previousBlock.reset();
+
+        return input;
+    }
+
 }