Java Code Examples for org.apache.commons.io.FileUtils.listFiles()

The following are Jave code examples for showing how to use listFiles() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: atlas   File: ApkFileListUtils.java   View Source Code Vote up 6 votes
protected static void prepareApkFileList(File folder, String prefixName, String awbName, ApkFiles apkFiles) {
    if (!folder.exists()) {
        return;
    }
    // Gets information about the main bundle
    Collection<File> files = FileUtils.listFiles(folder, new PureFileFilter(), TrueFileFilter.INSTANCE);
    for (File file : files) {
        if (file.isFile()) {
            String relativePath = prefixName + File.separator + PathUtil.toRelative(folder, file.getAbsolutePath());
            String md5 = MD5Util.getFileMD5(file);
            if (isImageFile(relativePath)) {
                if (null == apkFiles.apkFileList.getAwbs().get(awbName)) {
                    apkFiles.apkFileList.getAwbs().put(awbName, new HashMap<String, String>());
                }
                apkFiles.apkFileList.getAwbs().get(awbName).put(relativePath, md5);
            }
            if (null == apkFiles.finalApkFileList.getAwbs().get(awbName)) {
                apkFiles.finalApkFileList.getAwbs().put(awbName, new HashMap<String, String>());
            }
            apkFiles.finalApkFileList.getAwbs().get(awbName).put(relativePath, md5);
        }
    }

}
 
Example 2
Project: mtgo-best-bot   File: ProcessManager.java   View Source Code Vote up 6 votes
private String getExecutable() {
    File supposedExecutable = new File(executableDir + executableName);

    if(supposedExecutable.exists()) {
        return supposedExecutable.getAbsolutePath();
    } else {
        Collection<File> theExecutable = FileUtils.listFiles(new File(executableDir), new WildcardFileFilter(executableName), TrueFileFilter.INSTANCE);

        if(theExecutable != null || theExecutable.size() > 1 || theExecutable.isEmpty()) {
            File newestExecutable = theExecutable.stream().reduce(new File(""),
                    (aFile, newestFile) -> {
                        if(aFile.lastModified() > newestFile.lastModified()) {
                            return aFile;
                        }

                        return newestFile;
                    });

            return newestExecutable.getAbsolutePath();
        } else if(theExecutable.size() == 1) {
            return ((File)CollectionUtils.get(theExecutable, 0)).getAbsolutePath();
        } else {
            throw new RuntimeException("Could not determine executable path");
        }
    }
}
 
Example 3
Project: Habanero   File: JSONReportMerger.java   View Source Code Vote up 6 votes
/**
 * Give unique names to embedded images to ensure they aren't lost during merge
 * Update report file to reflect new image names
 *
 * @param reportFile
 */
public void renameEmbededImages(File reportFile) throws Throwable {
    File reportDirectory = reportFile.getParentFile();
    Collection<File> embeddedImages = FileUtils.listFiles(reportDirectory, new String[]{reportImageExtension}, true);

    String fileAsString = FileUtils.readFileToString(reportFile);

    for (File image : embeddedImages) {
        String curImageName = image.getName();
        String uniqueImageName = reportDirectory.getName() + "-" + UUID.randomUUID().toString() + "." + reportImageExtension;

        image.renameTo(new File(reportDirectory, uniqueImageName));
        fileAsString = fileAsString.replace(curImageName, uniqueImageName);
    }

    FileUtils.writeStringToFile(reportFile, fileAsString);
}
 
Example 4
Project: javaide   File: SampleDataTest.java   View Source Code Vote up 6 votes
public void testJavaLanguageFundamentals() throws IOException, InterruptedException {
    File parent = new File("C:\\github\\javaide2\\app\\src\\main\\assets\\sample\\JavaLanguageFundamentals");
    Collection<File> files = FileUtils.listFiles(parent, new String[]{"java"}, true);
    for (File file : files) {
        System.out.println(file);

        Process exec = Runtime.getRuntime().exec("javac " + file.getPath());
        exec.waitFor();
        InputStream inputStream = exec.getErrorStream();
        printStream(inputStream);
    }
    files = FileUtils.listFiles(parent, new String[]{"class"}, true);
    for (File f : files) {
        f.delete();
    }
}
 
