Search in sources :

Example 61 with FilenameFilter

use of java.io.FilenameFilter in project graphdb by neo4j-attic.

the class DumpLogicalLog method filenamesOf.

private static String[] filenamesOf(String string) {
    File file = new File(string);
    if (file.isDirectory()) {
        File[] files = file.listFiles(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.contains("_logical.log.v");
            }
        });
        Collection<String> result = new TreeSet<String>();
        for (int i = 0; i < files.length; i++) {
            result.add(files[i].getPath());
        }
        return result.toArray(new String[result.size()]);
    } else {
        return new String[] { string };
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) TreeSet(java.util.TreeSet) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 62 with FilenameFilter

use of java.io.FilenameFilter in project neo4j-mobile-android by neo4j-contrib.

the class DumpLogicalLog method filenamesOf.

protected static String[] filenamesOf(String filenameOrDirectory, final String prefix) {
    File file = new File(filenameOrDirectory);
    if (file.isDirectory()) {
        File[] files = file.listFiles(new FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.contains(prefix) && !name.contains("active");
            }
        });
        Collection<String> result = new TreeSet<String>(sequentialComparator());
        for (int i = 0; i < files.length; i++) {
            result.add(files[i].getPath());
        }
        return result.toArray(new String[result.size()]);
    } else {
        return new String[] { filenameOrDirectory };
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) TreeSet(java.util.TreeSet) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 63 with FilenameFilter

use of java.io.FilenameFilter in project graphdb by neo4j-attic.

the class TestXaFramework method testCreateXaResource.

@Test
public void testCreateXaResource() throws Exception {
    Map<Object, Object> config = new HashMap<Object, Object>();
    config.put("store_dir", "target/var");
    config.put(LogBufferFactory.class, CommonFactories.defaultLogBufferFactory(config));
    xaDsMgr.registerDataSource("dummy_datasource", new DummyXaDataSource(config), UTF8.encode("DDDDDD"));
    XaDataSource xaDs = xaDsMgr.getXaDataSource("dummy_datasource");
    DummyXaConnection xaC = null;
    try {
        xaC = (DummyXaConnection) xaDs.getXaConnection();
        try {
            xaC.doStuff1();
            fail("Non enlisted resource should throw exception");
        } catch (XAException e) {
        // good
        }
        Xid xid = new XidImpl(new byte[0], new byte[0]);
        xaC.getXaResource().start(xid, XAResource.TMNOFLAGS);
        try {
            xaC.doStuff1();
            xaC.doStuff2();
        } catch (XAException e) {
            fail("Enlisted resource should not throw exception");
        }
        xaC.getXaResource().end(xid, XAResource.TMSUCCESS);
        xaC.getXaResource().prepare(xid);
        xaC.getXaResource().commit(xid, false);
    } finally {
        xaDsMgr.unregisterDataSource("dummy_datasource");
        if (xaC != null) {
            xaC.destroy();
        }
    }
    // cleanup dummy resource log
    File dir = new File(".");
    File[] files = dir.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String fileName) {
            return fileName.startsWith(resourceFile());
        }
    });
    for (int i = 0; i < files.length; i++) {
        files[i].delete();
    }
}
Also used : XAException(javax.transaction.xa.XAException) HashMap(java.util.HashMap) XaDataSource(org.neo4j.kernel.impl.transaction.xaframework.XaDataSource) FilenameFilter(java.io.FilenameFilter) Xid(javax.transaction.xa.Xid) File(java.io.File) Test(org.junit.Test)

Example 64 with FilenameFilter

use of java.io.FilenameFilter in project pinpoint by naver.

the class AgentDirBaseClassPathResolver method resolvePlugins.

@Override
public URL[] resolvePlugins() {
    final File file = new File(getAgentPluginPath());
    if (!file.exists()) {
        logger.warn(file + " not found");
        return new URL[0];
    }
    if (!file.isDirectory()) {
        logger.warn(file + " is not a directory");
        return new URL[0];
    }
    final File[] jars = file.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".jar");
        }
    });
    if (jars == null || jars.length == 0) {
        return new URL[0];
    }
    final URL[] urls = new URL[jars.length];
    for (int i = 0; i < jars.length; i++) {
        try {
            urls[i] = jars[i].toURI().toURL();
        } catch (MalformedURLException e) {
            // TODO have to change to PinpointException AFTER moving the exception to pinpoint-common
            throw new RuntimeException("Fail to load plugin jars", e);
        }
    }
    for (File pluginJar : jars) {
        logger.info("Found plugins: " + pluginJar.getPath());
    }
    return urls;
}
Also used : FilenameFilter(java.io.FilenameFilter) MalformedURLException(java.net.MalformedURLException) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL)

Example 65 with FilenameFilter

use of java.io.FilenameFilter in project custom-cert-https by nelenkov.

the class MainActivity method listCertificateFiles.

private static String[] listCertificateFiles() {
    File externalStorage = Environment.getExternalStorageDirectory();
    FilenameFilter ff = new FilenameFilter() {

        @Override
        public boolean accept(File dir, String filename) {
            if (filename.contains(".")) {
                String[] filenameExt = filename.split("\\.");
                String ext = filenameExt[filenameExt.length - 1].toLowerCase();
                if (ext.equals("cer") || ext.equals("der")) {
                    return true;
                }
            }
            return false;
        }
    };
    return externalStorage.list(ff);
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Aggregations

FilenameFilter (java.io.FilenameFilter)402 File (java.io.File)398 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)72 Test (org.junit.Test)60 URL (java.net.URL)22 List (java.util.List)22 RandomAccessFile (java.io.RandomAccessFile)19 HashSet (java.util.HashSet)17 FileOutputStream (java.io.FileOutputStream)14 JarFile (java.util.jar.JarFile)14 FileNotFoundException (java.io.FileNotFoundException)13 MalformedURLException (java.net.MalformedURLException)13 HashMap (java.util.HashMap)13 FileFilter (java.io.FileFilter)11 FileWriter (java.io.FileWriter)11 ZipFile (java.util.zip.ZipFile)11 TestClient (org.syncany.tests.util.TestClient)11 FileReader (java.io.FileReader)10 Pattern (java.util.regex.Pattern)10