WatchEvent
Stay organized with collections
Save and categorize content based on your preferences.
An event or a repeated event for an object that is registered with a WatchService
.
An event is classified by its kind
and has a count
to indicate the number of times that the event has been
observed. This allows for efficient representation of repeated events. The
context
method returns any context associated with
the event. In the case of a repeated event then the context is the same for
all events.
Watch events are immutable and safe for use by multiple concurrent
threads.
Public Method Summary
abstract
T
|
context()
Returns the context for the event.
|
abstract
int
|
count()
Returns the event count.
|
abstract
Kind<T>
|
kind()
Returns the event kind.
|
Public Methods
public
abstract
T
context
()
Returns the context for the event.
In the case of ENTRY_CREATE
,
ENTRY_DELETE
, and ENTRY_MODIFY
events the context is
a Path
that is the relative
path between
the directory registered with the watch service, and the entry that is
created, deleted, or modified.
Returns
- the event context; may be
null
public
abstract
int
count
()
Returns the event count. If the event count is greater than 1
then this is a repeated event.
public
abstract
Kind<T>
kind
()
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eWatchEvent\u003c/code\u003e represents an event (or repeated event) for an object registered with a \u003ccode\u003eWatchService\u003c/code\u003e, providing information about changes to the watched object.\u003c/p\u003e\n"],["\u003cp\u003eEach event has a \u003ccode\u003ekind\u003c/code\u003e (type of event), a \u003ccode\u003ecount\u003c/code\u003e (number of occurrences), and a \u003ccode\u003econtext\u003c/code\u003e (object-specific information).\u003c/p\u003e\n"],["\u003cp\u003eEvents can indicate file creation, deletion, or modification within a watched directory, with the context often being the relative path to the affected file.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eWatchEvent\u003c/code\u003e interface provides methods to access these event details, aiding in monitoring and managing changes to registered files and directories.\u003c/p\u003e\n"],["\u003cp\u003eThese events are immutable, ensuring safe access from multiple threads.\u003c/p\u003e\n"]]],["`WatchEvent` represents events for objects registered with a `WatchService`. Key actions include retrieving the event's `kind`, `count`, and `context`. `kind` identifies the event type, `count` indicates event repetition, and `context` provides associated information, often a relative `Path`. Events are immutable and thread-safe. The `context` method returns the context for the event. `count` returns the number of times the event is observed. `kind` method returns the type of the event.\n"],null,["public interface **WatchEvent** \nAn event or a repeated event for an object that is registered with a [WatchService](../../../../reference/java/nio/file/WatchService.html).\n\nAn event is classified by its [kind](../../../../reference/java/nio/file/WatchEvent.html#kind()) and has a [count](../../../../reference/java/nio/file/WatchEvent.html#count()) to indicate the number of times that the event has been\nobserved. This allows for efficient representation of repeated events. The\n[context](../../../../reference/java/nio/file/WatchEvent.html#context()) method returns any context associated with\nthe event. In the case of a repeated event then the context is the same for\nall events.\n\nWatch events are immutable and safe for use by multiple concurrent\nthreads. \n\nNested Class Summary\n\n|-----------|---|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| interface | [WatchEvent.Kind](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003cT\\\u003e || An event kind, for the purposes of identification. |\n| interface | [WatchEvent.Modifier](../../../../reference/java/nio/file/WatchEvent.Modifier.html) || An event modifier that qualifies how a [Watchable](../../../../reference/java/nio/file/Watchable.html) is registered with a [WatchService](../../../../reference/java/nio/file/WatchService.html). |\n\nPublic Method Summary\n\n|--------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|\n| abstract T | [context](../../../../reference/java/nio/file/WatchEvent.html#context())() Returns the context for the event. |\n| abstract int | [count](../../../../reference/java/nio/file/WatchEvent.html#count())() Returns the event count. |\n| abstract [Kind](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003cT\\\u003e | [kind](../../../../reference/java/nio/file/WatchEvent.html#kind())() Returns the event kind. |\n\nPublic Methods \n\npublic abstract T\n**context**\n() \nReturns the context for the event.\n\nIn the case of [ENTRY_CREATE](../../../../reference/java/nio/file/StandardWatchEventKinds.html#ENTRY_CREATE),\n[ENTRY_DELETE](../../../../reference/java/nio/file/StandardWatchEventKinds.html#ENTRY_DELETE), and [ENTRY_MODIFY](../../../../reference/java/nio/file/StandardWatchEventKinds.html#ENTRY_MODIFY) events the context is\na `Path` that is the [relative](../../../../reference/java/nio/file/Path.html#relativize(java.nio.file.Path)) path between\nthe directory registered with the watch service, and the entry that is\ncreated, deleted, or modified. \n\nReturns\n\n- the event context; may be `null` \n\npublic abstract int\n**count**\n() \nReturns the event count. If the event count is greater than `1`\nthen this is a repeated event. \n\nReturns\n\n- the event count \n\npublic abstract [Kind](../../../../reference/java/nio/file/WatchEvent.Kind.html)\\\u003cT\\\u003e\n**kind**\n() \nReturns the event kind. \n\nReturns\n\n- the event kind"]]