Example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

List of usage examples for org.apache.commons.io.filefilter TrueFileFilter INSTANCE

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Prototype

IOFileFilter INSTANCE

To view the source code for org.apache.commons.io.filefilter TrueFileFilter INSTANCE.

Click Source Link

Document

Singleton instance of true filter.

Usage

From source file:org.omnaest.utils.store.NestedDirectoryToByteArrayContainerListAdapter.java

private Collection<File> determineFileCollection() {
    final IOFileFilter fileFilter = new NameFileFilter(new String[] { "0.dat", "1.dat", "2.dat", "3.dat",
            "4.dat", "5.dat", "6.dat", "7.dat", "8.dat", "9.dat" });
    Collection<File> listFiles = FileUtils.listFiles(this.getBaseDirectory(), fileFilter,
            TrueFileFilter.INSTANCE);
    return listFiles;
}

From source file:org.onexus.data.loader.file.internal.FileCallable.java

private List<URL> getUrls(Plugin plugin, Data data) {

    String location = plugin.getParameter("location");
    String mirror = plugin.getParameter("mirror");
    String basePath = data.getLoader().getParameter("base-path");

    if (basePath == null) {
        basePath = "";
    }//from   w  ww.j  av a 2 s.  c  o m

    if (!basePath.isEmpty() && !basePath.endsWith(File.separator)) {
        basePath = basePath + File.separator;
    }

    List<String> paths = data.getLoader().getParameterList("path");

    List<URL> urls = new ArrayList<URL>();

    for (String templatePath : paths) {
        String path = templatePath;
        String fileName = FilenameUtils.getName(path);

        // Check if it is a wildcard filter
        if (path.contains("*") || path.contains("?")) {

            // Is recursive?
            IOFileFilter dirFilter = null;
            if (path.contains("**/")) {
                dirFilter = TrueFileFilter.INSTANCE;
                path = path.replace("**/", "");
            }

            String sourceContainer = location + File.separator + basePath
                    + FilenameUtils.getFullPathNoEndSeparator(path);
            File sourceFile = new File(sourceContainer);

            for (File file : (Collection<File>) FileUtils.listFiles(sourceFile,
                    new WildcardFileFilter(fileName), dirFilter)) {
                try {
                    urls.add(file.toURI().toURL());
                } catch (MalformedURLException e) {
                    throw new RuntimeException(e);
                }
            }

        } else {
            String sourcePath = location + File.separator + basePath + path;
            File sourceFile = new File(sourcePath);

            if (sourceFile.exists()) {
                try {
                    urls.add(sourceFile.toURI().toURL());
                } catch (MalformedURLException e) {
                    throw new RuntimeException(e);
                }
            } else {

                // Try mirror
                if (mirror != null) {

                    String remoteFile = mirror + '/' + path;

                    try {
                        URL url = new URL(remoteFile);
                        urls.add(url);
                    } catch (MalformedURLException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }

    return urls;
}

From source file:org.openmrs.module.owa.activator.OwaActivator.java

/**
 * @see ModuleActivator#contextRefreshed()
 *//*  ww  w  .  java 2  s.  c  o m*/
@Override
public void contextRefreshed() {
    /**
     * Used to move the files from omod webapp resources to owa folder when omod webapps contain
     * manifest.webapp
     */
    String owaAppFolderPath = Context.getAdministrationService()
            .getGlobalProperty(AppManager.KEY_APP_FOLDER_PATH);
    if (null == owaAppFolderPath) {
        owaAppFolderPath = OpenmrsUtil.getApplicationDataDirectory()
                + (OpenmrsUtil.getApplicationDataDirectory().endsWith(File.separator) ? "owa"
                        : File.separator + "owa");
        Context.getAdministrationService().setGlobalProperty(AppManager.KEY_APP_FOLDER_PATH, owaAppFolderPath);
    }
    String owaStarted = Context.getAdministrationService().getGlobalProperty("owa.started");
    String realPath = System.getProperty("user.dir");
    realPath = realPath.substring(0, realPath.length() - 3);
    StringBuffer tomcatPath = new StringBuffer(realPath);
    tomcatPath.append("webapps/openmrs");
    StringBuilder absPath = new StringBuilder(tomcatPath + "/WEB-INF");
    absPath.append("/view/module/");
    File dir = new File(absPath.toString().replace("/", File.separator));
    try {
        List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE);
        for (File file : files) {
            if (file.getCanonicalPath().contains("manifest.webapp") && owaStarted.equalsIgnoreCase("true")) {
                File source = file.getParentFile();
                File dest = new File(owaAppFolderPath + File.separator + source.getName());
                FileUtils.moveDirectory(source, dest);
                log.info("Moving file from: " + source + " to " + dest);
            }
        }
    } catch (IOException e) {
        log.error(e);
    }
    log.info("OWA Module refreshed");
}

From source file:org.opennms.upgrade.implementations.DiscoveryConfigurationLocationMigratorOfflineTest.java

@Before
public void setUp() throws Exception {
    FileUtils.copyDirectory(new File("src/test/resources/etc3"), m_tempFolder.newFolder("etc"));
    System.setProperty("opennms.home", m_tempFolder.getRoot().getAbsolutePath());
    final List<File> files = new ArrayList<>(FileUtils.listFilesAndDirs(new File(m_tempFolder.getRoot(), "etc"),
            TrueFileFilter.TRUE, TrueFileFilter.INSTANCE));
    Collections.sort(files);/*w  ww  .  j a v  a  2 s. co m*/
}

From source file:org.opennms.upgrade.implementations.DiscoveryConfigurationMigratorOfflineTest.java

@Before
public void setUp() throws Exception {
    FileUtils.copyDirectory(new File("src/test/resources/etc"), m_tempFolder.newFolder("etc"));
    System.setProperty("opennms.home", m_tempFolder.getRoot().getAbsolutePath());
    final List<File> files = new ArrayList<>(FileUtils.listFilesAndDirs(new File(m_tempFolder.getRoot(), "etc"),
            TrueFileFilter.TRUE, TrueFileFilter.INSTANCE));
    Collections.sort(files);//  ww w  .j  a  va 2  s. com
}

From source file:org.opentestsystem.authoring.testitembank.service.impl.ApipZipOutputFileBuilderService.java

private static final File createZipFromLocalDirectory(final File sourceDirectory, final String targetZipName)
        throws IOException {
    final Collection<File> filesToZip = FileUtils.listFiles(sourceDirectory, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);/*ww w .  j  a v  a  2s. c om*/

    FileOutputStream fout = null;
    ZipOutputStream zout = null;
    final File targetZip = new File(targetZipName);
    try {
        fout = new FileOutputStream(targetZip);
        zout = new ZipOutputStream(fout);

        for (final File file : filesToZip) {
            FileInputStream fin = null;
            try {
                fin = new FileInputStream(file);
                zout.putNextEntry(new ZipEntry(getRelativePath(file, sourceDirectory)));

                final byte[] buffer = new byte[1024];
                int length;
                while ((length = fin.read(buffer)) > 0) {
                    zout.write(buffer, 0, length);
                }
            } finally {
                IOUtils.closeQuietly(fin);
                closeEntryQuiety(zout);
            }
        }
    } catch (final FileNotFoundException e) {
        LOGGER.error("unexcepted FileNotFoundException: ", e);
    } finally {
        closeAndFlushQuietly(zout);
        closeAndFlushQuietly(fout);
    }

    return targetZip;
}

From source file:org.ow2.chameleon.core.activators.DirectoryMonitor.java

private FileAlterationMonitor createFileAlterationMonitor(File directory, long polling) {
    FileAlterationObserver observer = new FileAlterationObserver(directory, TrueFileFilter.INSTANCE);
    observer.addListener(new FileMonitor(directory));
    LOGGER.debug("Creating file alteration monitor for " + directory.getAbsolutePath()
            + " with a polling period " + "of " + polling);
    final FileAlterationMonitor monitor = new FileAlterationMonitor(polling, observer);
    monitor.setThreadFactory(new MonitorThreadFactory(directory));
    monitors.put(directory, monitor);/*from www.  ja va 2  s  .co m*/
    return monitor;
}

From source file:org.ow2.chameleon.fuchsia.discovery.filebased.monitor.DirectoryMonitor.java

public DirectoryMonitor(String directorypath, long polling, String classname) {

    this.directory = new File(directorypath);
    this.trackedClassName = classname;
    this.polling = polling;

    if (!directory.isDirectory()) {
        LOG.info("Monitored directory {} not existing - creating directory", directory.getAbsolutePath());
        if (!this.directory.mkdirs()) {
            throw new IllegalStateException("Monitored directory doesn't exist and cannot be created.");
        }/*from   ww  w .  jav  a  2  s.  c o m*/
    }

    // We observes all files.
    FileAlterationObserver observer = new FileAlterationObserver(directory, TrueFileFilter.INSTANCE);
    observer.checkAndNotify();
    observer.addListener(new FileMonitor());
    monitor = new FileAlterationMonitor(polling, observer);

}

From source file:org.ow2.chameleon.testing.helpers.TestBundleOption.java

public static Option testBundle(List<String> extraExports, boolean deleteTestBundle) {
    File out = new File("target/tested/test-bundle.jar");
    if (out.exists()) {
        if (deleteTestBundle) {
            out.delete();/* ww  w.  ja v  a2s . c  o  m*/
        } else {
            try {
                return bundle(out.toURI().toURL().toExternalForm());
            } catch (MalformedURLException e) {
                // Ignore it.
            }
        }
    }

    TinyBundle tested = TinyBundles.bundle();

    // We look inside target/classes to find the class and resources
    File classes = new File("target/classes");
    Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    List<String> exports = new ArrayList<String>();
    for (File file : files) {
        if (file.isDirectory()) {
            // By convention we export of .services and .service package
            if (file.getAbsolutePath().contains("/services") || file.getAbsolutePath().contains("/service")) {
                String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
                String packageName = path.replace('/', '.');
                exports.add(packageName);
            }
        } else {
            // We need to compute the path
            String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() + 1);
            try {
                tested.add(path, file.toURI().toURL());
            } catch (MalformedURLException e) {
                // Ignore it.
            }
            System.out.println(file.getName() + " added to " + path);
        }
    }

    // Added extra imports.
    exports.addAll(extraExports);

    String clause = "";
    for (String export : exports) {
        if (export.length() > 0) {
            export += ", ";
        }
        clause += export;
    }

    System.out.println("Exported packages : " + clause);

    InputStream inputStream = tested.set(Constants.BUNDLE_SYMBOLICNAME, BaseTest.TEST_BUNDLE_SYMBOLIC_NAME)
            .set(Constants.EXPORT_PACKAGE, clause)
            .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));

    // Setting the import-package to * generates an import clause with * which is invalid. In addition * is not
    // required as it's the default.

    try {
        org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
        return bundle(out.toURI().toURL().toExternalForm());
    } catch (MalformedURLException e) {
        throw new RuntimeException("Cannot compute the url of the manipulated bundle");
    } catch (IOException e) {
        throw new RuntimeException("Cannot write of the manipulated bundle");
    }
}

