Class ChunkReader


  • public final class ChunkReader
    extends Object
    Provides an efficient means to read JFR data, chunk by chunk. The actual method employed will depend on whether the JFR file is available as a stream or as a file, and whether or not the data is compressed or not.

    Each chunk will be self-contained and parsable, for example by wrapping it in a ByteArrayInputStream and using the JfrLoaderToolkit.

    • Method Detail

      • readChunks

        public static Iterator<byte[]> readChunks​(File jfrFile)
                                           throws IOException
        Reads a JFR file, chunk by chunk.

        Each chunk will be self contained and parsable, for example by wrapping it in a ByteArrayInputStream. Note that Iterator.next() can throw IllegalArgumentException if it encounters a corrupted chunk.

        Parameters:
        jfrFile - the file to read binary data from
        Returns:
        returns an iterator over byte arrays, where each byte array is a self containing jfr chunk
        Throws:
        IOException
      • readChunks

        public static Iterator<byte[]> readChunks​(InputStream jfrStream)
                                           throws IOException
        Reads a JFR file, chunk by chunk, from a stream.

        Each chunk will be self contained and parsable, for example by wrapping it in a ByteArrayInputStream. Note that Iterator.next() can throw IllegalArgumentException if it encounters a corrupted chunk.

        Parameters:
        jfrStream - the stream to read binary data from
        Returns:
        returns an iterator over byte arrays, where each byte array is a self containing JFR chunk
        Throws:
        IOException
      • main

        public static void main​(String[] args)
                         throws IOException
        Program for listing the number of chunks in a recording.
        Parameters:
        args - takes one argument, which must be the path to a recording
        Throws:
        IOException - if there was a problem reading the file