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

The following examples show how to use org.apache.commons.io.FileUtils#listFiles() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WildcardNamespaceCollector.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
public static void main(final String[] args) throws IOException {

		for (int i = 0; i < packageNames.length; i++) {
			System.out.println("===== Package " + projFolders[i] + ", namespace " + packageNames[i]);

			final List<File> files = (List<File>) FileUtils.listFiles(new File(libFolder + projFolders[i]),
					new String[] { "java" }, true);
			final List<File> filesEx = (List<File>) FileUtils.listFiles(new File(exampleFolder + projFolders[i]),
					new String[] { "java" }, true);
			files.addAll(filesEx);
			Collections.sort(files);

			final WildcardImportVisitor wiv = getWildcardImports(packageNames[i], files);
			final List<File> filesSrc = new ArrayList<>();
			for (final String srcDir : srcFolders[i])
				filesSrc.addAll((List<File>) FileUtils.listFiles(new File(corpusFolder + srcDir),
						new String[] { "java" }, true));
			files.addAll(filesSrc);
			writeNamespaces("class", wiv.wildcardImports, files);
			writeNamespaces("method", wiv.wildcardMethodImports, files);
		}

	}
 
Example 2
Source File: CountDatasetMethods.java    From api-mining with GNU General Public License v3.0 6 votes vote down vote up
static int countExampleMethods(final String project, final String projFQName) throws IOException {

		// Get all java files in source folder
		final Set<String> callingMethods = new HashSet<>();
		final List<File> files = (List<File>) FileUtils.listFiles(new File(exampleFolder + project),
				new String[] { "java" }, true);
		Collections.sort(files);

		for (final File file : files) {
			// Ignore empty files
			if (file.length() == 0)
				continue;

			final APICallVisitor acv = new APICallVisitor(ASTVisitors.getAST(file), namespaceFolder);
			acv.process();
			final LinkedListMultimap<String, String> fqAPICalls = acv.getAPINames(projFQName);
			for (final String fqCaller : fqAPICalls.keySet()) {
				callingMethods.add(fqCaller);
			}
		}

		return callingMethods.size();
	}
 
Example 3
Source File: StreamsHbaseResourceGeneratorCLITest.java    From streams with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreamsHbaseResourceGeneratorCLI() throws Exception {

  String sourceDirectory = "target/dependency/jsonschemaorg-schemas";
  String targetDirectory = "target/generated-resources/hbase-cli";

  StreamsHbaseResourceGenerator.main(new String[]{sourceDirectory, targetDirectory});

  File testOutput = new File(targetDirectory);

  Assert.assertNotNull(testOutput);
  Assert.assertTrue(testOutput.exists());
  Assert.assertTrue(testOutput.isDirectory());

  Collection<File> outputCollection = FileUtils.listFiles(testOutput, StreamsHbaseResourceGeneratorTest.txtFilter, true);
  Assert.assertEquals(4, outputCollection.size());
}
 
Example 4
Source File: StreamsPigResourceGeneratorCLITest.java    From streams with Apache License 2.0 6 votes vote down vote up
@Test
public void testStreamsPigResourceGeneratorCLI() throws Exception {

  String sourceDirectory = "target/dependency/jsonschemaorg-schemas";
  String targetDirectory = "target/generated-resources/pig-cli";

  StreamsPigResourceGenerator.main(new String[]{sourceDirectory, targetDirectory});

  File testOutput = new File(targetDirectory);

  Assert.assertNotNull(testOutput);
  Assert.assertTrue(testOutput.exists());
  Assert.assertTrue(testOutput.isDirectory());

  Collection<File> outputCollection = FileUtils.listFiles(testOutput, StreamsPigResourceGeneratorTest.pigFilter, true);
  Assert.assertEquals(4, outputCollection.size());
}
 
