本文整理匯總了Java中java.nio.file.StandardWatchEventKinds.ENTRY_CREATE屬性的典型用法代碼示例。如果您正苦於以下問題:Java StandardWatchEventKinds.ENTRY_CREATE屬性的具體用法?Java StandardWatchEventKinds.ENTRY_CREATE怎麽用?Java StandardWatchEventKinds.ENTRY_CREATE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.nio.file.StandardWatchEventKinds
的用法示例。
在下文中一共展示了StandardWatchEventKinds.ENTRY_CREATE屬性的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: handleEvent
private void handleEvent(final WatchKeyHolder watchKeys, final WatchKey key) throws IOException {
for (final WatchEvent<?> event : key.pollEvents()) {
if (event.kind() == StandardWatchEventKinds.OVERFLOW) {
continue;
}
final WatchEvent<Path> watchEvent = cast(event);
Path path = watchKeys.get(key);
if (path == null) {
continue;
}
path = path.resolve(watchEvent.context());
if (Files.isDirectory(path, LinkOption.NOFOLLOW_LINKS)) {
if (event.kind() == StandardWatchEventKinds.ENTRY_CREATE) {
watchKeys.register(path);
}
} else {
// Dispatch
FileEvent fe = toEvent(watchEvent, path);
if (fe != null) {
this.eventBus.post(fe);
}
}
}
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
}
示例9: 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;
}
示例10: 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");
}
}
示例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: handleEvent
public void handleEvent ( final Path watchable, final WatchEvent<?> event ) throws IOException
{
final Path path = (Path)event.context ();
logger.debug ( "Change {} for base: {} on {}", new Object[] { event.kind (), watchable, path } );
if ( watchable.endsWith ( "native" ) && path.toString ().equals ( "settings.xml" ) )
{
if ( event.kind () != StandardWatchEventKinds.ENTRY_DELETE )
{
check ();
}
else
{
storageRemoved ();
}
}
else
{
if ( path.toString ().equals ( "settings.xml" ) )
{
if ( event.kind () == StandardWatchEventKinds.ENTRY_CREATE )
{
this.nativeKey = new File ( watchable.toFile (), "native" ).toPath ().register ( this.watcher, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE );
}
}
else if ( path.toString ().endsWith ( ".hds" ) )
{
if ( this.id != null )
{
this.storageManager.fileChanged ( this.path.toFile (), this.id, path.toFile () );
}
}
}
}
示例14: processFileSystemChanges
private void processFileSystemChanges(final Path watchedDirectory, final WatchKey key) {
final ChangesProcessor processor = getChangesProcessorOrNull(watchedDirectory);
if (processor == null) {
log.warn("Ignoring change in {}: no change processor found", watchedDirectory);
return;
}
processor.start();
for (WatchEvent<?> event : key.pollEvents()) {
final WatchEvent.Kind<?> kind = event.kind();
final Object eventContext = event.context();
log.debug("Processing {} {} in {}", kind.name(), eventContext, watchedDirectory);
if (kind == StandardWatchEventKinds.OVERFLOW) {
log.info("event overflow in {}. Reimporting and registering watchedDirectory '{}' to avoid half synced state",
watchedDirectory, watchedDirectory);
if (Files.exists(watchedDirectory)) {
registerQuietly(watchedDirectory);
}
processor.processChange(kind, watchedDirectory, true);
} else {
final Path changedRelPath = (Path) eventContext;
final Path changedAbsPath = watchedDirectory.resolve(changedRelPath);
final boolean isDirectory = isDirectory(changedAbsPath, kind);
if (watchedFiles.matches(changedAbsPath, isDirectory)) {
if (isDirectory && kind == StandardWatchEventKinds.ENTRY_CREATE) {
registerQuietly(changedAbsPath);
}
processor.processChange(kind, changedAbsPath, isDirectory);
} else {
log.debug("Skipping excluded path {}", changedAbsPath);
}
}
}
}
示例15: 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.");
}
}
}