Example usage for org.apache.commons.io FileUtils EMPTY_FILE_ARRAY

List of usage examples for org.apache.commons.io FileUtils EMPTY_FILE_ARRAY

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils EMPTY_FILE_ARRAY.

Prototype

File[] EMPTY_FILE_ARRAY

To view the source code for org.apache.commons.io FileUtils EMPTY_FILE_ARRAY.

Click Source Link

Document

An empty array of type File.

Usage

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

public void checkAndNotifyNow() {
    /* fire onStart() */
    for (final AdvancedFileAlterationListener listener : listeners) {
        listener.onStart(this);
    }/*from   w w w  . j  av a  2  s.  c o m*/

    /* fire directory/file events */
    final File rootFile = rootEntry.getFile();
    if (rootFile.exists()) {
        checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootFile), 0);
    } else if (rootEntry.isExists()) {
        try {
            // try to init once more
            init();
            if (rootEntry.getFile().exists()) {
                checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootEntry.getFile()), 0);
            } else {
                checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, 0);
            }
        } catch (Exception e) {
            Log_OC.d("AdvancedFileAlterationObserver", "Failed getting an observer to intialize " + e);
            checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, 0);
        }
    } // else didn't exist and still doesn't

    /* fire onStop() */
    for (final AdvancedFileAlterationListener listener : listeners) {
        listener.onStop(this);
    }
}

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

/**
 * Check whether the file and its children have been created, modified or deleted.
 *///from w  w w  . j ava  2 s  .  co  m
public void checkAndNotify() {

    /* fire onStart() */
    for (final AdvancedFileAlterationListener listener : listeners) {
        listener.onStart(this);
    }

    /* fire directory/file events */
    final File rootFile = rootEntry.getFile();
    if (rootFile.exists()) {
        checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootFile), DELAY_INVOCATION_MS);
    } else if (rootEntry.isExists()) {
        try {
            // try to init once more
            init();
            if (rootEntry.getFile().exists()) {
                checkAndNotify(rootEntry, rootEntry.getChildren(), listFiles(rootEntry.getFile()),
                        DELAY_INVOCATION_MS);
            } else {
                checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY,
                        DELAY_INVOCATION_MS);
            }
        } catch (Exception e) {
            Log_OC.d("AdvancedFileAlterationObserver", "Failed getting an observer to intialize " + e);
            checkAndNotify(rootEntry, rootEntry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, DELAY_INVOCATION_MS);
        }
    } // else didn't exist and still doesn't

    /* fire onStop() */
    for (final AdvancedFileAlterationListener listener : listeners) {
        listener.onStop(this);
    }
}

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  ww  w .  ja  v a 2  s .  com*/
 * @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);
    }
}

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

/**
 * List the contents of a directory//from www.  j av  a 2s  .  co m
 *
 * @param file The file to list the contents of
 * @return the directory contents or a zero length array if
 * the empty or the file is not a directory
 */
private File[] listFiles(final File file) {
    File[] children = null;
    if (file.isDirectory()) {
        children = fileFilter == null ? file.listFiles() : file.listFiles(fileFilter);
    }
    if (children == null) {
        children = FileUtils.EMPTY_FILE_ARRAY;
    }
    if (comparator != null && children.length > 1) {
        Arrays.sort(children, comparator);
    }
    return children;
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.IndexCopierTest.java

@Test
public void wrapForWriteWithoutIndexPath() throws Exception {
    Directory remote = new CloseSafeDir();

    IndexCopier copier = new IndexCopier(sameThreadExecutor(), getWorkDir());

    IndexDefinition defn = new IndexDefinition(root, builder.getNodeState());
    Directory dir = copier.wrapForWrite(defn, remote, false);

    byte[] t1 = writeFile(dir, "t1");

    dir.close();//  w ww.j av a  2  s. c  o  m

    readAndAssert(remote, "t1", t1);
    //Work dir must be empty post close
    assertArrayEquals(FileUtils.EMPTY_FILE_ARRAY, copier.getIndexWorkDir().listFiles());
}

From source file:org.codice.ddf.catalog.content.monitor.AsyncFileAlterationObserver.java

/**
 * Steps file by file comparing the snapshot state to the current state of the directory being
 * monitored.//from  w  w w.java2s.c om
 *
 * @param parent The parent directory (Wrapped in a AsyncFileEntry)
 * @param previous The list of all children of the parent directory (In sorted order)
 * @param files The list of current files (in sorted order)
 */
private void checkAndNotify(final AsyncFileEntry parent, final List<AsyncFileEntry> previous,
        @Nullable final File[] files, final AsyncFileAlterationListener listenerCopy) {
    //  If there was an IO error then just stop.
    if (files == null) {
        return;
    }

    int c = 0;
    for (final AsyncFileEntry entry : previous) {
        while (c < files.length && entry.compareToFile(files[c]) > 0) {
            doCreate(new AsyncFileEntry(parent, files[c]), listenerCopy);
            c++;
        }
        if (c < files.length && entry.compareToFile(files[c]) == 0) {
            doMatch(entry, listenerCopy);
            checkAndNotify(entry, entry.getChildren(), listFiles(files[c]), listenerCopy);
            c++;
        } else {
            //  Do Delete
            if (!entry.checkNetwork()) {
                //  The file may still exist but it's the network that's down.
                return;
            }
            checkAndNotify(entry, entry.getChildren(), FileUtils.EMPTY_FILE_ARRAY, listenerCopy);
            doDelete(entry, listenerCopy);
        }
    }
    for (; c < files.length; c++) {
        doCreate(new AsyncFileEntry(parent, files[c]), listenerCopy);
    }
}

From source file:org.codice.ddf.catalog.content.monitor.AsyncFileAlterationObserver.java

/**
 * Note: returns a new Array to avoid sync access exceptions
 *
 * @param file file to retrieve files from.
 * @return A new sorted File Array if {@code file} is a directory, an empty Array if the file is
 *     not a directory, and null if there is an error retrieving the children files.
 *//*  ww w .jav a2 s  . c om*/
private File[] listFiles(File file) {
    if (file.isDirectory()) {
        File[] temp = file.listFiles();
        if (temp != null) {
            Arrays.sort(temp);
            return temp;
        }
        LOGGER.info("There was a problem reading the files contained within [{}]", file.getName());
        return null;
    }
    return FileUtils.EMPTY_FILE_ARRAY;
}