From source file:org.pentaho.platform.plugin.services.pluginmgr.PluginResourceLoader.java

public List<URL> findResources(ClassLoader classLoader, String namePattern) {

    String dirPattern = "", filePattern = "*"; //$NON-NLS-1$ //$NON-NLS-2$

    if (namePattern.contains("/")) { //$NON-NLS-1$
        String pattern = namePattern.substring(0, namePattern.lastIndexOf('/'));
        if (pattern.length() > 0) {
            dirPattern = pattern;/*w w  w . j a  va 2  s  .com*/
        }
        pattern = namePattern.substring(namePattern.lastIndexOf('/') + 1, namePattern.length());
        if (pattern.length() > 0) {
            filePattern = pattern;
        }
    } else {
        filePattern = namePattern;
    }

    IOFileFilter fileFilter = new WildcardFileFilter(filePattern);
    IOFileFilter dirFilter = TrueFileFilter.INSTANCE;

    Collection<?> files = FileUtils.listFiles(new File(getPluginDir(classLoader), dirPattern), fileFilter,
            dirFilter);
    Iterator<?> fileIter = files.iterator();
    List<URL> urls = new ArrayList<URL>(files.size());
    while (fileIter.hasNext()) {
        try {
            urls.add(((File) fileIter.next()).toURI().toURL());
        } catch (MalformedURLException e) {
            Logger.warn(this, "Could not create url", e); //$NON-NLS-1$
        }
    }
    return urls;
}