Search in sources :

Example 71 with FilenameFilter

use of java.io.FilenameFilter in project neo4j by neo4j.

the class StoreFilesTest method moveMustIgnoreFilesFilteredOut.

@Test
public void moveMustIgnoreFilesFilteredOut() throws Exception {
    File base = getBaseDir();
    File src = new File(base, "src");
    File a = new File(src, "a");
    File b = new File(src, "b");
    File ignore = new File(src, "ignore");
    File c = new File(ignore, "c");
    File d = new File(ignore, "d");
    File tgt = new File(base, "tgt");
    createOnFileSystem(a);
    createOnPageCache(b);
    createOnFileSystem(c);
    createOnPageCache(d);
    // Ensure the 'tgt' directory exists
    createOnFileSystem(new File(tgt, ".fs-ignore"));
    createOnPageCache(new File(tgt, ".pc-ignore"));
    FilenameFilter filter = (directory, name) -> !name.startsWith("ignore");
    storeFiles = new StoreFiles(fs, pageCache, filter);
    storeFiles.moveTo(src, tgt);
    assertFalse(fs.fileExists(a));
    assertFalse(pc.fileExists(b));
    assertTrue(fs.fileExists(c));
    assertTrue(pc.fileExists(d));
    assertTrue(fs.fileExists(new File(tgt, "a")));
    assertTrue(pc.fileExists(new File(tgt, "b")));
}
Also used : FilenameFilter(java.io.FilenameFilter) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Before(org.junit.Before) PageCache(org.neo4j.io.pagecache.PageCache) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) StoreId(org.neo4j.causalclustering.identity.StoreId) RuleChain(org.junit.rules.RuleChain) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) List(java.util.List) Rule(org.junit.Rule) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) FilenameFilter(java.io.FilenameFilter) File(java.io.File) Test(org.junit.Test)

Example 72 with FilenameFilter

use of java.io.FilenameFilter in project neo4j by neo4j.

the class StoreFilesTest method isEmptyMustFindFilesBothOnFileSystemAndPageCache.

@Test
public void isEmptyMustFindFilesBothOnFileSystemAndPageCache() throws Exception {
    File dir = getBaseDir();
    File ignore = new File(dir, "ignore");
    File a = new File(dir, "a");
    File b = new File(dir, "b");
    File c = new File(dir, "c");
    File d = new File(dir, "d");
    createOnFileSystem(a);
    createOnFileSystem(c);
    createOnFileSystem(ignore);
    createOnPageCache(b);
    createOnPageCache(d);
    createOnPageCache(ignore);
    FilenameFilter filter = (directory, name) -> !name.startsWith("ignore");
    storeFiles = new StoreFiles(fs, pageCache, filter);
    List<File> filesOnFilesystem = Arrays.asList(new File[] { a, c });
    List<File> fileOnFilesystem = Arrays.asList(new File[] { a });
    List<File> filesOnPageCache = Arrays.asList(new File[] { b, d });
    List<File> fileOnPageCache = Arrays.asList(new File[] { b });
    List<File> ingore = Arrays.asList(new File[] { ignore });
    assertFalse(storeFiles.isEmpty(dir, filesOnFilesystem));
    assertFalse(storeFiles.isEmpty(dir, fileOnFilesystem));
    assertFalse(storeFiles.isEmpty(dir, filesOnPageCache));
    assertFalse(storeFiles.isEmpty(dir, fileOnPageCache));
    assertTrue(storeFiles.isEmpty(dir, Collections.emptyList()));
    assertTrue(storeFiles.isEmpty(dir, ingore));
}
Also used : FilenameFilter(java.io.FilenameFilter) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Supplier(java.util.function.Supplier) Assert.assertThat(org.junit.Assert.assertThat) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Before(org.junit.Before) PageCache(org.neo4j.io.pagecache.PageCache) Position(org.neo4j.kernel.impl.store.MetaDataStore.Position) TestDirectory(org.neo4j.test.rule.TestDirectory) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) File(java.io.File) StoreId(org.neo4j.causalclustering.identity.StoreId) RuleChain(org.junit.rules.RuleChain) EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) List(java.util.List) Rule(org.junit.Rule) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) FilenameFilter(java.io.FilenameFilter) File(java.io.File) Test(org.junit.Test)

Example 73 with FilenameFilter

