本文整理匯總了Java中java.nio.file.StandardWatchEventKinds.ENTRY_MODIFY屬性的典型用法代碼示例。如果您正苦於以下問題:Java StandardWatchEventKinds.ENTRY_MODIFY屬性的具體用法?Java StandardWatchEventKinds.ENTRY_MODIFY怎麽用?Java StandardWatchEventKinds.ENTRY_MODIFY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.nio.file.StandardWatchEventKinds
的用法示例。
在下文中一共展示了StandardWatchEventKinds.ENTRY_MODIFY屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleEvent
@SuppressWarnings ( "unchecked" )
private void handleEvent ( final WatchEvent<?> event )
{
final Kind<?> kind = event.kind ();
if ( kind == StandardWatchEventKinds.OVERFLOW )
{
// FIXME: full rescan
return;
}
final Path path = this.path.resolve ( ( (WatchEvent<Path>)event ).context () );
if ( kind == StandardWatchEventKinds.ENTRY_CREATE )
{
this.listener.event ( path, Event.ADDED );
}
else if ( kind == StandardWatchEventKinds.ENTRY_DELETE )
{
this.listener.event ( path, Event.REMOVED );
}
else if ( kind == StandardWatchEventKinds.ENTRY_MODIFY )
{
this.listener.event ( path, Event.MODIFIED );
}
}
示例2: MacOSXWatchKey
public MacOSXWatchKey(final Watchable file, final FSEventWatchService service, final WatchEvent.Kind<?>[] events) {
super(service);
this.file = file;
boolean reportCreateEvents = false;
boolean reportModifyEvents = false;
boolean reportDeleteEvents = false;
for(WatchEvent.Kind<?> event : events) {
if(event == StandardWatchEventKinds.ENTRY_CREATE) {
reportCreateEvents = true;
}
else if(event == StandardWatchEventKinds.ENTRY_MODIFY) {
reportModifyEvents = true;
}
else if(event == StandardWatchEventKinds.ENTRY_DELETE) {
reportDeleteEvents = true;
}
}
this.reportCreateEvents = reportCreateEvents;
this.reportDeleteEvents = reportDeleteEvents;
this.reportModifyEvents = reportModifyEvents;
}
示例3: translateActionToEvent
private WatchEvent.Kind<?> translateActionToEvent(int action) {
switch (action) {
case FILE_ACTION_MODIFIED :
return StandardWatchEventKinds.ENTRY_MODIFY;
case FILE_ACTION_ADDED :
case FILE_ACTION_RENAMED_NEW_NAME :
return StandardWatchEventKinds.ENTRY_CREATE;
case FILE_ACTION_REMOVED :
case FILE_ACTION_RENAMED_OLD_NAME :
return StandardWatchEventKinds.ENTRY_DELETE;
default :
return null; // action not recognized
}
}
示例4: processWatchEvent
/**
* Handles a watchevent, it currently only handles the DELETE and MODIFY - create isn't handled
* as when you create a new file you get two events - one of the create and one for the modify,
* therefore it can be safely handled in the modify only.
*
* If the delete corresponds to a adapter loaded - it deregisterWithAdapterManager it with the
* adatperManager If the modify is new / modified it passes it to the load method that handles
* re-registering existing adapters
*
* @param event
*/
public void processWatchEvent(final WatchEvent<?> event) {
synchronized (propertiesToAdapter) {
if (LOG.isInfoEnabled()) {
LOG.info("Logging watch event:" + event.kind() + ": " + event.context());
}
// check it is ended with .properties
if (isPropertyFile(event)) {
String path = ((Path) event.context()).toString();
Adapter adapter = propertiesToAdapter.get(path);
// if we have already seen this then deregister it
if (adapter != null) {
removeAdapter(path, adapter);
}
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE
|| event.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
File file = new File(getPathToWatch().toString(), ((Path) event.context()).toString());
load(file);
}
}
}
}
示例5: MacOSXWatchKey
public MacOSXWatchKey(AbstractWatchService macOSXWatchService, Iterable<? extends WatchEvent.Kind<?>> events) {
super(macOSXWatchService, null, events);
boolean reportCreateEvents = false;
boolean reportModifyEvents = false;
boolean reportDeleteEvents = false;
for (WatchEvent.Kind<?> event : events) {
if (event == StandardWatchEventKinds.ENTRY_CREATE) {
reportCreateEvents = true;
} else if (event == StandardWatchEventKinds.ENTRY_MODIFY) {
reportModifyEvents = true;
} else if (event == StandardWatchEventKinds.ENTRY_DELETE) {
reportDeleteEvents = true;
}
}
this.reportCreateEvents = reportCreateEvents;
this.reportDeleteEvents = reportDeleteEvents;
this.reportModifyEvents = reportModifyEvents;
}
示例6: filesFromEvents
private Set<File> filesFromEvents() throws InterruptedException {
WatchKey key = watcher.take();
Set<File> files = new LinkedHashSet<File>();
if (key != null && key.isValid())
{
for (WatchEvent<?> event : key.pollEvents())
{
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE || event.kind() == StandardWatchEventKinds.ENTRY_MODIFY)
{
Path item = (Path) event.context();
File file = new File(((Path) key.watchable()).toAbsolutePath() + File.separator + item.getFileName());
if (log.isDebugEnabled()) {
log.debug("Watch Event: " + event.kind() + ": " + file);
}
if(isJarFile(file))
{
files.add(file);
}
else
log.warn("[JAR Loader] Ignoring file "+file);
}
}
key.reset();
}
return files;
}
示例7: DirEvent
public DirEvent(final JsonObject json) {
m_base = Paths.get(json.getString(FIELD_BASE));
m_file = Paths.get(json.getString(FIELD_FILE));
m_hash = json.getInteger(FIELD_HASH);
m_modtm = FileTime.fromMillis(json.getLong(FIELD_MODTM));
switch (json.getString(FIELD_KIND)) {
case "ENTRY_CREATE":
m_kind = StandardWatchEventKinds.ENTRY_CREATE;
break;
case "ENTRY_MODIFY":
m_kind = StandardWatchEventKinds.ENTRY_MODIFY;
break;
case "ENTRY_DELETE":
m_kind = StandardWatchEventKinds.ENTRY_DELETE;
break;
default:
m_kind = null;
break;
}
}
示例8: MacOSXWatchKey
public MacOSXWatchKey(Path path, AbstractWatchService macOSXWatchService, WatchEvent.Kind<?>[] events) {
super(macOSXWatchService);
this.path = path;
boolean reportCreateEvents = false;
boolean reportModifyEvents = false;
boolean reportDeleteEvents = false;
for (WatchEvent.Kind<?> event : events) {
if (event == StandardWatchEventKinds.ENTRY_CREATE) {
reportCreateEvents = true;
} else if (event == StandardWatchEventKinds.ENTRY_MODIFY) {
reportModifyEvents = true;
} else if (event == StandardWatchEventKinds.ENTRY_DELETE) {
reportDeleteEvents = true;
}
}
this.reportCreateEvents = reportCreateEvents;
this.reportDeleteEvents = reportDeleteEvents;
this.reportModifyEvents = reportModifyEvents;
}
示例9: processSendListEvt
private void processSendListEvt(WatchEvent.Kind<?> kind) throws IOException {
if ((kind == StandardWatchEventKinds.ENTRY_CREATE)
|| (kind == StandardWatchEventKinds.ENTRY_MODIFY)) {
if (!isExcelLocked && allowUpdate) {
// update
(new UpdateTable()).execute();
allowUpdate = false;
retry = false;
// update table
log.append("list update."+Constants.NEWLINE);
} else {
// set retry
retry = true;
log.append("excel file is locked. wait..." + Constants.NEWLINE);
}
} else {
// the DELETE evt
System.out.println("The sync excel has been deleted");
}
}
示例10: notifyChange
public void notifyChange(EphemeralFsPath path) throws NoSuchFileException {
ResolvedPath resolvedPath;
try {
resolvedPath = ResolvedPath.resolve(path.getParent(), false);
} catch (FileSystemException e) {
//we can't resolve the path
//ignore and skip notifying
return;
}
if(!resolvedPath.hasTarget()) {
return;
}
if(resolvedPath.getTarget().isDir() &&
resolvedPath.getTarget().getName(this) != null) {
EphemeralFsWatchEvent event = new EphemeralFsWatchEvent(
path,
StandardWatchEventKinds.ENTRY_MODIFY);
fs.getWatchRegistry().hearChange(resolvedPath.getTarget(), event);
}
}
示例11: _registerDir
/**
* Register the given directory with the WatchService
*
* @param aDir
* Directory to be watched. May not be <code>null</code>.
*/
private void _registerDir (@Nonnull final Path aDir) throws IOException
{
if (s_aLogger.isDebugEnabled ())
s_aLogger.debug ("Register directory " +
aDir +
(m_bRecursive && !m_bRegisterRecursiveManually ? " (recursively)" : ""));
final WatchEvent.Kind <?> [] aKinds = new WatchEvent.Kind <?> [] { StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_DELETE,
StandardWatchEventKinds.ENTRY_MODIFY };
// throws exception when using with modifiers even if null
final WatchKey aKey = m_aModifiers != null ? aDir.register (m_aWatcher, aKinds, m_aModifiers)
: aDir.register (m_aWatcher, aKinds);
m_aKeys.put (aKey, aDir);
}
示例12: main
public static void main(String[] args) {
DirectoryWatcher dictionaryWatcher = new DirectoryWatcher(new WatcherCallback(){
private long lastExecute = System.currentTimeMillis();
@Override
public void execute(WatchEvent.Kind<?> kind, String path) {
if(System.currentTimeMillis() - lastExecute > 1000){
lastExecute = System.currentTimeMillis();
//刷新詞典
System.out.println("事件:"+kind.name()+" ,路徑:"+path);
}
}
}, StandardWatchEventKinds.ENTRY_CREATE,
StandardWatchEventKinds.ENTRY_MODIFY,
StandardWatchEventKinds.ENTRY_DELETE);
//監控DIC目錄及其所有子目錄的子目錄...遞歸
dictionaryWatcher.watchDirectoryTree("d:/DIC");
//隻監控DIC2目錄
dictionaryWatcher.watchDirectory("d:/DIC2");
}
示例13: processChange
void processChange(final WatchEvent.Kind<?> kind, final Path changedAbsPath, final boolean isDirectory) {
if (isDirectory) {
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
listener.directoryCreated(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
listener.directoryModified(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
listener.directoryDeleted(changedAbsPath);
} else if (kind == StandardWatchEventKinds.OVERFLOW) {
if (Files.exists(changedAbsPath)) {
log.info("Having an event overflow for '{}'. Entire directory '{}' will be recreated",
changedAbsPath, changedAbsPath);
listener.directoryCreated(changedAbsPath);
} else {
log.info("Having an event overflow for non existing directory '{}'. Directory will be removed",
changedAbsPath, changedAbsPath);
listener.directoryDeleted(changedAbsPath);
}
}
} else {
if (kind == StandardWatchEventKinds.ENTRY_CREATE) {
listener.fileCreated(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
listener.fileModified(changedAbsPath);
} else if (kind == StandardWatchEventKinds.ENTRY_DELETE) {
listener.fileDeleted(changedAbsPath);
} else if (kind == StandardWatchEventKinds.OVERFLOW) {
throw new IllegalStateException("Only a directory should even possibly overflow in events, for example" +
" by saving 1000 new files in one go.");
}
}
}
示例14: testLoadMissingFileNotInClasspath
/**
* Test what happens when the jarfile link is missing/empty
*
* @throws DuplicateAdapterException
* @throws IOException
*/
@Test
public void testLoadMissingFileNotInClasspath() throws DuplicateAdapterException, IOException {
Path newdir = Paths.get(monitorDir);
AdapterManager adapterManager = mock(AdapterManager.class);
AdapterLoader adapterLoader = new AdapterLoader(newdir.toAbsolutePath().toString());
adapterLoader.adapterManager = adapterManager;
// copy the config into the monitored DIR
Path source = Paths.get("src/test/resources/adapterConfigs/noAdapter.properties-example");
Files.copy(source, newdir.resolve("noAdapter.properties"));
WatchEvent<Path> event = new WatchEvent<Path>() {
@Override
public java.nio.file.WatchEvent.Kind<Path> kind() {
return StandardWatchEventKinds.ENTRY_MODIFY;
}
@Override
public int count() {
return 1;
}
@Override
public Path context() {
return Paths.get("noAdapter.properties");
}
};
adapterLoader.processWatchEvent(event);
// verify that no adapters are registered
Adapter adapter = adapterLoader.getAdapter("noAdapter.properties");
Assert.assertNull(adapter);
}
示例15: monitor
private void monitor(Path path) throws Exception{
watchService = FileSystems.getDefault().newWatchService();
registerTree(path);
while(running){
WatchKey watchKey = watchService.take();
List<WatchEvent<?>> events = watchKey.pollEvents();
if(events != null){
for(WatchEvent<?> e : events){
//事件處理
final WatchEvent<Path> watchEventPath = (WatchEvent<Path>)e;
final Path filename = watchEventPath.context();
final Path directory_path = directories.get(watchKey);
final Path child = directory_path.resolve(filename);
boolean isChildDirectory = Files.isDirectory(child, LinkOption.NOFOLLOW_LINKS);
if(e.kind() == StandardWatchEventKinds.ENTRY_CREATE){
if(isChildDirectory){
registerTree(child);
}else{
updateSqlFile(child.toFile(),false);
}
logger.info("新增文件:"+child.toAbsolutePath());
}else if(e.kind() == StandardWatchEventKinds.ENTRY_MODIFY){
boolean isExsist = child.toFile().exists();
if(isExsist && !isChildDirectory){
updateSqlFile(child.toFile(),false);
logger.info("更新sql文件:"+child.toAbsolutePath());
}
}else if(e.kind() == StandardWatchEventKinds.ENTRY_DELETE){
updateSqlFile(child.toFile(),true);
logger.info("刪除文件:"+child.toAbsolutePath());
}
}
}
if(!watchKey.reset()){
Path pth = directories.remove(watchKey);
watchKey.cancel();
logger.error("移除sql文件目錄"+pth.toString()+"監控服務");
if(directories.isEmpty()){
break;
}
}
}
running = false;
watchService.close();
}