- java.lang.Object
-
- jdk.jfr.consumer.RecordingFile
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public final class RecordingFile extends Object implements Closeable
A recording file.Example,
try (RecordingFile recordingFile = new RecordingFile(Paths.get("recording.jfr"))) { while (recordingFile.hasMoreEvents()) { RecordedEvent event = recordingFile.readEvent(); System.out.println(event); } }
- Since:
- 9
-
-
Constructor Summary
Constructors Constructor Description RecordingFile(Path file)
Create a recording file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this recording file and releases any system resources associated with it.boolean
hasMoreEvents()
Returnstrue
if there are unread events in the recording file,false
otherwise.static List<RecordedEvent>
readAllEvents(Path path)
Returns a list of all events in a file.RecordedEvent
readEvent()
Reads the next event in the recording.List<EventType>
readEventTypes()
Returns a list of all event types in this recording.
-
-
-
Constructor Detail
-
RecordingFile
public RecordingFile(Path file) throws IOException
Create a recording file.- Parameters:
file
- path of the file to open notnull
- Throws:
IOException
- if it's not a valid recording file, or an I/O error occurredNoSuchFileException
- iffile
can't be locatedSecurityException
- if a security manager exists and itscheckRead
method denies read access to the file.
-
-
Method Detail
-
readEvent
public RecordedEvent readEvent() throws IOException
Reads the next event in the recording.- Returns:
- the next event, not
null
- Throws:
EOFException
- if there are no more events in the recording fileIOException
- if an I/O error occurs.- See Also:
hasMoreEvents()
-
hasMoreEvents
public boolean hasMoreEvents()
Returnstrue
if there are unread events in the recording file,false
otherwise.- Returns:
true
if there are unread events in the recording,false
otherwise.
-
readEventTypes
public List<EventType> readEventTypes() throws IOException
Returns a list of all event types in this recording.- Returns:
- a list of event types, not
null
- Throws:
IOException
- if an I/O error occurred while reading from the file- See Also:
hasMoreEvents()
-
close
public void close() throws IOException
Closes this recording file and releases any system resources associated with it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error occurred
-
readAllEvents
public static List<RecordedEvent> readAllEvents(Path path) throws IOException
Returns a list of all events in a file.Note that this method is intended for simple cases where it is convenient to read all events in a single operation. It is not intended for reading large files.
- Parameters:
path
- the path to the file, notnull
- Returns:
- the events from the file as a
List
; whether theList
is modifiable or not is implementation dependent and therefore not specified, notnull
- Throws:
IOException
- if an I/O error occurred, it's not a Java Flight Recorder file or a version of a JFR file that can't be parsedSecurityException
- if a security manager exists and its checkRead method denies read access to the file.
-
-