List of usage examples for java.io FileFilter FileFilter
FileFilter
From source file:com.doplgangr.secrecy.filesystem.encryption.Vault.java
private List<File> getFileList() { File folder = new File(path); return Arrays.asList(folder.listFiles(new FileFilter() { @Override/* www . j a v a 2s. c o m*/ public boolean accept(java.io.File file) { return fileFilter(file); } })); }
From source file:org.apache.carbondata.sdk.file.AvroCarbonWriterTest.java
@Test public void testWriteAllPrimitive() throws IOException { FileUtils.deleteDirectory(new File(path)); // Avro schema // Supported Primitive Datatype. // 1. Boolean // 2. Int/*w ww.jav a 2 s. c om*/ // 3. long // 4. float -> To carbon Internally it is double. // 5. double // 6. String // Not Supported // 1.NULL Datatype // 2.Bytes String avroSchema = "{\n" + " \"name\" : \"myrecord\",\n" + " \"namespace\": \"org.apache.parquet.avro\",\n" + " \"type\" : \"record\",\n" + " \"fields\" : [ " + " {\n" + " \"name\" : \"myboolean\",\n" + " \"type\" : \"boolean\"\n }," + " {\n" + " \"name\" : \"myint\",\n" + " \"type\" : \"int\"\n" + " }, " + " {\n \"name\" : \"mylong\",\n" + " \"type\" : \"long\"\n" + " }," + " {\n \"name\" : \"myfloat\",\n" + " \"type\" : \"float\"\n" + " }, " + " {\n \"name\" : \"mydouble\",\n" + " \"type\" : \"double\"\n" + " }," + " {\n \"name\" : \"mystring\",\n" + " \"type\" : \"string\"\n" + " }\n" + "] }"; String json = "{" + "\"myboolean\":true, " + "\"myint\": 10, " + "\"mylong\": 7775656565," + " \"myfloat\": 0.2, " + "\"mydouble\": 44.56, " + "\"mystring\":\"Ajantha\"}"; // conversion to GenericData.Record GenericData.Record record = TestUtil.jsonToAvro(json, avroSchema); try { CarbonWriter writer = CarbonWriter.builder().outputPath(path) .withAvroInput(new Schema.Parser().parse(avroSchema)).writtenBy("AvroCarbonWriterTest").build(); for (int i = 0; i < 100; i++) { writer.write(record); } writer.close(); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } File[] dataFiles = new File(path).listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().endsWith(CarbonCommonConstants.FACT_FILE_EXT); } }); Assert.assertNotNull(dataFiles); Assert.assertEquals(1, dataFiles.length); FileUtils.deleteDirectory(new File(path)); }
From source file:org.eclipse.gemini.blueprint.test.provisioning.internal.MavenPackagedArtifactFinder.java
private File findInDirectoryTree(String fileName, File root) { boolean trace = log.isTraceEnabled(); File targetDir = new File(root, TARGET); if (targetDir.exists()) { File artifact = new File(targetDir, fileName); // found artifact if (artifact.exists()) { if (trace) log.trace("Found artifact at " + artifact.getAbsolutePath() + "; checking the pom.xml groupId..."); // check the groupId inside the parent pom // (happens late to allow filtering to occur) File pomXml = new File(root, POM_XML); String groupId = getGroupIdFromPom(new FileSystemResource(pomXml)); if (trace) log.trace("Pom [" + pomXml.getAbsolutePath() + "] has groupId [" + groupId + "]"); if (this.groupId.equals(groupId)) return artifact; }//from ww w.j a v a 2 s .c om } File[] children = root.listFiles(new FileFilter() { public boolean accept(File pathname) { if (!isMavenProjectDirectory(pathname)) { return false; } if (pathname.getName().equals(TARGET)) { return false; } if (pathname.getName().equals("src")) { return false; } if (pathname.getName().equals(".svn")) { return false; } return true; } }); for (int i = 0; i < children.length; i++) { File found = findInDirectoryTree(fileName, children[i]); if (found != null) { return found; } } return null; }
From source file:com.bluexml.tools.miscellaneous.PrepareSIDEModulesMigration.java
private static void executeInpath(boolean inplace, String frameworkmodulesPath, String classifier_base, String version_base, String classifier_target, String version_target, String frameworkmodulesInplace, File workspaceFile, final String versionInProjectName, String versionInProjectName2) { File frameworkmodulesPathFile = new File(frameworkmodulesPath); if (inplace) { frameworkmodulesPathFile = new File(frameworkmodulesInplace); Collection<?> listFiles = FileUtils.listFiles(frameworkmodulesPathFile, TrueFileFilter.INSTANCE, new IOFileFilter() { public boolean accept(File dir, String name) { return !name.equals(".svn"); }/*from ww w.j a v a 2 s . com*/ public boolean accept(File file) { return !file.getName().equals(".svn"); } }); for (Object object : listFiles) { File f = (File) object; // System.out.println("PrepareSIDEModulesMigration.main() file :" + f); replaceVersionInFile(versionInProjectName, versionInProjectName2, version_base, classifier_base, version_target, classifier_target, f, true); } } else if (frameworkmodulesPathFile.exists()) { // copy resource // get project to copy File[] listFilesT = frameworkmodulesPathFile.listFiles(); System.out.println("PrepareSIDEModulesMigration.main() all :" + listFilesT.length); File[] listFiles = frameworkmodulesPathFile.listFiles(new FileFilter() { public boolean accept(File file) { if (file.isDirectory()) { String pat = versionInProjectName; pat = ".*" + Pattern.quote(pat) + ".*"; boolean matches = file.getName().matches(pat); System.out.println("accept() file" + file.getName() + " pattern :" + pat + " ?" + matches); return matches; } System.out .println("PrepareSIDEModulesMigration.main(...).new FileFilter() {...}.accept() FALSE"); return false; } }); System.out.println("PrepareSIDEModulesMigration.main() to copy : " + listFiles.length); for (File srcDir : listFiles) { System.out.println("PrepareSIDEModulesMigration.main() copy dir :" + srcDir); File copyDir = copyDir(workspaceFile, srcDir); reNameResources(versionInProjectName, copyDir, versionInProjectName2, version_base, classifier_base, version_target, classifier_target); } } else { System.err.println("frameworkmodulesPathFile do not exists :" + frameworkmodulesPathFile); } }
From source file:com.adaptris.core.ftp.FtpConsumer.java
private void moveToProcDir(String wipFile, final String filename, String procDir) { String[] existingFileNames = null; try {//from w ww.ja va 2s. c o m existingFileNames = ftpClient.dir(procDir, new FileFilter() { @Override public boolean accept(File f) { boolean result = false; if (f.getName().equals(filename)) { result = true; } return result; } }); String procFile = procDir + FORWARD_SLASH + filename; if (existingFileNames.length != 0) { procFile = procFile + "-" + System.currentTimeMillis(); } log.trace("Renaming processed file to [{}]", procFile); ftpClient.rename(wipFile, procFile); } catch (Exception e) { log.warn("Failed to rename to [{}] to [{}]", filename, procDir); } }
From source file:com.gargoylesoftware.htmlunit.source.BrowserVersionFeaturesSource.java
private void generate(final File dir, final String toSearchFor, final BrowserVersion[] versions) throws IOException { final File propertiesFolder = new File(root_, "src/main/resources/com/gargoylesoftware/htmlunit/javascript/configuration"); final File featuresFile = new File(root_, "src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java"); for (final File f : dir.listFiles()) { if (f.isDirectory()) { if (!".svn".equals(f.getName())) { generate(f, toSearchFor, versions); }//from w w w.j ava 2 s. c o m } else if (!"JavaScriptConfiguration.java".equals(f.getName())) { final List<String> lines = FileUtils.readLines(f); boolean modified = false; for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (line.contains(toSearchFor)) { line = line.replace(toSearchFor, ".hasFeature(BrowserVersionFeatures." + GENERATED_PREFIX + generatedNext_ + ")"); lines.set(i, line); modified = true; final List<String> featuresLines = FileUtils.readLines(featuresFile); featuresLines.add(featuresLines.size() - 4, ""); featuresLines.add(featuresLines.size() - 4, " /** Was originally " + toSearchFor + ". */"); featuresLines.add(featuresLines.size() - 4, " " + GENERATED_PREFIX + generatedNext_ + ","); FileUtils.writeLines(featuresFile, featuresLines); for (final File file : propertiesFolder.listFiles(new FileFilter() { public boolean accept(final File pathname) { for (final BrowserVersion version : versions) { if (pathname.getName().equals(version.getNickname() + ".properties")) { return true; } } return false; } })) { final List<String> features = FileUtils.readLines(file); features.add(GENERATED_PREFIX + generatedNext_); Collections.sort(features); FileUtils.writeLines(file, features); } generatedNext_++; } } if (modified) { FileUtils.writeLines(f, lines); } } } }
From source file:com.fujitsu.dc.engine.extension.support.ExtensionJarLoader.java
/** * ExtensionJarDirectory?? jar?URL??.//from ww w. j ava 2s . co m * ???? "jar"???? * @param extJarDir Extensionjar?? * @param searchDescend true: ?, false: ???? * @return jar? URL. */ private List<URL> getJarPaths(Path extJarDir, boolean searchDescend) throws DcEngineException { try { // ?? List<URL> uriList = new ArrayList<URL>(); // jar????? uriList.add(new URL("file", "", extJarDir.toFile().getAbsolutePath() + "/")); // jar? File[] jarFiles = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (!pathname.exists() || !pathname.canRead() || pathname.isDirectory()) { return false; } return FilenameUtils.isExtension(pathname.getName(), JAR_SUFFIX); } }); if (null != jarFiles) { for (File jarFile : jarFiles) { try { uriList.add(new URL("file", "", jarFile.getCanonicalPath())); log.info(String.format("Info: Adding extension jar file %s to classloader.", jarFile.toURI())); } catch (MalformedURLException e) { // ############################################################################3 // ????????? jar???????? jar???? // ? Extension????????? Extension????? UserScript?? // ???????????? // ?? Extension?????Script??? // ############################################################################3 log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } catch (IOException e) { log.info(String.format("Warn: Some Extension jar file has malformed path. Ignoring: %s", jarFile.toURI())); } } } // ? File[] subDirs = extJarDir.toFile().listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.exists() && pathname.isDirectory() && pathname.canRead(); } }); if (null != subDirs) { for (File subDir : subDirs) { // jar? uriList.addAll(getJarPaths(subDir.toPath(), searchDescend)); } } return uriList; } catch (RuntimeException e) { e.printStackTrace(); log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new DcEngineException("Error occured while loading Extension.", DcEngineException.STATUSCODE_SERVER_ERROR, e); } catch (Exception e) { log.info(String.format("Warn: Error occured while loading Extension: %s", e.getMessage())); throw new DcEngineException("Error occured while loading Extension.", DcEngineException.STATUSCODE_SERVER_ERROR, e); } }
From source file:de.petermoesenthin.alarming.util.FileUtil.java
/** * Returns a file list of all non-hidden files in the application directory. * * @return// www. j a v a 2 s. c o m */ public static File[] getAlarmDirectoryFileList() { return FileUtil.getApplicationDirectory().listFiles(new FileFilter() { @Override public boolean accept(File f) { return !f.isHidden(); } }); }
From source file:dk.statsbiblioteket.doms.radiotv.extractor.transcoder.OutputFileUtil.java
public static boolean lookForFileInFolder(File fileLocation, final String filenameWithoutExt) throws ProcessorException { final FileFilter filter = new FileFilter() { @Override//from w w w. j a v a 2 s . com public boolean accept(File pathname) { return pathname.getName().startsWith(filenameWithoutExt); } }; log.debug("Looking for file " + filenameWithoutExt + " in: " + fileLocation.getAbsolutePath()); int i = 0; while ((fileLocation.listFiles(filter) == null) && (i < 5)) { try { log.warn("Unable to access : " + fileLocation.getAbsolutePath() + ". Retrying " + i + ". " + new Date(System.currentTimeMillis())); Thread.sleep(1000); } catch (InterruptedException e) { log.info("Got interrupted. Ignoring interruption. Cause: " + e.getMessage()); // Do nothing... } i++; } if (fileLocation.listFiles(filter) == null) { log.error("Unable to access directory: " + fileLocation); throw new ProcessorException("Unable to access directories at storage."); } boolean hasFileInFinishedDir = fileLocation.listFiles(filter).length > 0; return hasFileInFinishedDir; }
From source file:com.doplgangr.secrecy.FileSystem.Vault.java
private List<java.io.File> getFileList() { java.io.File folder = new java.io.File(path); return Arrays.asList(folder.listFiles(new FileFilter() { @Override/*w w w. j a va2 s. c o m*/ public boolean accept(java.io.File file) { return fileFilter(file); } })); }