示例#1
0
 /**
  * Initialize the observer.
  *
  * @throws Exception if an error occurs
  */
 public void initialize() throws Exception {
   rootEntry.refresh(rootEntry.getFile());
   File[] files = listFiles(rootEntry.getFile());
   FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
   for (int i = 0; i < files.length; i++) {
     children[i] = createFileEntry(rootEntry, files[i]);
   }
   rootEntry.setChildren(children);
 }
示例#2
0
 /**
  * Fire directory/file change events to the registered listeners.
  *
  * @param entry The previous file system entry
  * @param file The current file
  */
 private void doMatch(FileEntry entry, File file) {
   if (entry.refresh(file)) {
     for (FileAlterationListener listener : listeners) {
       if (entry.isDirectory()) {
         listener.onDirectoryChange(file);
       } else {
         listener.onFileChange(file);
       }
     }
   }
 }
示例#3
0
 /**
  * Create a new file entry for the specified file.
  *
  * @param parent The parent file entry
  * @param file The file to create an entry for
  * @return A new file entry
  */
 private FileEntry createFileEntry(FileEntry parent, File file) {
   FileEntry entry = parent.newChildInstance(file);
   entry.refresh(file);
   File[] files = listFiles(file);
   FileEntry[] children = files.length > 0 ? new FileEntry[files.length] : FileEntry.EMPTY_ENTRIES;
   for (int i = 0; i < files.length; i++) {
     children[i] = createFileEntry(entry, files[i]);
   }
   entry.setChildren(children);
   return entry;
 }