List of usage examples for java.io File list
public String[] list(FilenameFilter filter)
From source file:io.siddhi.doc.gen.core.utils.DocumentationUtils.java
/** * Remove the snapshot version documentation files from docs/api directory * * @param mkdocsConfigFile The mkdocs configuration file * @param documentationBaseDirectory The path of the base directory in which the documentation will be generated * @param logger The maven plugin logger */// w ww . j a v a2 s . c o m public static void removeSnapshotAPIDocs(File mkdocsConfigFile, String documentationBaseDirectory, Log logger) { // Retrieving the documentation file names File apiDocsDirectory = new File(documentationBaseDirectory + File.separator + Constants.API_SUB_DIRECTORY); String[] documentationFileNames = apiDocsDirectory .list((directory, fileName) -> fileName.endsWith(Constants.MARKDOWN_FILE_EXTENSION)); if (documentationFileNames != null) { // Removing snapshot files and creating a list of the files that are left out for (String documentationFileName : documentationFileNames) { if (documentationFileName .endsWith(Constants.SNAPSHOT_VERSION_POSTFIX + Constants.MARKDOWN_FILE_EXTENSION)) { // Removing the snapshot documentation file File documentationFile = new File( apiDocsDirectory.getAbsolutePath() + File.separator + documentationFileName); if (!documentationFile.delete()) { logger.warn("Failed to delete SNAPSHOT documentation file " + documentationFile.getAbsolutePath()); } } } } }
From source file:de.ee.hezel.PDFCorpusAnalyser.java
/** * Run thru the given folders and find pdf document which have the same name. * For every pair, a PDFInfoHolder objects gets created. * //from w w w.j ava 2 s . c om * @param pdfs1 for the 1st directory * @param pdfs2 for the 2nd directory * @param prefix * @return list of all pdf pairs */ public static Set<PDFInfoHolder> getSimplePDFInfoHolders(File pdfs1, File pdfs2, String prefix) { Set<PDFInfoHolder> pdfInfoHolders = new HashSet<PDFInfoHolder>(); // are those valid pathes if (pdfs1 != null && pdfs2 != null && pdfs1.isDirectory() && pdfs2.isDirectory()) { // create a filter to only get pdf files List<FilenameFilter> filters = new ArrayList<FilenameFilter>(); if (null != prefix && prefix.length() > 0) { PrefixFileFilter filter = new PrefixFileFilter(prefix, IOCase.SYSTEM); filters.add(filter); } filters.add(new SuffixFileFilter(".pdf", IOCase.INSENSITIVE)); FilenameFilter filter = new AndFileFilter(filters); //get all pdf file sin this folder String[] pdfDocuments1 = pdfs1.list(filter); for (int i = 0; i < pdfDocuments1.length; i++) { // get the pdf file name String pdfFilename1 = pdfDocuments1[i]; // get the path for both pdf files File pdfFile1 = new File(pdfs1, pdfFilename1); File pdfFile2 = new File(pdfs2, pdfFilename1); // bind them together in a PDFInfoHolder objects PDFInfoHolder newPDFInfoHolder = new PDFInfoHolder(pdfFile1, pdfFile2); // remember them all pdfInfoHolders.add(newPDFInfoHolder); } // TODO what should happen if there are less reference documents than new generated ones } else { log.error("The path is not valid."); } return pdfInfoHolders; }
From source file:io.siddhi.doc.gen.core.utils.DocumentationUtils.java
/** * This add a new page to the list of pages in the mkdocs configuration * * @param mkdocsConfigFile The mkdocs configuration file * @param documentationBaseDirectory The base directory of the documentation * @throws FileNotFoundException If mkdocs configuration file is not found *///from w w w. jav a 2 s .c o m public static void updateAPIPagesInMkdocsConfig(File mkdocsConfigFile, String documentationBaseDirectory) throws FileNotFoundException { // Retrieving the documentation file names File documentationDirectory = new File( documentationBaseDirectory + File.separator + Constants.API_SUB_DIRECTORY); String[] documentationFiles = documentationDirectory .list((directory, fileName) -> fileName.endsWith(Constants.MARKDOWN_FILE_EXTENSION)); List<String> apiDirectoryContent; if (documentationFiles == null) { apiDirectoryContent = new ArrayList<>(); } else { apiDirectoryContent = Arrays.asList(documentationFiles); apiDirectoryContent.sort(new Comparator<String>() { @Override public int compare(String s1, String s2) { String[] s1s = s1.split("\\D+"); String[] s2s = s2.split("\\D+"); int i = 0; while (s1s.length > i || s2s.length > i) { String s1a = "0"; String s2a = "0"; if (s1s.length > i) { s1a = s1s[i]; } if (s2s.length > i) { s2a = s2s[i]; } int s1aInt = Integer.parseInt(s1a); int s2aInt = Integer.parseInt(s2a); if (s2aInt > s1aInt) { return 1; } else if (s2aInt < s1aInt) { return -1; } i++; } return 0; } }); } String latestVersionFile = null; if (apiDirectoryContent.size() > 1) { String first = apiDirectoryContent.get(0); String second = apiDirectoryContent.get(1); if (first.equals(Constants.LATEST_FILE_NAME + Constants.MARKDOWN_FILE_EXTENSION)) { latestVersionFile = second; } } // Creating yaml parser DumperOptions dumperOptions = new DumperOptions(); dumperOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); Yaml yaml = new Yaml(dumperOptions); // Reading the mkdocs configuration Map<String, Object> yamlConfig = (Map<String, Object>) yaml .load(new InputStreamReader(new FileInputStream(mkdocsConfigFile), Constants.DEFAULT_CHARSET)); // Getting the pages list List<Map<String, Object>> yamlConfigPagesList = (List<Map<String, Object>>) yamlConfig .get(Constants.MKDOCS_CONFIG_PAGES_KEY); // Creating the new api pages list List<Map<String, Object>> apiPagesList = new ArrayList<>(); for (String apiFile : apiDirectoryContent) { String pageName = apiFile.substring(0, apiFile.length() - Constants.MARKDOWN_FILE_EXTENSION.length()); Map<String, Object> newPage = new HashMap<>(); if (latestVersionFile != null && pageName.equals(Constants.LATEST_FILE_NAME)) { pageName = "Latest (" + latestVersionFile.substring(0, latestVersionFile.length() - Constants.MARKDOWN_FILE_EXTENSION.length()) + ")"; } newPage.put(pageName, Constants.API_SUB_DIRECTORY + Constants.MKDOCS_FILE_SEPARATOR + apiFile); apiPagesList.add(newPage); } // Setting the new api pages Map<String, Object> yamlConfigAPIPage = null; for (Map<String, Object> yamlConfigPage : yamlConfigPagesList) { if (yamlConfigPage.get(Constants.MKDOCS_CONFIG_PAGES_API_KEY) != null) { yamlConfigAPIPage = yamlConfigPage; break; } } if (yamlConfigAPIPage == null) { yamlConfigAPIPage = new HashMap<>(); yamlConfigPagesList.add(yamlConfigAPIPage); } yamlConfigAPIPage.put(Constants.MKDOCS_CONFIG_PAGES_API_KEY, apiPagesList); // Saving the updated configuration yaml.dump(yamlConfig, new OutputStreamWriter(new FileOutputStream(mkdocsConfigFile), Constants.DEFAULT_CHARSET)); }
From source file:com.thoughtworks.go.legacywrapper.CCProjectFolderFilter.java
public boolean accept(File dirFile) { if (dirFile.isDirectory()) { String[] files = dirFile.list(new CCLogFilter()); return !ArrayUtils.isEmpty(files); }// w w w . ja v a 2 s . co m return false; }
From source file:me.neatmonster.spacertk.utilities.WorldFileFilter.java
@Override public boolean accept(final File file) { if (file.isDirectory()) if (file.list(new NameFileFilter("level.dat")).length > 0) return true; return false; }
From source file:de.zib.gndms.infra.system.PluginLoader.java
public URLClassLoader loadPlugins() throws IOException { final ArrayList<URL> jars; final File pluginDir = new File(pluginPath); final String[] list = pluginDir.list(new FilenameFilter() { @Override//from w w w .j av a2 s . com public boolean accept(final File dir, final String name) { return name.matches(".*\\.jar"); } }); if (list != null) { jars = new ArrayList<URL>(list.length); for (int i = 0; i < list.length; ++i) jars.add(new URL("file://" + pluginPath + File.separator + list[i])); return new URLClassLoader(jars.toArray(new URL[jars.size()]), this.getClass().getClassLoader()); } return new URLClassLoader(new URL[] {}, this.getClass().getClassLoader()); }
From source file:com.discursive.jccook.io.FilterExample.java
public void start() { File rootDir = new File("."); FilenameFilter fileFilter = new SuffixFileFilter(".xml"); String[] xmlFiles = rootDir.list(fileFilter); System.out.println("*** XML Files"); System.out.println(ArrayUtils.toString(xmlFiles)); rootDir = new File("./test"); IOFileFilter htmlFilter = new OrFileFilter(new SuffixFileFilter("htm"), new SuffixFileFilter("html")); IOFileFilter notDirectory = new NotFileFilter(DirectoryFileFilter.INSTANCE); fileFilter = new AndFileFilter(htmlFilter, notDirectory); String[] htmlFiles = rootDir.list(fileFilter); System.out.println("*** HTML Files"); System.out.println(ArrayUtils.toString(htmlFiles)); }
From source file:com.rtg.launcher.CommonFlags.java
/** * Initialise flag for AVR model to use for prediction * * @param flags shared flags/* ww w . j a va 2s . co m*/ * @param anonymous if true, register the flag as an anonymous flag * @return the newly registered flag */ public static Flag initAvrModel(final CFlags flags, boolean anonymous) { String description = "name of AVR model to use when scoring variants"; boolean hasDefault = false; final String modelDirName = Environment.getEnvironmentMap().get(ENVIRONMENT_MODELS_DIR); if (modelDirName != null) { final File modelDir = new File(modelDirName); if (modelDir.exists() && modelDir.isDirectory()) { final String[] models = modelDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.endsWith(".avr"); } }); if (!anonymous && models != null && models.length > 0) { final String[] newModels = new String[models.length + 1]; newModels[0] = AVR_NONE_NAME; System.arraycopy(models, 0, newModels, 1, models.length); description += " (Must be one of " + Arrays.toString(newModels) + " or a path to a model file)"; if (ArrayUtils.contains(newModels, MODEL_DEFAULT)) { hasDefault = true; } } } } final Flag modelFlag = anonymous ? flags.registerRequired(File.class, "file", description) .setCategory(CommonFlagCategories.REPORTING) : flags.registerOptional(AVR_MODEL_FILE_FLAG, File.class, "file", description) .setCategory(CommonFlagCategories.REPORTING); if (!anonymous && hasDefault) { modelFlag.setParameterDefault(MODEL_DEFAULT); } return modelFlag; }
From source file:com.norconex.commons.wicket.markup.html.filesystem.FileSystemTreeProvider.java
@Override public boolean hasChildren(File node) { if (node.isDirectory()) { String[] children = node.list(fileNameFilter); return children != null && children.length > 0; }//www. j a v a2 s. co m return false; }
From source file:mitm.common.pdf.FileFontProvider.java
public FileFontProvider(File fontDir) { Check.notNull(fontDir, "fontDir"); String[] fontFiles = fontDir.list(new SuffixFileFilter(".ttf")); if (fontFiles == null) { fontFiles = new String[] {}; }//from www . j a v a 2 s . c o m fonts = new ArrayList<Font>(fontFiles.length); for (String fontFile : fontFiles) { logger.info("Adding font " + fontFile); try { fonts.add(new Font( BaseFont.createFont(new File(fontDir, fontFile).getPath(), BaseFont.IDENTITY_H, true))); } catch (Throwable e) { logger.error("Error loading font " + fontFile, e); } } }