Class ChunkReader
- java.lang.Object
-
- org.openjdk.jmc.flightrecorder.util.ChunkReader
-
public final class ChunkReader extends java.lang.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 theJfrLoaderToolkit
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ChunkReader.ChunkIterator
Chunk iterator for an uncompressed JFR file.private static class
ChunkReader.StreamChunkIterator
Iterator reading JFR chunks from a stream.private static class
ChunkReader.StreamState
-
Field Summary
Fields Modifier and Type Field Description private static int[]
GZ_MAGIC
private static int
HEADER_SIZE
private static int[]
JFR_MAGIC
private static byte[]
JFR_MAGIC_BYTES
private static int[]
ZIP_MAGIC
-
Constructor Summary
Constructors Modifier Constructor Description private
ChunkReader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
main(java.lang.String[] args)
Program for listing the number of chunks in a recording.static java.util.Iterator<byte[]>
readChunks(java.io.File jfrFile)
Reads a JFR file, chunk by chunk.static java.util.Iterator<byte[]>
readChunks(java.io.InputStream jfrStream)
Reads a JFR file, chunk by chunk, from a stream.
-
-
-
Field Detail
-
JFR_MAGIC_BYTES
private static final byte[] JFR_MAGIC_BYTES
-
JFR_MAGIC
private static final int[] JFR_MAGIC
-
ZIP_MAGIC
private static final int[] ZIP_MAGIC
-
GZ_MAGIC
private static final int[] GZ_MAGIC
-
HEADER_SIZE
private static final int HEADER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
readChunks
public static java.util.Iterator<byte[]> readChunks(java.io.File jfrFile) throws java.io.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 thatIterator.next()
can throwIllegalArgumentException
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:
java.io.IOException
-
readChunks
public static java.util.Iterator<byte[]> readChunks(java.io.InputStream jfrStream) throws java.io.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 thatIterator.next()
can throwIllegalArgumentException
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:
java.io.IOException
-
main
public static void main(java.lang.String[] args) throws java.io.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:
java.io.IOException
- if there was a problem reading the file
-
-