src/jdk.jfr/share/classes/jdk/jfr/internal/consumer/RecordingInput.java
branchJEP-349-branch
changeset 57425 1da8552f0b59
parent 57386 acdd0dbe37ee
child 57452 6fabe73e5d9a
equal deleted inserted replaced
57386:acdd0dbe37ee 57425:1da8552f0b59
    63            blockPosition = 0;
    63            blockPosition = 0;
    64            size = 0;
    64            size = 0;
    65         }
    65         }
    66     }
    66     }
    67 
    67 
    68     private final RandomAccessFile file;
    68     private RandomAccessFile file;
    69     private final String filename;
    69     private String filename;
    70     private Block currentBlock = new Block();
    70     private Block currentBlock = new Block();
    71     private Block previousBlock = new Block();
    71     private Block previousBlock = new Block();
    72     private long position;
    72     private long position;
    73     private final int blockSize;
    73     private final int blockSize;
    74     private long size = -1; // Fail fast if setSize(...) has not been called before parsing
    74     private long size = -1; // Fail fast if setSize(...) has not been called before parsing
    75 
    75 
    76     public RecordingInput(File f, int blockSize) throws IOException {
    76     public RecordingInput(File f, int blockSize) throws IOException {
    77         this.blockSize = blockSize;
    77         this.blockSize = blockSize;
       
    78         initialize(f);
       
    79     }
       
    80 
       
    81     private void initialize(File f) throws IOException {
    78         this.filename = f.getAbsolutePath().toString();
    82         this.filename = f.getAbsolutePath().toString();
    79         this.file = new RandomAccessFile(f, "r");
    83         this.file = new RandomAccessFile(f, "r");
       
    84         this.position = 0;
       
    85         this.size = -1;
       
    86         this.currentBlock.reset();
       
    87         this.previousBlock.reset();
    80         if (f.length() < 8) {
    88         if (f.length() < 8) {
    81             throw new IOException("Not a valid Flight Recorder file. File length is only " + f.length() + " bytes.");
    89             throw new IOException("Not a valid Flight Recorder file. File length is only " + f.length() + " bytes.");
    82         }
    90         }
    83     }
    91     }
    84 
    92 
   333         return filename;
   341         return filename;
   334     }
   342     }
   335 
   343 
   336     // Purpose of this method is to reuse block cache from a
   344     // Purpose of this method is to reuse block cache from a
   337     // previous RecordingInput
   345     // previous RecordingInput
   338     public RecordingInput newFile(Path path) throws IOException  {
   346     public void setFile(Path path) throws IOException  {
   339         try {
   347         try {
   340             close();
   348             file.close();
   341         } catch (IOException e) {
   349         } catch (IOException e) {
   342             // perhaps deleted
   350             // perhaps deleted
   343         }
   351         }
   344         RecordingInput input = new RecordingInput(path.toFile(), this.blockSize);
   352         file = null;
   345         input.currentBlock = this.currentBlock;
   353         initialize(path.toFile());
   346         input.currentBlock.reset();
       
   347         input.previousBlock = this.previousBlock;
       
   348         input.previousBlock.reset();
       
   349 
       
   350         return input;
       
   351     }
   354     }
   352 
   355 
   353 }
   356 }