/** * Fire directory/file change events to the registered listeners. * * @param entry The previous file system entry * @param file The current file */ private void doMatch(FileInfo entry, File file) { if (entry.refresh(file)) { for (FileChangeListener listener : listeners) { if (entry.isDirectory()) { listener.onDirectoryChange(this,file); } else { listener.onFileChange(this,file); } } } }
/** * 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 FileInfo createFileEntry(FileInfo parent, File file) { FileInfo entry = parent.newChildInstance(file); entry.refresh(file); File[] files = listFiles(file); FileInfo[] children = files.length > 0 ? new FileInfo[files.length] : FileInfo.EMPTY_FILE_INFOS; for (int i = 0; i < files.length; i++) { children[i] = createFileEntry(entry, files[i]); } entry.setChildren(children); return entry; }
/** * Initialize the observer. * * @throws Exception if an error occurs */ protected synchronized void initialize() { rootEntry.refresh(rootEntry.getFile()); File[] files = listFiles(rootEntry.getFile()); FileInfo[] children = files.length > 0 ? new FileInfo[files.length] : FileInfo.EMPTY_FILE_INFOS; for (int i = 0; i < files.length; i++) { children[i] = createFileEntry(rootEntry, files[i]); } rootEntry.setChildren(children); _initialized = true; }