public final class WaitFile extends Object
The goal is to wait for filesystem event, by using the
WatchService functionality.
WatchService| Modifier and Type | Method | Description |
|---|---|---|
static WaitResultBuilder1<Collection<WatchEvent<Path>>> |
eventIn(Path directory,
WatchEvent.Kind<Path>... events) |
Wait for a folder to have some event.
|
static WaitResultBuilder1<Collection<Path>> |
newFileIn(Path directory) |
Wait for a folder to contains new entry.
|
static WaitResultBuilder1<Path> |
newFileNamedIn(Path directory,
String name) |
Wait for a folder to contains new entry based on his name.
|
static WaitResultBuilder1<Collection<Path>> |
removeFileFrom(Path directory) |
Wait for a folder to have entry removed.
|
@SafeVarargs public static WaitResultBuilder1<Collection<WatchEvent<Path>>> eventIn(Path directory, WatchEvent.Kind<Path>... events)
The wait starts at the first try to get the result.
For example :
CompletableFuture<Optional<Collection<WatchEvent<Path>>>> wait = WaitFile
.eventIn(test, StandardWatchEventKinds.ENTRY_CREATE)
.expecting(l -> l.stream().map(WatchEvent::context).map(Path::getFileName).map(Path::toString)
.anyMatch(n -> n.equals("test")))
.repeat(3).every(Duration.ofMillis(250)).usingDefaultExecutor().asyncExec();
Defines a 3 tries with a wait time of 250ms, for a creation event, containing
at least one event with last part of a path named test.directory - the directory to be verified.events - the events to wait for.WaitResultBuilder1 the next step of the builder.public static WaitResultBuilder1<Collection<Path>> newFileIn(Path directory)
The wait starts at the first try to get the result.
For example :
CompletableFuture<Optional<Collection<Path>>> wait = WaitFile.newFileIn(test)
.expecting(l -> l.stream().map(Path::getFileName).map(Path::toString).anyMatch(n -> n.equals("test")))
.repeat(3).every(Duration.ofMillis(250)).usingDefaultExecutor().asyncExec();
Defines a 3 tries with a wait time of 250ms, for a list of new file,
containing at least one file with last part of a path named test.directory - the directory to be verified.WaitResultBuilder1 the next step of the builder.public static WaitResultBuilder1<Path> newFileNamedIn(Path directory, String name)
The wait starts at the first try to get the result.
For example :
CompletableFuture<Optional<Path>> wait = WaitFile.newFileNamedIn(test, "test").expectingNotNull().repeat(3)
.every(Duration.ofMillis(250)).usingDefaultExecutor().asyncExec();
Defines a 3 tries with a wait time of 25ms, for a file named "test".directory - the directory to be verified.name - the expected nameWaitResultBuilder1 the next step of the builder.public static WaitResultBuilder1<Collection<Path>> removeFileFrom(Path directory)
The wait starts at the first try to get the result.
directory - the directory to be verified.WaitResultBuilder1 the next step of the builder.Copyright © 2021. All rights reserved.