Example usage for org.apache.commons.io.monitor FileEntry getChildren

List of usage examples for org.apache.commons.io.monitor FileEntry getChildren

Introduction

In this page you can find the example usage for org.apache.commons.io.monitor FileEntry getChildren.

Prototype

public FileEntry[] getChildren() 

Source Link

Document

Return the directory's files.

Usage

From source file:com.owncloud.android.services.observer.AdvancedFileAlterationObserver.java

/**
 * Fire directory/file created events to the registered listeners.
 *
 * @param entry The file entry//from   w w w  . ja va 2s  . c  o  m
 */
private void doCreate(final FileEntry entry, int delay) {
    for (final AdvancedFileAlterationListener listener : listeners) {
        if (entry.isDirectory()) {
            listener.onDirectoryCreate(entry.getFile());
        } else {
            listener.onFileCreate(entry.getFile(), delay);
        }
    }
    final FileEntry[] children = entry.getChildren();
    for (final FileEntry aChildren : children) {
        doCreate(aChildren, delay);
    }
}

From source file:com.owncloud.android.services.observer.AdvancedFileAlterationObserver.java

/**
 * Compare two file lists for files which have been created, modified or deleted.
 *
 * @param parent   The parent entry/*from  w  w  w  .  j  av  a  2s .c o  m*/
 * @param previous The original list of files
 * @param files    The current list of files
 */
private void checkAndNotify(final FileEntry parent, final FileEntry[] previous, final File[] files, int delay) {
    if (files != null && files.length > 0) {
        int c = 0;
        final FileEntry[] current = files.length > 0 ? new FileEntry[files.length] : EMPTY_ENTRIES;
        for (final FileEntry entry : previous) {
            while (c < files.length && comparator.compare(entry.getFile(), files[c]) > 0) {
                current[c] = createFileEntry(parent, files[c]);
                doCreate(current[c], delay);
                c++;
            }
            if (c < files.length && comparator.compare(entry.getFile(), files[c]) == 0) {
                doMatch(entry, files[c], delay);
                checkAndNotify(entry, entry.getChildren(), listFiles(files[c]), delay);
                current[c] = entry;
                c++;
            } else {
                checkAndNotify(entry, entry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, delay);
                doDelete(entry);
            }
        }
        for (; c < files.length; c++) {
            current[c] = createFileEntry(parent, files[c]);
            doCreate(current[c], delay);
        }
        parent.setChildren(current);
    }
}