Class ChunkReader.ChunkIterator

  • All Implemented Interfaces:
    java.util.Iterator<byte[]>
    Enclosing class:
    ChunkReader

    private static class ChunkReader.ChunkIterator
    extends java.lang.Object
    implements java.util.Iterator<byte[]>
    Chunk iterator for an uncompressed JFR file. Efficiently reads a JFR file, chunk by chunk, into memory as byte arrays by memory mapping the JFR file, finding the chunk boundaries with a minimum of parsing, and then block-transferring the byte arrays. The transfers will be done on Iterator.next(), and the resulting byte array will only be reachable for as long as it is referenced. The JFR file must not be zip or gzip compressed.

    Note that Iterator.next() can throw IllegalArgumentException if it encounters a corrupted chunk.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.MappedByteBuffer buffer  
      private java.nio.channels.FileChannel channel  
      private java.io.RandomAccessFile file  
      (package private) int lastChunkOffset  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ChunkIterator​(java.io.File jfrFile)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean bufferHasMagic​(int[] magicBytes)  
      private boolean checkHasMore()  
      boolean hasNext()  
      byte[] next()  
      void remove()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Iterator

        forEachRemaining
    • Field Detail

      • lastChunkOffset

        int lastChunkOffset
      • file

        private java.io.RandomAccessFile file
      • channel

        private final java.nio.channels.FileChannel channel
      • buffer

        private final java.nio.MappedByteBuffer buffer
    • Constructor Detail

      • ChunkIterator

        private ChunkIterator​(java.io.File jfrFile)
                       throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • hasNext

        public boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<byte[]>
      • checkHasMore

        private boolean checkHasMore()
      • next

        public byte[] next()
        Specified by:
        next in interface java.util.Iterator<byte[]>
      • bufferHasMagic

        private boolean bufferHasMagic​(int[] magicBytes)
      • remove

        public void remove()
        Specified by:
        remove in interface java.util.Iterator<byte[]>