Search in sources :

Example 26 with FileFilter

use of java.io.FileFilter in project head by mifos.

the class OSGILauncher method searchFor.

/***************************************************************************
	 * See org.eclipse.core.launcher [copy of searchFor, findMax,
	 * compareVersion, getVersionElements] TODO: If these methods were made
	 * public and static we could use them directly
	 **************************************************************************/
/**
	 * Searches for the given target directory starting in the "plugins"
	 * subdirectory of the given location. If one is found then this location is
	 * returned; otherwise an exception is thrown.
	 * 
	 * @param target
	 * 
	 * @return the location where target directory was found
	 * @param start
	 *            the location to begin searching
	 */
protected String searchFor(final String target, String start) {
    FileFilter filter = new FileFilter() {

        public boolean accept(File candidate) {
            return candidate.getName().equals(target) || //$NON-NLS-1$
            candidate.getName().startsWith(target + "_");
        }
    };
    //$NON-NLS-1$
    File[] candidates = new File(start).listFiles(filter);
    if (candidates == null)
        return null;
    String[] arrays = new String[candidates.length];
    for (int i = 0; i < arrays.length; i++) {
        arrays[i] = candidates[i].getName();
    }
    int result = findMax(arrays);
    if (result == -1)
        return null;
    return candidates[result].getAbsolutePath().replace(File.separatorChar, '/') + //$NON-NLS-1$//$NON-NLS-2$
    (candidates[result].isDirectory() ? "/" : "");
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File)

Example 27 with FileFilter

use of java.io.FileFilter in project nutz by nutzam.

the class UTF8_BOM method main.

public static void main(String[] args) {
    final byte[] UTF_BOM = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
    final byte[] bom = new byte[3];
    Disks.visitFile(new File("."), new FileVisitor() {

        public void visit(File file) {
            try {
                FileInputStream fis = new FileInputStream(file);
                fis.read(bom);
                if (bom[0] == UTF_BOM[0] && bom[1] == UTF_BOM[1] && bom[2] == UTF_BOM[2]) {
                    System.out.println("Found BOM --> " + file);
                    byte[] data = Streams.readBytes(fis);
                    fis.close();
                    Files.write(file, data);
                    System.out.println("Fixed");
                }
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }, new FileFilter() {

        public boolean accept(File pathname) {
            if (pathname.isDirectory())
                return true;
            return pathname.getName().endsWith(".java") && pathname.length() > 3;
        }
    });
}
Also used : FileVisitor(org.nutz.lang.util.FileVisitor) FileFilter(java.io.FileFilter) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 28 with FileFilter

use of java.io.FileFilter in project spring-boot by spring-projects.

the class SampleAntApplicationIT method runJar.

@Test
public void runJar() throws Exception {
    File target = new File("target");
    File[] jarFiles = target.listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            return file.getName().endsWith(".jar");
        }
    });
    assertThat(jarFiles).hasSize(1);
    Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
    process.waitFor(5, TimeUnit.MINUTES);
    assertThat(process.exitValue()).isEqualTo(0);
    String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
    assertThat(output).contains("Spring Boot Ant Example");
}
Also used : InputStreamReader(java.io.InputStreamReader) FileFilter(java.io.FileFilter) File(java.io.File) JavaExecutable(org.springframework.boot.loader.tools.JavaExecutable) Test(org.junit.Test)

Example 29 with FileFilter

use of java.io.FileFilter in project cassandra by apache.

the class AbstractSSTableSimpleWriter method getNextGeneration.

private static int getNextGeneration(File directory, final String columnFamily) {
    final Set<Descriptor> existing = new HashSet<>();
    directory.listFiles(new FileFilter() {

        public boolean accept(File file) {
            Descriptor desc = SSTable.tryDescriptorFromFilename(file);
            if (desc == null)
                return false;
            if (desc.cfname.equals(columnFamily))
                existing.add(desc);
            return false;
        }
    });
    int maxGen = generation.getAndIncrement();
    for (Descriptor desc : existing) {
        while (desc.generation > maxGen) {
            maxGen = generation.getAndIncrement();
        }
    }
    return maxGen;
}
Also used : FileFilter(java.io.FileFilter) File(java.io.File) HashSet(java.util.HashSet)

Example 30 with FileFilter

use of java.io.FileFilter in project rest.li by linkedin.

the class ResourceSchemaCollection method createFromIdls.

/**
   * Create {@link ResourceSchemaCollection} from idl files.
   *
   * @param restspecSearchPaths file system paths to search for idl files
   * @return constructed ResourceSchemaCollection
   */
public static ResourceSchemaCollection createFromIdls(String[] restspecSearchPaths) {
    final RestSpecCodec codec = new RestSpecCodec();
    final Map<String, ResourceSchema> resourceSchemaMap = new HashMap<String, ResourceSchema>();
    for (String path : restspecSearchPaths) {
        final File dir = new File(path);
        if (!dir.isDirectory()) {
            throw new IllegalArgumentException(String.format("path '%s' is not a directory", dir.getAbsolutePath()));
        }
        final File[] idlFiles = dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname.getName().endsWith(RestConstants.RESOURCE_MODEL_FILENAME_EXTENSION);
            }
        });
        for (File idlFile : idlFiles) {
            try {
                final FileInputStream is = new FileInputStream(idlFile);
                final ResourceSchema resourceSchema = codec.readResourceSchema(is);
                resourceSchemaMap.put(resourceSchema.getName(), resourceSchema);
            } catch (IOException e) {
                throw new RestLiInternalException(String.format("Error loading restspec IDL file '%s'", idlFile.getName()), e);
            }
        }
    }
    return new ResourceSchemaCollection(resourceSchemaMap);
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) RestSpecCodec(com.linkedin.restli.restspec.RestSpecCodec) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

FileFilter (java.io.FileFilter)232 File (java.io.File)218 ArrayList (java.util.ArrayList)50 IOException (java.io.IOException)40 Test (org.junit.Test)13 FilenameFilter (java.io.FilenameFilter)11 URL (java.net.URL)10 HashMap (java.util.HashMap)10 FileInputStream (java.io.FileInputStream)8 FileNotFoundException (java.io.FileNotFoundException)8 HashSet (java.util.HashSet)8 JarFile (java.util.jar.JarFile)8 Pattern (java.util.regex.Pattern)8 Map (java.util.Map)7 WildcardFileFilter (org.apache.commons.io.filefilter.WildcardFileFilter)7 NotNull (org.jetbrains.annotations.NotNull)7 Treebank (edu.stanford.nlp.trees.Treebank)6 Pair (edu.stanford.nlp.util.Pair)6 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)6 EvaluateTreebank (edu.stanford.nlp.parser.lexparser.EvaluateTreebank)5