本文整理汇总了Java中com.sun.nio.file.SensitivityWatchEventModifier类的典型用法代码示例。如果您正苦于以下问题:Java SensitivityWatchEventModifier类的具体用法?Java SensitivityWatchEventModifier怎么用?Java SensitivityWatchEventModifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SensitivityWatchEventModifier类属于com.sun.nio.file包,在下文中一共展示了SensitivityWatchEventModifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addProblem
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public ProblemSync addProblem(Problem newProblem) throws IOException {
ProblemSync newProblemSync = new ProblemSync(workspaceDirectory, newProblem);
String directory = newProblemSync.getDirectory();
for (ProblemSync problemSync : problemSyncs) {
if (problemSync.getDirectory().equals(directory)) {
throw new IOException("Problem with such directory already exists: " + problemSync.getDirectory());
}
}
newProblemSync.initialize();
synchronized (workspaceWatcher) {
problemSyncs.add(newProblemSync);
WatchKey key = Paths.get(directory).register(workspaceWatcher,
new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY},
SensitivityWatchEventModifier.HIGH);
watchKeys.add(key);
}
return newProblemSync;
}
示例2: JavaWatchObserver
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public JavaWatchObserver(File fileToWatch) throws IOException {
if (fileToWatch == null || !fileToWatch.exists()) {
throw new RuntimeException("fileToWatch must not be null and must already exist.");
}
this.fileToWatch = fileToWatch;
lastModified = fileToWatch.lastModified();
length = fileToWatch.length();
watchService = FileSystems.getDefault().newWatchService();
// Note that poll depends on us only registering events that are of type path
if (OsData.getOsType() != OsData.OsType.MAC) {
key = fileToWatch.getParentFile().toPath().register(watchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY);
} else {
// Unfortunately the default watch service on Mac is broken, it uses a separate thread and really slow polling to detect file changes
// rather than integrating with the OS. There is a hack to make it poll faster which we can use for now. See
// http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
key = fileToWatch.getParentFile().toPath().register(watchService, new WatchEvent.Kind[]
{StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH);
}
}
示例3: watch
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void watch(
final Path dir,
final Kind<Path>[] kinds) throws IOException {
WatchService service = FileSystems.getDefault().newWatchService();
// Rationale for SensitivityWatchEventModifier.HIGH:
// http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
dir.register(
service,
kinds,
SensitivityWatchEventModifier.HIGH);
m_logger.info("Watching directory: {}", dir);
m_watcher = new WatcherThread(service, m_eventBus);
m_watcher.start(); // Start watcher thread
}
示例4: observePathSet
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void observePathSet(PathSet pathSet, Listener listener) throws IOException {
Preconditions.checkNotNull(listener);
Preconditions.checkNotNull(pathSet);
final Path rootPath = pathSet.getRootPath();
log.debug("Watching directory {} for changes matching: {}", rootPath, pathSet);
final WatchKey key = rootPath.register(watcher, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY},
SensitivityWatchEventModifier.HIGH);
// Synchronize on keys to make the two operations atomic.
synchronized (keys) {
keys.putIfAbsent(key, Sets.<WatchPath>newConcurrentHashSet());
keys.get(key).add(new WatchPath(pathSet, listener));
}
}
示例5: register
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
/**
* Register the given directory with the WatchService
*/
private void register(Path dir) throws IOException {
WatchKey key = dir.register(watcher, new WatchEvent.Kind[]{
ENTRY_CREATE,
ENTRY_DELETE,
ENTRY_MODIFY,
}, SensitivityWatchEventModifier.HIGH);
Path prev = keys.get(key);
if (prev == null) {
System.out.format("register: %s\n", dir);
} else {
if (!dir.equals(prev)) {
System.out.format("update: %s -> %s\n", prev, dir);
}
}
keys.put(key, dir);
}
示例6: addWatch
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void addWatch(final String directoryToWatch) throws IOException {
final Path path = Paths.get(directoryToWatch);
if (path == null) {
throw new IllegalArgumentException("Directory " + directoryToWatch + " not found");
}
// Handlers
mFileProcessor.addHandler(PathEventProcessor.PathEvent.EVENT_CREATE, new NewJpegFileHandler(path));
final WatchService watcher = path.getFileSystem().newWatchService();
final QueueReader queueReader = new QueueReader(watcher);
final Thread thread = new Thread(queueReader, "FileWatcher" + (int) (Math.random() * 10000));
// Register operations
path.register(watcher, new WatchEvent.Kind[]{StandardWatchEventKinds.ENTRY_CREATE}, SensitivityWatchEventModifier.HIGH);
mThreadList.add(thread);
}
示例7: observePathSet
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void observePathSet(PathSet pathSet, Listener listener) throws IOException {
Preconditions.checkNotNull(listener);
Preconditions.checkNotNull(pathSet);
final Path rootPath = pathSet.getRootPath();
log.debug("Watching directory {} for changes matching: {}", rootPath, pathSet);
final WatchKey key = rootPath.register(watcher, new WatchEvent.Kind[]{ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY},
SensitivityWatchEventModifier.HIGH);
// Synchronize on keys to make the two operations atomic.
synchronized (keys) {
keys.putIfAbsent(key, Sets.newConcurrentHashSet());
keys.get(key).add(new WatchPath(pathSet, listener));
}
}
示例8: walkFiles
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public void walkFiles( File folder, Kind[] events) throws IOException {
Queue<File> dirsq = new LinkedList<>();
dirsq.add(folder);
while (!dirsq.isEmpty()) {
for (File f : dirsq.poll().listFiles()) {
if (f.isDirectory()) {
dirsq.add(f);
f.toPath().register(folderWatcher, events, SensitivityWatchEventModifier.HIGH);
}
}
}
}
示例9: doPrivilegedRegister
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
private PollingWatchKey doPrivilegedRegister(Path path,
Set<? extends WatchEvent.Kind<?>> events,
SensitivityWatchEventModifier sensivity)
throws IOException
{
// check file is a directory and get its file key if possible
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
if (!attrs.isDirectory()) {
throw new NotDirectoryException(path.toString());
}
Object fileKey = attrs.fileKey();
if (fileKey == null)
throw new AssertionError("File keys must be supported");
// grab close lock to ensure that watch service cannot be closed
synchronized (closeLock()) {
if (!isOpen())
throw new ClosedWatchServiceException();
PollingWatchKey watchKey;
synchronized (map) {
watchKey = map.get(fileKey);
if (watchKey == null) {
// new registration
watchKey = new PollingWatchKey(path, this, fileKey);
map.put(fileKey, watchKey);
} else {
// update to existing registration
watchKey.disable();
}
}
watchKey.enable(events, sensivity.sensitivityValueInSeconds());
return watchKey;
}
}
示例10: register
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
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);
}
}
示例11: registerWatcherForFolder
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
private void registerWatcherForFolder(IWatchEventHandler handler, String folder) {
Path itemsDir = FileSystems.getDefault().getPath(folder);
try {
if (new File(itemsDir.toString()).isDirectory()) {
itemsDir.register(watcher, new WatchEvent.Kind[]{
StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE
}, SensitivityWatchEventModifier.HIGH);
Log.fine("Folder registered with watcher {0}", folder);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例12: register
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
private void register(Path dir) throws IOException {
WatchKey key = dir.register(watcher, new WatchEvent.Kind[]{
StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY
}, SensitivityWatchEventModifier.HIGH);
keys.put(key, dir);
}
示例13: register
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
/**
* Register the given directory with the WatchService
*/
private void register(Path dir) throws IOException {
// WatchKey key = dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
// following works better on Mac OS X, which as of Java7 does not use native watchservice. OS X still slow relative to PC. See:
WatchKey key;
// http://stackoverflow.com/questions/9588737/is-java-7-watchservice-slow-for-anyone-else
try { // Windows (only) supports built-in recursive monitoring
key = dir.register(watcher, new WatchEvent.Kind[]{ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE}, SensitivityWatchEventModifier.HIGH, ExtendedWatchEventModifier.FILE_TREE);
} catch(Exception e) {
key = dir.register(watcher, new WatchEvent.Kind[]{ENTRY_MODIFY, ENTRY_CREATE, ENTRY_DELETE}, SensitivityWatchEventModifier.HIGH);
}
keys.put(key, dir);
}
示例14: WatcherPinListener
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
public WatcherPinListener(Pin pin) throws IOException {
super();
this.pin = pin;
service = FileSystems.getDefault().newWatchService();
try {
key = pin.getPath().toPath().getParent().register(service, new WatchEvent.Kind[]{ENTRY_MODIFY}, SensitivityWatchEventModifier.HIGH);
} catch (IOException e) {
Logger.error(TAG, "Error at registering pin %s", e, pin.getCode());
throw e;
}
}
示例15: WatchThread
import com.sun.nio.file.SensitivityWatchEventModifier; //导入依赖的package包/类
/**
* @param dir the directory to watch
* @throws IOException if there's a problem watching the directory
*/
public WatchThread(Path dir) throws IOException {
setName(getClass().getSimpleName());
setDaemon(true);
this.dir = dir;
watcher = FileSystems.getDefault().newWatchService();
dir.register(watcher, new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY }, SensitivityWatchEventModifier.HIGH);
}