APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.jfr.consumer

public final Class RecordingFile

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.Closeable, .EOFException, .File, .IOException, java.nio.file.NoSuchFileException, .Path, java.util.ArrayList, .HashSet, .List, .Objects, java.util.function.Predicate, jdk.jfr.EventType, jdk.jfr.internal.MetadataDescriptor, .Type, jdk.jfr.internal.consumer.ChunkParser.ParserConfiguration, .ParserFilter, .ChunkHeader, .ChunkParser, .ParserState, .RecordingInput, jdk.jfr.internal.consumer.filter.ChunkWriter, .ChunkWriter.RemovedEvents

A recording file.

The following example shows how to 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); } }
try (RecordingFile recordingFile = new RecordingFile(Paths.get("recording.jfr"))) {
    while (recordingFile.hasMoreEvents()) {
        RecordedEvent event = recordingFile.readEvent();
        System.out.println(event);
    }
}
Since
9

Field Summary

Modifier and TypeField and Description
private ChunkParser
private final ChunkWriter
private boolean
private final File
private RecordingInput
private boolean
private RecordedEvent
private final ParserState

Constructor Summary

AccessConstructor and Description
public
RecordingFile(Path
the path of the file to open, not null
file
)

Creates a recording file.

private

Method Summary

Modifier and TypeMethod and Description
private static MetadataDescriptor
private MetadataDescriptor
public void
close()

Implements java.io.Closeable.close.

Closes this recording file and releases any system resources that are associated with it.

private ChunkParser
private void
private void
private void
pack-priv File
public boolean

Returns:

true if unread events exist in the recording, false otherwise.
hasMoreEvents
()

Returns true if unread events exist in the recording file, false otherwise.

pack-priv boolean
private ChunkParser
public static List<RecordedEvent>

Returns:

the events from the file as a List object; whether the List is modifiable or not is implementation dependent and therefore not specified, not null
readAllEvents
(Path
the path to the file, not null
path
)

Returns a list of all events in a file.

public RecordedEvent

Returns:

the next event, not null
readEvent
()

Reads the next event in the recording.

public List<EventType>

Returns:

a list of event types, not null
readEventTypes
()

Returns a list of all event types in this recording.

pack-priv List<Type>
public void
write(Path
path where the new file should be written, not null
destination
,
Predicate<RecordedEvent>
filter that determines if an event should be included, not null
filter
)

Filter out events and write them to a new file.

pack-priv List<ChunkWriter.RemovedEvents>
write(Path destination, Predicate<RecordedEvent> filter, boolean collectResults)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chunkParserback to summary
private ChunkParser chunkParser
chunkWriterback to summary
private final ChunkWriter chunkWriter
eofback to summary
private boolean eof
fileback to summary
private final File file
inputback to summary
private RecordingInput input
isLastEventInChunkback to summary
private boolean isLastEventInChunk
nextEventback to summary
private RecordedEvent nextEvent
parserStateback to summary
private final ParserState parserState

Constructor Detail

RecordingFileback to summary
public RecordingFile(Path file) throws IOException

Creates a recording file.

Only recording files from trusted sources should be used.

Parameters
file:Path

the path of the file to open, not null

Exceptions
IOException:
if it's not a valid recording file, or an I/O error occurred
NoSuchFileException:
if the file can't be located
RecordingFileback to summary
private RecordingFile(ChunkWriter chunkWriter) throws IOException

Method Detail

aggregateEventTypeForChunkback to summary
private static MetadataDescriptor aggregateEventTypeForChunk(ChunkHeader ch, MetadataDescriptor previous, List<EventType> types, HashSet<Long> foundIds) throws IOException
aggregateTypeForChunkback to summary
private MetadataDescriptor aggregateTypeForChunk(ChunkHeader ch, MetadataDescriptor previous, List<Type> types, HashSet<Long> foundIds) throws IOException
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Closes this recording file and releases any system resources that are associated with it.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurred
createChunkParserback to summary
private ChunkParser createChunkParser() throws IOException
endChunkParserback to summary
private void endChunkParser() throws IOException
ensureOpenback to summary
private void ensureOpen() throws IOException
findNextback to summary
private void findNext() throws IOException
getFileback to summary
pack-priv File getFile()
hasMoreEventsback to summary
public boolean hasMoreEvents()

Returns true if unread events exist in the recording file, false otherwise.

Returns:boolean

true if unread events exist in the recording, false otherwise.

isLastEventInChunkback to summary
pack-priv boolean isLastEventInChunk()
nextChunkParserback to summary
private ChunkParser nextChunkParser() throws IOException
readAllEventsback to summary
public static List<RecordedEvent> readAllEvents(Path path) throws IOException

Returns a list of all events in a file.

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.

Parameters
path:Path

the path to the file, not null

Returns:List<RecordedEvent>

the events from the file as a List object; whether the List is modifiable or not is implementation dependent and therefore not specified, not null

Exceptions
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 parsed
readEventback to summary
public RecordedEvent readEvent() throws IOException

Reads the next event in the recording.

Returns:RecordedEvent

the next event, not null

Exceptions
IOException:
if an I/O error occurs
EOFException:
if no more events exist in the recording file
See Also
hasMoreEvents()
readEventTypesback to summary
public List<EventType> readEventTypes() throws IOException

Returns a list of all event types in this recording.

Returns:List<EventType>

a list of event types, not null

Exceptions
IOException:
if an I/O error occurred while reading from the file
See Also
hasMoreEvents()
readTypesback to summary
pack-priv List<Type> readTypes() throws IOException
writeback to summary
public void write(Path destination, Predicate<RecordedEvent> filter) throws IOException

Filter out events and write them to a new file.

Parameters
destination:Path

path where the new file should be written, not null

filter:Predicate<RecordedEvent>

filter that determines if an event should be included, not null

Exceptions
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 parsed
Since
19
writeback to summary
pack-priv List<ChunkWriter.RemovedEvents> write(Path destination, Predicate<RecordedEvent> filter, boolean collectResults) throws IOException