Closeable
, AutoCloseable
public final class RecordingFile extends Object implements Closeable
The following example shows how read and print all events in a recording file.
try (RecordingFile recordingFile = new RecordingFile(Paths.get("recording.jfr"))) {
while (recordingFile.hasMoreEvents()) {
RecordedEvent event = recordingFile.readEvent();
System.out.println(event);
}
}
Constructor | Description |
---|---|
RecordingFile |
Creates a recording file. |
Modifier and Type | Method | Description |
---|---|---|
void |
close() |
Closes this recording file and releases any system resources that are associated with it. |
boolean |
hasMoreEvents() |
Returns true if unread events exist in the recording file, false otherwise. |
static List |
readAllEvents |
Returns a list of all events in a file. |
RecordedEvent |
readEvent() |
Reads the next event in the recording. |
List |
readEventTypes() |
Returns a list of all event types in this recording. |
void |
write |
Filter out events and write them to a new file. |
public RecordingFile(Path file) throws IOException
Only recording files from trusted sources should be used.
file
- the path of the file to open, not null
IOException
- if it's not a valid recording file, or an I/O error occurredNoSuchFileException
- if the file
can't be locatedSecurityException
- if a security manager exists and its checkRead
method denies read access to the file.public RecordedEvent readEvent() throws IOException
null
EOFException
- if no more events exist in the recording fileIOException
- if an I/O error occurspublic boolean hasMoreEvents()
true
if unread events exist in the recording file, false
otherwise.true
if unread events exist in the recording, false
otherwise.public List<EventType> readEventTypes() throws IOException
null
IOException
- if an I/O error occurred while reading from the filepublic void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
IOException
- if an I/O error occurredpublic void write(Path destination, Predicate<RecordedEvent> filter) throws IOException
destination
- path where the new file should be written, not null
filter
- filter that determines if an event should be included, not null
IOException
- if an I/O error occurred, it's not a Flight Recorder file or a version of a JFR file that can't be parsedSecurityException
- if a security manager exists and its checkWrite
method denies write access to the filepublic static List<RecordedEvent> readAllEvents(Path path) throws IOException
This method is intended for simple cases where it's convenient to read all events in a single operation. It isn't intended for reading large files.
Only recording files from trusted sources should be used.
path
- the path to the file, not null
List
object; whether the List
is modifiable or not is implementation dependent and therefore not specified, not null
IOException
- if an I/O error occurred, it's not a 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.
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/jdk.jfr/jdk/jfr/consumer/RecordingFile.html