本文整理汇总了Java中java.nio.file.WatchEvent.Modifier方法的典型用法代码示例。如果您正苦于以下问题:Java WatchEvent.Modifier方法的具体用法?Java WatchEvent.Modifier怎么用?Java WatchEvent.Modifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.WatchEvent
的用法示例。
在下文中一共展示了WatchEvent.Modifier方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: instantiateWatchModifiers
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private static WatchEvent.Modifier[] instantiateWatchModifiers() {
if (JavaVersion.current().isJava9Compatible()) {
return new WatchEvent.Modifier[]{};
} else {
// use reflection to support older JVMs while supporting Java 9
WatchEvent.Modifier highSensitive = instantiateEnum("com.sun.nio.file.SensitivityWatchEventModifier", "HIGH");
if (FILE_TREE_WATCHING_SUPPORTED) {
WatchEvent.Modifier fileTree = instantiateEnum("com.sun.nio.file.ExtendedWatchEventModifier", "FILE_TREE");
return new WatchEvent.Modifier[]{fileTree, highSensitive};
} else {
return new WatchEvent.Modifier[]{highSensitive};
}
}
}
示例2: instantiateEnum
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
private static WatchEvent.Modifier instantiateEnum(String className, String enumName) {
try {
return (WatchEvent.Modifier) Enum.valueOf((Class<Enum>) Class.forName(className), enumName);
} catch (ClassNotFoundException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
示例3: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register(final Watchable folder,
final WatchEvent.Kind<?>[] events,
final WatchEvent.Modifier... modifiers)
throws IOException {
if(log.isInfoEnabled()) {
log.info(String.format("Register file %s for events %s", folder, Arrays.toString(events)));
}
final Pointer[] values = {
CFStringRef.toCFString(folder.toString()).getPointer()};
final MacOSXWatchKey key = new MacOSXWatchKey(folder, this, events);
final double latency = 1.0; // Latency in seconds
final Map<File, Long> timestamps = createLastModifiedMap(new File(folder.toString()));
final FSEvents.FSEventStreamCallback callback = new Callback(key, timestamps);
final FSEventStreamRef stream = library.FSEventStreamCreate(
Pointer.NULL, callback, Pointer.NULL,
library.CFArrayCreate(null, values, CFIndex.valueOf(1), null),
-1, latency,
kFSEventStreamCreateFlagNoDefer);
final CountDownLatch lock = new CountDownLatch(1);
final CFRunLoop loop = new CFRunLoop(lock, stream);
threadFactory.newThread(loop).start();
try {
lock.await();
}
catch(InterruptedException e) {
throw new IOException(String.format("Failure registering for events in %s", folder), e);
}
loops.put(key, loop);
callbacks.put(key, callback);
return key;
}
示例4: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register(final Watchable folder, final WatchEvent.Kind<?>[] events,
final WatchEvent.Modifier... modifiers) throws IOException {
if(null == monitor) {
monitor = FileSystems.getDefault().newWatchService();
}
final WatchKey key = folder.register(monitor, events, modifiers);
if(log.isInfoEnabled()) {
log.info(String.format("Registered for events for %s", key));
}
return key;
}
示例5: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
WatchKey register(Path path,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers)
throws IOException
{
// delegate to poller
return poller.register(path, events, modifiers);
}
示例6: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register( WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers )
{
if( watcher == null || events == null || modifiers == null ) {
throw new NullPointerException();
}
throw new UnsupportedOperationException();
}
示例7: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register(WatchService watcher,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers)
throws IOException {
if (watcher == null) {
throw new NullPointerException();
}
if (!(watcher instanceof AbstractWatchService)) {
throw new ProviderMismatchException();
}
return ((AbstractWatchService) watcher).register(this, Arrays.asList(events));
}
示例8: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events, WatchEvent.Modifier... modifiers) throws IOException {
throw new UnsupportedOperationException("Unexpected call!");
}
示例9: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
WatchKey register(Watchable folder,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers) throws IOException;
示例10: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register(final Watchable folder, final WatchEvent.Kind<?>[] events, final WatchEvent.Modifier... modifiers) throws IOException {
return null;
}
示例11: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
/**
* Register this internal option as a WatchEvent.Modifier.
*/
public void register(WatchEvent.Modifier option) {
registerInternal(option, null);
}
示例12: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
/**
* Register the given file with this watch service
*/
@Override
WatchKey register(final Path path,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers)
throws IOException
{
// check events - CCE will be thrown if there are invalid elements
final Set<WatchEvent.Kind<?>> eventSet = new HashSet<>(events.length);
for (WatchEvent.Kind<?> event: events) {
// standard events
if (event == StandardWatchEventKinds.ENTRY_CREATE ||
event == StandardWatchEventKinds.ENTRY_MODIFY ||
event == StandardWatchEventKinds.ENTRY_DELETE)
{
eventSet.add(event);
continue;
}
// OVERFLOW is ignored
if (event == StandardWatchEventKinds.OVERFLOW) {
continue;
}
// null/unsupported
if (event == null)
throw new NullPointerException("An element in event set is 'null'");
throw new UnsupportedOperationException(event.name());
}
if (eventSet.isEmpty())
throw new IllegalArgumentException("No events to register");
// Extended modifiers may be used to specify the sensitivity level
int sensitivity = 10;
if (modifiers.length > 0) {
for (WatchEvent.Modifier modifier: modifiers) {
if (modifier == null)
throw new NullPointerException();
if (ExtendedOptions.SENSITIVITY_HIGH.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_HIGH.parameter();
} else if (ExtendedOptions.SENSITIVITY_MEDIUM.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_MEDIUM.parameter();
} else if (ExtendedOptions.SENSITIVITY_LOW.matches(modifier)) {
sensitivity = ExtendedOptions.SENSITIVITY_LOW.parameter();
} else {
throw new UnsupportedOperationException("Modifier not supported");
}
}
}
// check if watch service is closed
if (!isOpen())
throw new ClosedWatchServiceException();
// registration is done in privileged block as it requires the
// attributes of the entries in the directory.
try {
int value = sensitivity;
return AccessController.doPrivileged(
new PrivilegedExceptionAction<PollingWatchKey>() {
@Override
public PollingWatchKey run() throws IOException {
return doPrivilegedRegister(path, eventSet, value);
}
});
} catch (PrivilegedActionException pae) {
Throwable cause = pae.getCause();
if (cause != null && cause instanceof IOException)
throw (IOException)cause;
throw new AssertionError(pae);
}
}
示例13: register
import java.nio.file.WatchEvent; //导入方法依赖的package包/类
@Override
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers) throws IOException {
throw new UnsupportedOperationException();
}