Example 5
Source File: Boot.java    From DexExtractor with GNU General Public License v3.0 6 votes vote down vote up
public static void deodex() {
	Collection<File> dexFiles = FileUtils.listFiles(new File("/Users/BunnyBlue/Downloads/jeb2demo"),
			new String[] { "dex" }, false);

	for (File file : dexFiles) {
		try {

			if (DexChecker.isOdexFileFile(file)) {
				System.err.println("Boot.deodex()" + file.getAbsolutePath() + DexChecker.isOdexFileFile(file));
				// ODex.dumpToSmalli("/Users/BunnyBlue/Downloads/jeb2demo/system/framework",
				// file);
			}

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
Example 6
Source File: WorkflowConfigurationParser.java    From celos with Apache License 2.0 5 votes vote down vote up
public WorkflowConfigurationParser parseConfiguration(File workflowsDir, StateDatabaseConnection connection) {
    LOGGER.info("Using workflows directory: " + workflowsDir);
    LOGGER.info("Using defaults directory: " + defaultsDir);
    Collection<File> files = FileUtils.listFiles(workflowsDir, new String[] { WORKFLOW_FILE_EXTENSION }, false);
    for (File f : files) {
        try {
            parseFile(f, connection);
        } catch(Exception e) {
            LOGGER.error("Failed to load file: " + f + ": " + e.getMessage(), e);
        }
    }
    return this;
}
 
Example 7
Source File: BuildImageCmdIT.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void buildImageFromTarWithDockerfileNotInBaseDirectory() throws Exception {
    File baseDir = fileFromBuildTestResource("dockerfileNotInBaseDirectory");
    Collection<File> files = FileUtils.listFiles(baseDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    File tarFile = CompressArchiveUtil.archiveTARFiles(baseDir, files, UUID.randomUUID().toString());
    String response = dockerfileBuild(new FileInputStream(tarFile), "dockerfileFolder/Dockerfile");
    assertThat(response, containsString("Successfully executed testrun.sh"));
}
 
Example 8
Source File: MapUtils.java    From tankbattle with MIT License 5 votes vote down vote up
public static List<String> getCustomFileList() {
    Collection<File> listFiles = FileUtils.listFiles(new File(System.getProperty("user.home") + File.separator +
            ".tankBattle" + File.separator + "custom"), FileFilterUtils.suffixFileFilter("xml"), DirectoryFileFilter
            .INSTANCE);
    List<String> list = new ArrayList<>();
    for (File file : listFiles) {
        list.add(file.getName().substring(0, file.getName().lastIndexOf(".")));
        System.out.println(file.getName());
    }
    return list;
}
 
Example 9
Source File: UsagePointExtractor.java    From api-mining with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param args
 */
public static void main(final String[] args) {
	if (args.length != 2) {
		System.err.println("Usage <fullyQualifiedClass> <directory>");
		System.exit(-1);
	}

	final File directory = new File(args[1]);
	final String qualifiedClass = args[0];

	for (final File fi : FileUtils
			.listFiles(directory, JavaTokenizer.javaCodeFileFilter,
					DirectoryFileFilter.DIRECTORY)) {
		try {
			final List<ASTNode> usages = usagePoints(qualifiedClass, fi);
			if (!usages.isEmpty()) {
				System.out.println(fi.getAbsolutePath());
				for (final ASTNode node : usages) {
					System.out
							.println("----------------------------------------------");
					System.out.println(node);
				}
			}
		} catch (final Exception e) {
			System.err.println("Error processing " + fi.getName());
		}

	}

}
 
Example 10
Source File: AbstractGoDependencyAwareMojo.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
@Nonnull
@MustNotContainNull
private List<Tuple<Artifact, Tuple<GoMod, File>>> fildGoModsAndParse(@Nonnull @MustNotContainNull final List<Tuple<Artifact, File>> unpackedFolders) throws IOException {
  final List<Tuple<Artifact, Tuple<GoMod, File>>> result = new ArrayList<>();

  for (final Tuple<Artifact, File> tuple : unpackedFolders) {
    for (final File f : FileUtils.listFiles(tuple.right(), FileFilterUtils.nameFileFilter("go.mod"), TrueFileFilter.INSTANCE)) {
      final GoMod model = GoMod.from(FileUtils.readFileToString(f, StandardCharsets.UTF_8));
      result.add(Tuple.of(tuple.left(), Tuple.of(model, f)));
    }
  }

  return result;
}
 
Example 11
Source File: MagicImages.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
private static File getRandomAvatarFile() {
    final Collection<File> files = FileUtils.listFiles(
        MagicFileSystem.getDataPath(MagicFileSystem.DataPath.AVATARS).toFile(),
        new String[]{"png"},
        true
    );
    return files.stream()
        .skip(MagicRandom.nextRNGInt(files.size() - 1))
        .findFirst().orElse(new File(""));
}
 
Example 12
Source File: TestJobServerLogs.java    From scheduling with GNU Affero General Public License v3.0 4 votes vote down vote up
private void printDiagnosticMessage() {
    int LIMIT = 5;
    System.out.println("This test is going to fail, but before we print diagnostic message." +
                       simpleDateFormat.format(new Date()));
    // iterate over all files in the 'logsLocation'
    for (File file : FileUtils.listFiles(new File(logsLocation),
                                         TrueFileFilter.INSTANCE,
                                         TrueFileFilter.INSTANCE)) {
        try {
            BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
            System.out.println(String.format("Name: %s, Size: %d, Created: %s, Modified: %s",
                                             file.getAbsolutePath(),
                                             attr.size(),
                                             attr.creationTime(),
                                             attr.lastModifiedTime()));
            BufferedReader br = new BufferedReader(new FileReader(file));
            String line;
            int i;
            // print up to LIMIT first lines
            for (i = 0; i < LIMIT && (line = br.readLine()) != null; ++i) {
                System.out.println(line);
            }

            Queue<String> queue = new CircularFifoQueue<>(LIMIT);
            // reading last LIMIT lines
            for (; (line = br.readLine()) != null; ++i) {
                queue.add(line);
            }

            if (i >= LIMIT * 2) { // if there is more line than 2*LIMIT
                System.out.println(".......");
                System.out.println("....... (skipped content)");
                System.out.println(".......");
            }
            for (String l : queue) { // print rest of the file
                System.out.println(l);
            }

            System.out.println("------------------------------------");
            System.out.println();
        } catch (IOException e) {
            System.out.println("Exception ocurred during accessing file attributes " + e);
        }
    }
}
 
Example 13
Source File: GFileUtils.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static Collection listFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter) {
    return FileUtils.listFiles(directory, fileFilter, dirFilter);
}
 
Example 14
Source File: GFileUtils.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static Collection listFiles(File directory, String[] extensions, boolean recursive) {
    return FileUtils.listFiles(directory, extensions, recursive);
}
 
Example 15
Source File: IdentifierNGramModelBuilder.java    From naturalize with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param args
 * @throws IllegalAccessException
 * @throws InstantiationException
 * @throws ClassNotFoundException
 * @throws IOException
 * @throws SecurityException
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalArgumentException
 * @throws SerializationException
 */
public static void main(final String[] args) throws InstantiationException,
		IllegalAccessException, ClassNotFoundException, IOException,
		IllegalArgumentException, InvocationTargetException,
		NoSuchMethodException, SecurityException, SerializationException {
	final CommandLineParser parser = new PosixParser();

	final Options options = new Options();

	options.addOption(OptionBuilder.isRequired(true)
			.withDescription("n-gram n parameter. The size of n.").hasArg()
			.create("n"));
	options.addOption(OptionBuilder
			.isRequired(true)
			.withLongOpt("trainDir")
			.hasArg()
			.withDescription("The directory containing the training files.")
			.create("t"));
	options.addOption(OptionBuilder.isRequired(true).withLongOpt("output")
			.hasArg()
			.withDescription("File to output the serialized n-gram model.")
			.create("o"));

	final CommandLine parse;
	try {
		parse = parser.parse(options, args);
	} catch (ParseException ex) {
		System.err.println(ex.getMessage());
		final HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp("buildlm", options);
		return;
	}

	final ITokenizer tokenizer = new JavaTokenizer();
	final String nStr = parse.getOptionValue("n");
	final int n = Integer.parseInt(nStr);
	final File trainDirectory = new File(parse.getOptionValue("t"));
	checkArgument(trainDirectory.isDirectory());
	final String targetSerFile = parse.getOptionValue("o");

	final IdentifierNeighborsNGramLM dict = new IdentifierNeighborsNGramLM(
			n, tokenizer);

	LOGGER.info("NGramLM Model builder started with " + n
			+ "-gram for files in " + trainDirectory.getAbsolutePath());

	final Collection<File> files = FileUtils.listFiles(trainDirectory,
			dict.modelledFilesFilter(), DirectoryFileFilter.DIRECTORY);
	dict.trainModel(files);

	LOGGER.info("Ngram model build. Adding Smoother...");

	final AbstractNGramLM ng = new StupidBackoff(dict);

	LOGGER.info("Ngram model build. Serializing...");
	Serializer.getSerializer().serialize(ng, targetSerFile);
}
 
Example 16
Source File: DumpUtils.java    From kotlogram with MIT License 4 votes vote down vote up
public static Collection<File> loadAll(String path) {
    return FileUtils.listFiles(new File(path), new String[]{"dump"}, true);
}
 
Example 17
Source File: TemplateScanner.java    From apiman with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
    if (args == null || args.length != 1) {
        System.out.println("Template directory not provided (no path provided).");
        System.exit(1);
    }
    File templateDir = new File(args[0]);
    if (!templateDir.isDirectory()) {
        System.out.println("Template directory not provided (provided path is not a directory).");
        System.exit(1);
    }

    if (!new File(templateDir, "dash.html").isFile()) {
        System.out.println("Template directory not provided (dash.html not found).");
        System.exit(1);
    }

    File outputDir = new File(templateDir, "../../../../../../tools/i18n/target");
    if (!outputDir.isDirectory()) {
        System.out.println("Output directory not found: " + outputDir);
        System.exit(1);
    }
    File outputFile = new File(outputDir, "scanner-messages.properties");
    if (outputFile.isFile() && !outputFile.delete()) {
        System.out.println("Couldn't delete the old messages.properties: " + outputFile);
        System.exit(1);
    }

    System.out.println("Starting scan.");
    System.out.println("Scanning template directory: " + templateDir.getAbsolutePath());

    String[] extensions = { "html", "include" };
    Collection<File> files = FileUtils.listFiles(templateDir, extensions, true);

    TreeMap<String, String> strings = new TreeMap<>();

    for (File file : files) {
        System.out.println("\tScanning file: " + file);
        scanFile(file, strings);
    }

    outputMessages(strings, outputFile);

    System.out.println("Scan complete.  Scanned " + files.size() + " files and discovered " + strings.size() + " translation strings.");
}
 
Example 18
Source File: RestoreStorage.java    From o2oa with GNU Affero General Public License v3.0 4 votes vote down vote up
private <T extends StorageObject> long store(final Class<T> cls, final EntityManager em,
		final StorageMappings storageMappings) throws Exception {
	final File classDirectory = new File(this.dir, cls.getName());
	if ((!classDirectory.exists()) || (!classDirectory.isDirectory())) {
		throw new Exception("can not find directory: " + classDirectory.getAbsolutePath() + ".");
	}
	long count = 0;
	final List<File> files = new ArrayList<File>(
			FileUtils.listFiles(classDirectory, new String[] { "json" }, false));
	/** 对文件进行排序,和dump的时候的顺序保持一直 */
	Collections.sort(files, new Comparator<File>() {
		public int compare(final File o1, final File o2) {
			final String n1 = FilenameUtils.getBaseName(o1.getName());
			final String n2 = FilenameUtils.getBaseName(o2.getName());
			final Integer i1 = Integer.parseInt(n1);
			final Integer i2 = Integer.parseInt(n2);
			return i1.compareTo(i2);
		}
	});
	/** 尽量将删除的工作放在后面 */
	this.clean(cls, em, storageMappings);
	StorageMapping mapping = null;
	File file = null;
	for (int i = 0; i < files.size(); i++) {
		file = files.get(i);
		/** 必须先转换成 jsonElement 不能直接转成泛型T,如果直接转会有类型不匹配比如Integer变成了Double */
		logger.print("restoring " + (i + 1) + "/" + files.size() + " part of storage: " + cls.getName() + ".");
		final JsonArray raws = this.convert(file);
		if (null != raws) {
			em.getTransaction().begin();
			for (final JsonElement o : raws) {
				final T t = pureGsonDateFormated.fromJson(o, cls);
				if (Config.dumpRestoreStorage().getRedistribute()) {
					mapping = storageMappings.random(cls);
				} else {
					mapping = storageMappings.get(cls, t.getStorage());
				}
				if (null == mapping) {
					throw new Exception(
							"can not find storageMapping class: " + cls.getName() + ", name:" + t.getName());
				}
				final File source = new File(classDirectory, FilenameUtils.getBaseName(file.getName())
						+ StorageObject.PATHSEPARATOR + FilenameUtils.getName(t.path()));
				try (FileInputStream input = new FileInputStream(source)) {
					t.saveContent(mapping, input, t.getName());
				}
				em.persist(t);
				count++;
			}
			em.getTransaction().commit();
			em.clear();
			Runtime.getRuntime().gc();
		}
	}
	return count;
}
 
Example 19
Source File: ReloadableData.java    From aion-germany with GNU General Public License v3.0 4 votes vote down vote up
protected Collection<File> listFiles(File root, boolean recursive) {
	IOFileFilter dirFilter = recursive ? makeSVNAware(HiddenFileFilter.VISIBLE) : null;
	return FileUtils.listFiles(root, and(and(notFileFilter(prefixFileFilter("new")), suffixFileFilter(".xml")), HiddenFileFilter.VISIBLE), dirFilter);
}
 
Example 20
Source File: TacFileService.java    From tac with MIT License 2 votes vote down vote up
/**
 *listAllFiles
 *
 * @param directory
 * @return List
 */
public static List<File> listAllFiles(File directory) {
    Collection<File> files = FileUtils.listFiles(directory, FileFileFilter.FILE, DirectoryFileFilter.DIRECTORY);
    return Lists.newArrayList(files);
}