Search in sources :

Example 1 with SensitivityWatchEventModifier

use of com.sun.nio.file.SensitivityWatchEventModifier in project jdk8u_jdk by JetBrains.

the class PollingWatchService method register.

/**
     * 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<WatchEvent.Kind<?>>(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");
    // A modifier may be used to specify the sensitivity level
    SensitivityWatchEventModifier sensivity = SensitivityWatchEventModifier.MEDIUM;
    if (modifiers.length > 0) {
        for (WatchEvent.Modifier modifier : modifiers) {
            if (modifier == null)
                throw new NullPointerException();
            if (modifier instanceof SensitivityWatchEventModifier) {
                sensivity = (SensitivityWatchEventModifier) modifier;
                continue;
            }
            throw new UnsupportedOperationException("Modifier not supported");
        }
    }
    // check if watch service is closed
    if (!isOpen())
        throw new ClosedWatchServiceException();
    // attributes of the entries in the directory.
    try {
        final SensitivityWatchEventModifier s = sensivity;
        return AccessController.doPrivileged(new PrivilegedExceptionAction<PollingWatchKey>() {

            @Override
            public PollingWatchKey run() throws IOException {
                return doPrivilegedRegister(path, eventSet, s);
            }
        });
    } catch (PrivilegedActionException pae) {
        Throwable cause = pae.getCause();
        if (cause != null && cause instanceof IOException)
            throw (IOException) cause;
        throw new AssertionError(pae);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) SensitivityWatchEventModifier(com.sun.nio.file.SensitivityWatchEventModifier)

Example 2 with SensitivityWatchEventModifier

use of com.sun.nio.file.SensitivityWatchEventModifier in project jdk8u_jdk by JetBrains.

the class SensitivityModifier method register.

static void register(Path[] dirs, WatchService watcher) throws IOException {
    SensitivityWatchEventModifier[] sensitivtives = SensitivityWatchEventModifier.values();
    for (int i = 0; i < dirs.length; i++) {
        SensitivityWatchEventModifier sensivity = sensitivtives[rand.nextInt(sensitivtives.length)];
        Path dir = dirs[i];
        dir.register(watcher, new WatchEvent.Kind<?>[] { ENTRY_MODIFY }, sensivity);
    }
}
Also used : SensitivityWatchEventModifier(com.sun.nio.file.SensitivityWatchEventModifier)

Aggregations

SensitivityWatchEventModifier (com.sun.nio.file.SensitivityWatchEventModifier)2 IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1