Example 5
Project: acmeair   File: JmeterJTLParser.java   View Source Code Vote up 6 votes
public void processResultsDirectory(String dirName) {
	File root = new File(dirName);
	try {
		Collection<File> files = FileUtils.listFiles(root,
				new RegexFileFilter(jmeterJTLFileName),
				DirectoryFileFilter.DIRECTORY);

		for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) {
			File file = (File) iterator.next();
			parse(file);
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 6
Project: rest-modeling-framework   File: MdGenerator.java   View Source Code Vote up 6 votes
@Override
public void generate(Api api, File outputPath) throws IOException {
    if (outputPath.exists()) {
        Collection<File> files = FileUtils.listFiles(
                outputPath,
                TrueFileFilter.INSTANCE,
                TrueFileFilter.INSTANCE
        );
        for (File file : files) {
            if (file.isFile()) {
                Files.deleteIfExists(file.toPath());
            }
        }
    } else {
        Files.createDirectories(outputPath.toPath());
    }

    TypesGenerator generator = new TypesGenerator();
    generator.generate(api.getTypes(), new File(outputPath, "types") );

}
 
Example 7
Project: javaide   File: FileTest.java   View Source Code Vote up 6 votes
public static ArrayList<String> listClassName(File src) {
    if (!src.exists()) return new ArrayList<>();

    String[] exts = new String[]{"java"};
    Collection<File> files = FileUtils.listFiles(src, exts, true);

    ArrayList<String> classes = new ArrayList<>();
    String srcPath = src.getPath();
    for (File file : files) {
        String javaPath = file.getPath();
        javaPath = javaPath.substring(srcPath.length(), javaPath.length() - 5); //.java
        javaPath = javaPath.replace(File.separator, ".");
        classes.add(javaPath);
    }
    return classes;
}
 
Example 8
Project: atlas   File: NativeSoUtils.java   View Source Code Vote up 5 votes
/**
 * @param localNativeLibrariesDirectory
 * @param destinationDirectory
 * @param supportAbis                   Type of architecture supported
 * @param removeSoFiles
 */
public static void copyLocalNativeLibraries(final File localNativeLibrariesDirectory,
                                            final File destinationDirectory, Set<String> supportAbis,
                                            Set<String> removeSoFiles) {
    sLogger.info("Copying existing native libraries from " + localNativeLibrariesDirectory + " to "
                     + destinationDirectory);
    try {
        IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
        // First, determine whether there is a file of the same name, if there is a discrepancy
        Collection<File> files = FileUtils.listFiles(localNativeLibrariesDirectory, filter, TrueFileFilter.TRUE);
        List<String> dumpFiles = new ArrayList<String>();
        for (File file : files) {
            String relativePath = getRelativePath(localNativeLibrariesDirectory, file);
            File destFile = new File(destinationDirectory, relativePath);
            if (destFile.exists()) {
                String orgFileMd5 = MD5Util.getFileMD5(file);
                String destFileMd5 = MD5Util.getFileMD5(destFile);
                if (!orgFileMd5.equals(destFileMd5)) {
                    dumpFiles.add(file.getAbsolutePath() + " to " + destFile.getAbsolutePath());
                }
            }
        }
        if (dumpFiles.size() > 0) {
            throw new RuntimeException("Copy native so error,duplicate file exist!:\n"
                                           + StringUtils.join(dumpFiles, "\n"));
        }
        FileUtils.copyDirectory(localNativeLibrariesDirectory, destinationDirectory, filter);
    } catch (IOException e) {
        throw new RuntimeException("Could not copy native dependency.", e);
    }
}
 
Example 9
Project: storm_spring_boot_demo   File: buildStormCmd.java   View Source Code Vote up 5 votes
@Test
public void test(){
    Collection<File> files = FileUtils.listFiles(new File(PATH_NAME), new String[]{"jar"}, false);
    StringBuilder cmd = new StringBuilder("storm --jars \"");
    files.forEach(file -> {
        cmd.append("libs/").append(file.getName()).append(",");
    });
    cmd.deleteCharAt(cmd.length()-1);
    cmd.append("\" jar ").append(FINAL_NAME)
            .append(" com.maxplus1.DemoApplication ");
    System.out.println("====================================");
    System.out.println(cmd.toString());
    System.out.println("====================================");
}
 
Example 10
Project: jijimaku   File: WorkerAnnotate.java   View Source Code Vote up 5 votes
@Override
public Void doInBackground() throws Exception {
  if (SwingUtilities.isEventDispatchThread()) {
    throw new Exception("Worker should not run on the EDT thread!");
  }

  LOGGER.info("------------------- Searching in {} -------------------", searchDirectory.getAbsolutePath());
  Integer nbAnnotated = 0;
  for (File fileEntry : FileUtils.listFiles(searchDirectory, searchExtensions, true)) {
    try {
      if (processFile(fileEntry)) {
        nbAnnotated++;
      }
    } catch (Exception exc) {
      LOGGER.error("Error while trying to annotate {}. See log for details. Skip file.", fileEntry.getName());
      LOGGER.debug("Got exception", exc);
    }

    if (isCancelled()) {
      LOGGER.debug("WorkerSubAnnotator was cancelled.");
      return null;
    }
  }

  if (nbAnnotated > 0) {
    LOGGER.info("{} subtitle files were annotated.", nbAnnotated);
  } else {
    LOGGER.info("No subtitle found in this directory.");
  }
  return null;
}
 
Example 11
Project: otter-G   File: ArchiveBeanIntegration.java   View Source Code Vote up 5 votes
public void test_pack() {
    ArchiveBean archiveBean = new ArchiveBean();
    try {
        archiveBean.afterPropertiesSet();
        archiveBean.setUseLocalFileMutliThread(false);
    } catch (Exception e1) {
        want.fail();
    }

    File file = new File("/tmp/otter/test");
    Collection<File> allFiles = FileUtils.listFiles(file, new String[] { "jpg" }, true);

    List<FileData> fileDatas = new ArrayList<FileData>();
    for (File files : allFiles) {
        FileData data = new FileData();
        // data.setPath("wsproduct_repository/product_sku/76/84/32/84/768432847_10.summ.jpg");
        data.setPath(StringUtils.substringAfter(files.getAbsolutePath(), "/tmp/otter/test"));
        fileDatas.add(data);
    }

    File archiveFile = new File("/tmp/otter/test.gzip");
    if (archiveFile.exists()) {
        archiveFile.delete();
    }

    boolean result = archiveBean.pack(archiveFile, fileDatas, new ArchiveRetriverCallback<FileData>() {

        public InputStream retrive(FileData source) {
            return new LazyFileInputStream(new File("/tmp/otter/test", source.getPath()));
        }
    });

    if (!result) {
        want.fail();
    }

}
 
Example 12
Project: Open_Source_ECOA_Toolset_AS5   File: PluginUtil.java   View Source Code Vote up 5 votes
public ArrayList<String> getResourcesWithExtension(String ext, String containerName) {
	ArrayList<String> ret = new ArrayList<String>();
	if (containerName != null) {
		String[] names = StringUtils.split(containerName, "/");
		IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
		IResource resource = wsRoot.findMember(new Path("/" + names[0]));
		IPath loc = resource.getLocation();
		File prjLoc = new File(loc.toString());
		Collection<File> res = FileUtils.listFiles(prjLoc, FileFilterUtils.suffixFileFilter(ext, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
		for (File file : res)
			ret.add(file.getAbsolutePath());
	}
	return ret;
}
 
Example 13
Project: Java-Data-Science-Cookbook   File: FileListing.java   View Source Code Vote up 5 votes
public void listFiles(String rootDir){
	File dir = new File(rootDir);

	List<File> files = (List<File>) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
	for (File file : files) {
		System.out.println("file: " + file.getAbsolutePath());
	}
}
 
Example 14
Project: Biliomi   File: FindUpdatesSetupTask.java   View Source Code Vote up 5 votes
private void removeOldInstall() throws IOException {
  Collection<File> filesToDelete = FileUtils.listFiles(installDir, new String[]{"jar"}, false);
  List<File> directories = Arrays.stream(INSTALLER_DIRS)
      .map(s -> new File(installDir, s))
      .collect(Collectors.toList());

  filesToDelete.addAll(directories);

  EStream.from(filesToDelete)
      .filter(File::exists)
      .forEach(FileUtils::forceDelete);
}
 
Example 15
Project: AndroTickler   File: SearchUtil.java   View Source Code Vote up 5 votes
/**
* Search for extensions in a directory (or list all files in directory)
* @param path
* @param extensions filter by extension types
* @return
*/
public List<File> search4FileInDir(String path, String[] extensions){
	File dir = new File(path);
	List<File> files;
	if (extensions != null){
		files = (List<File>)FileUtils.listFiles(dir, extensions, true);
		
	}
	else {
		files = (List<File>)FileUtils.listFiles(dir, null, true);
	}
	return files;
	
}
 
Example 16
Project: atlas   File: DexPatchPackageTask.java   View Source Code Vote up 5 votes
protected void addDirectory(JarOutputStream jos, File directory, String prefix) throws PatchException {
    if (directory != null && directory.exists()) {
        Collection files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
        byte[] buf = new byte[8064];
        Iterator var6 = files.iterator();

        while (true) {
            File file;
            do {
                if (!var6.hasNext()) {
                    return;
                }

                file = (File) var6.next();
            } while (file.isDirectory());

            String path = prefix + File.separator + PathUtils.toRelative(directory, file.getAbsolutePath());
            FileInputStream in = null;

            try {
                in = new FileInputStream(file);
                ZipEntry e = new ZipEntry(path);
                jos.putNextEntry(e);

                int len;
                while ((len = in.read(buf)) > 0) {
                    jos.write(buf, 0, len);
                }

                jos.closeEntry();
                in.close();
            } catch (IOException var12) {
                throw new PatchException(var12.getMessage(), var12);
            }
        }
    }
}
 
Example 17
Project: Reer   File: GFileUtils.java   View Source Code Vote up 4 votes
public static Collection listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
    return FileUtils.listFiles(directory, fileFilter, dirFilter);
}
 
Example 18
Project: emnlp2017-cmapsum-corpus   File: CheckConceptMaps.java   View Source Code Vote up 4 votes
public static void main(String[] args) throws IOException {

		// parameters
		if (args.length < 1) {
			System.err.println("arguments missing!");
			System.err.println("Usage: java CheckConceptMaps <map-folder> [<map-name>]");
			System.exit(0);
		}

		File folder = new File(args[0]);
		String[] ext = { "cmap" };

		String name = ".*";
		if (args.length == 2)
			name = args[1];

		boolean hasError = false;
		for (File mapFile : FileUtils.listFiles(folder, ext, true)) {
			if (mapFile.getName().matches(name)) {

				System.out.println(mapFile);

				ConceptMap map = ConceptMapReader.readFromFile(mapFile, Format.TSV);
				System.out.println("concepts: \t" + map.getConcepts().size());
				System.out.println("relations: \t" + map.getProps().size());

				boolean connected = map.isConnected();
				System.out.println("connected: \t" + connected);
				if (!connected)
					hasError = true;

				Proposition dup = map.hasDoubleEdge();
				if (dup != null) {
					System.out.println(
							"duplicate relation: \t" + dup.sourceConcept.name + " <-> " + dup.targetConcept.name);
					hasError = true;
				}
			}
		}

		if (hasError)
			System.exit(4);
		else
			System.exit(0);

	}
 
Example 19
Project: groupe3   File: PcmUtils.java   View Source Code Vote up 2 votes
/**
 * Imports into the program the data set to load
 * @param directory Path
 * @return A list of files
 */
public static Collection<File> getPCMFiles(File directory) {
    return FileUtils.listFiles(directory, extensions, true);
}
 
Example 20
Project: shabdiz   File: AnalyticsUtil.java   View Source Code Vote up 2 votes
static Collection<File> getFilesByName(File search_path, String name) {

        return FileUtils.listFiles(search_path, new FileFilterByName(name), TrueFileFilter.INSTANCE);
    }