use of java.io.FilenameFilter in project OpenAM by OpenRock.

the class EmbeddedOpenDS method getOpenDSVersion.

public static String getOpenDSVersion() {
    Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
    String odsRoot = AMSetupServlet.getBaseDir() + "/" + SetupConstants.SMS_OPENDS_DATASTORE;
    String version = "unknown";
    File configLdif = new File(odsRoot + OPENDS_UPGRADE_DIR);
    File buildInfo = new File(odsRoot + "/" + "config" + "/" + SetupConstants.OPENDJ_BUILDINFO);
    if (configLdif.exists() && configLdif.isDirectory()) {
        String[] configFile = configLdif.list(new FilenameFilter() {

            //@Override -- Not Allowed Here.
            public boolean accept(File dir, String name) {
                return name.startsWith(OPENDS_CONFIG_LDIF);
            }
        });
        if (configFile.length != 0) {
            version = configFile[0].substring(configFile[0].lastIndexOf('.') + 1);
        } else {
            debug.error("Unable to determine OpenDJ version");
        }
    } else if (buildInfo.exists() && buildInfo.canRead() && buildInfo.isFile()) {
        String buildInfoVersionText = getOpenDJBuildInfo(buildInfo);
        if ((buildInfoVersionText != null) && (!buildInfoVersionText.isEmpty())) {
            version = buildInfoVersionText.trim();
        } else {
            debug.error("Unable to determine OpenDJ version");
        }
    } else {
        if (debug.warningEnabled()) {
            debug.warning("Unable to determine OpenDJ version; could be pre-config");
        }
    }
    if (debug.messageEnabled()) {
        debug.message("Found OpenDJ version: " + version);
    }
    return version;
}
Also used : FilenameFilter(java.io.FilenameFilter) ByteString(org.forgerock.opendj.ldap.ByteString) ZipFile(java.util.zip.ZipFile) File(java.io.File) Debug(com.sun.identity.shared.debug.Debug)

Example 74 with FilenameFilter

use of java.io.FilenameFilter in project tdi-studio-se by Talend.

the class FilterFileSystemStructureProvider method getChildren.

/*
     * (non-Javadoc) Method declared on IImportStructureProvider
     */
public List getChildren(Object element) {
    File folder = (File) element;
    File[] files = folder.listFiles(new FilenameFilter() {

        public boolean accept(File dir, String name) {
            return !FilesUtils.isSVNFolder(name);
        }
    });
    int childrenLength = files == null ? 0 : files.length;
    List<File> result = new ArrayList(childrenLength);
    for (int i = 0; i < childrenLength; i++) {
        result.add(files[i]);
    }
    return result;
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) File(java.io.File)

Example 75 with FilenameFilter

use of java.io.FilenameFilter in project tdi-studio-se by Talend.

the class JobJavaScriptsManager method addSourceCode.

protected void addSourceCode(ExportFileResource[] allResources, ProcessItem processItem, boolean needSource, ExportFileResource resource, String... selectedJobVersion) {
    // Get java src
    if (!needSource) {
        return;
    }
    try {
        String projectName = getCorrespondingProjectName(processItem);
        String jobName = processItem.getProperty().getLabel();
        String jobVersion = processItem.getProperty().getVersion();
        if (!isMultiNodes() && selectedJobVersion != null && selectedJobVersion.length == 1) {
            jobVersion = selectedJobVersion[0];
        }
        String jobFolderName = JavaResourcesHelper.getJobFolderName(jobName, jobVersion);
        IPath path = getSrcRootLocation();
        path = path.append(projectName).append(jobFolderName);
        FilenameFilter filter = new FilenameFilter() {

            @Override
            public boolean accept(File dir, String name) {
                //$NON-NLS-1$
                return name.toLowerCase().endsWith(".java");
            }
        };
        List<URL> javaFileUrls = new ArrayList<URL>();
        File file = path.toFile();
        if (file.exists() && file.isDirectory()) {
            for (File curFile : file.listFiles(filter)) {
                javaFileUrls.add(FileLocator.toFileURL(curFile.toURL()));
            }
        }
        resource.addResources(JOB_SOURCE_FOLDER_NAME + PATH_SEPARATOR + projectName + PATH_SEPARATOR + jobFolderName, javaFileUrls);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) DocumentException(org.dom4j.DocumentException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException)

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