public abstract class FolderWatcher extends Object implements Runnable, Watchable, Stoppable, SafeCloseable
Modifier and Type | Field and Description |
---|---|
protected WatchHandler |
handler |
protected WatchEvent.Kind<?>[] |
kinds |
protected WatchEvent.Modifier[] |
modifiers |
protected boolean |
run |
protected Map<WatchKey,Path> |
watchKeys |
protected WatchService |
watchService |
Modifier | Constructor and Description |
---|---|
protected |
FolderWatcher(WatchHandler handler,
WatchEvent.Kind<?>... kinds) |
protected |
FolderWatcher(WatchHandler handler,
WatchEvent.Modifier[] modifiers,
WatchEvent.Kind<?>... kinds) |
protected |
FolderWatcher(WatchHandler handler,
WatchEvent.Modifier[] modifiers,
WatchEventKind... kinds) |
protected |
FolderWatcher(WatchHandler handler,
WatchEventKind... kinds) |
Modifier and Type | Method and Description |
---|---|
void |
close()
安全关闭
|
Collection<Path> |
getWatchPaths() |
protected void |
init()
初始化
|
void |
registerPath(File path) |
void |
registerPath(File path,
int maxDepth) |
void |
registerPath(Path path) |
void |
registerPath(Path path,
int maxDepth)
注册监听的文件夹到 service
如果文件夹不存在则创建
可以监听到新的文件 但是监听不到新的文件夹
|
void |
registerPath(String path) |
void |
registerPath(String path,
int maxDepth) |
void |
registerPath(URI path) |
void |
registerPath(URI path,
int maxDepth) |
void |
run() |
void |
stop()
停止
|
protected WatchHandler handler
protected WatchEvent.Kind<?>[] kinds
protected WatchEvent.Modifier[] modifiers
protected volatile boolean run
protected WatchService watchService
protected FolderWatcher(WatchHandler handler, WatchEventKind... kinds)
protected FolderWatcher(WatchHandler handler, WatchEvent.Kind<?>... kinds)
protected FolderWatcher(WatchHandler handler, WatchEvent.Modifier[] modifiers, WatchEventKind... kinds)
protected FolderWatcher(WatchHandler handler, WatchEvent.Modifier[] modifiers, WatchEvent.Kind<?>... kinds)
protected void init()
public void registerPath(String path)
public void registerPath(File path)
public void registerPath(URI path)
public void registerPath(Path path)
public void registerPath(String path, int maxDepth)
public void registerPath(File path, int maxDepth)
public void registerPath(URI path, int maxDepth)
public void registerPath(Path path, int maxDepth)
如果文件夹不存在则创建
可以监听到新的文件 但是监听不到新的文件夹
path
- pathmaxDepth
- 递归子目录深度 =1不递归 >1递归 x - 1public void stop()
Stoppable
public void close()
SafeCloseable
close
in interface SafeCloseable
close
in interface Closeable
close
in interface AutoCloseable
public Collection<Path> getWatchPaths()
Copyright © 2024. All rights reserved.