/** * Construct an observer for the specified directory, file filter and * file comparator. * * @param rootEntry the root directory to observe * @param fileFilter The file filter or null if none * @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive */ protected FileAlterationObserver(FileEntry rootEntry, FileFilter fileFilter, IOCase caseSensitivity) { if (rootEntry == null) { throw new IllegalArgumentException("Root entry is missing"); } if (rootEntry.getFile() == null) { throw new IllegalArgumentException("Root directory is missing"); } this.rootEntry = rootEntry; this.fileFilter = fileFilter; if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) { this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR; } else if (caseSensitivity.equals(IOCase.INSENSITIVE)) { this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR; } else { this.comparator = NameFileComparator.NAME_COMPARATOR; } }
/** * Gets the models. * * @return the models */ public static String[] getModels() { File dir = new File(Config.getConfiguration().getString(MODELPATH)); LOG.info("Loading Models from... " + dir.getAbsolutePath()); List<String> models = new ArrayList<>(); String[] modelNames = getModelNames(); List<String> wildCardPath = Arrays.stream(modelNames).map(model -> { return "en-ner-" + model + "*.bin"; }).collect(Collectors.toList()); FileFilter fileFilter = new WildcardFileFilter(wildCardPath, IOCase.INSENSITIVE); List<String> filePath = Arrays.asList(dir.listFiles(fileFilter)) .stream().map(file -> file.getAbsolutePath()) .collect(Collectors.toList()); return filePath.toArray(new String[filePath.size()]); }
/** * Gets the models. This method is used if ModelPath is passed as parameter. * * * @return the models */ public static String[] getModels(String modelDirectory) { File dir = new File(modelDirectory); LOG.info("Loading Models from... " + dir.getAbsolutePath()); List<String> models = new ArrayList<>(); String[] modelNames = getModelNames(); List<String> wildCardPath = Arrays.stream(modelNames).map(model -> { return "en-ner-" + model + "*.bin"; }).collect(Collectors.toList()); FileFilter fileFilter = new WildcardFileFilter(wildCardPath, IOCase.INSENSITIVE); List<String> filePath = Arrays.asList(dir.listFiles(fileFilter)) .stream().map(file -> file.getAbsolutePath()) .collect(Collectors.toList()); return filePath.toArray(new String[filePath.size()]); }
/** * Construct an observer for the specified directory, file filter and * file comparator. * * @param rootEntry the root directory to observe * @param fileFilter The file filter or null if none * @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive */ protected FileAlterationObserver(final FileEntry rootEntry, final FileFilter fileFilter, final IOCase caseSensitivity) { if (rootEntry == null) { throw new IllegalArgumentException("Root entry is missing"); } if (rootEntry.getFile() == null) { throw new IllegalArgumentException("Root directory is missing"); } this.rootEntry = rootEntry; this.fileFilter = fileFilter; if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) { this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR; } else if (caseSensitivity.equals(IOCase.INSENSITIVE)) { this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR; } else { this.comparator = NameFileComparator.NAME_COMPARATOR; } }
/** The extension for the given file. */ public static Optional<FileExt> forFile(String path) { int n = path.length(); int dot = path.lastIndexOf('.'); if (dot < 0 || dot + 1 == n) { return Optional.absent(); } for (int i = dot + 1; i < n; ++i) { char ch = path.charAt(i); if (ch == '/' || ch == '\\') { return Optional.absent(); } } String ext = path.substring(dot + 1); if (IOCase.SYSTEM.isCaseSensitive()) { // TODO: This may not do the right thing on Mac. // TODO: Should this be done in valueOf? ext = ext.toLowerCase(Locale.ENGLISH); // No locale-specific folding } return Optional.of(valueOf(ext)); }
public static List<String> findFilesToAnalyze(String dirPath) { IOFileFilter gitFilter = FileFilterUtils.notFileFilter( FileFilterUtils.nameFileFilter(".git") ); File dir = new File(dirPath); String[] phpExt = new String[] {"php"}; IOFileFilter phpFilter = new SuffixFileFilter(phpExt, IOCase.INSENSITIVE); List<File> files = (List<File>) FileUtils.listFiles(dir, phpFilter, gitFilter); List<String> results = new ArrayList<String>(); for (File f : files) { try { results.add(f.getCanonicalPath()); } catch (IOException e) { e.printStackTrace(); } } return results; }
/** * Checks whether two filenames are equal, optionally normalizing and providing * control over the case-sensitivity. * * @param filename1 the first filename to query, may be null * @param filename2 the second filename to query, may be null * @param normalized whether to normalize the filenames * @param caseSensitivity what case sensitivity rule to use, null means case-sensitive * @return true if the filenames are equal, null equals null * @since 1.3 */ public static boolean equals( String filename1, String filename2, boolean normalized, IOCase caseSensitivity) { if (filename1 == null || filename2 == null) { return filename1 == null && filename2 == null; } if (normalized) { filename1 = normalize(filename1); filename2 = normalize(filename2); if (filename1 == null || filename2 == null) { throw new NullPointerException( "Error normalizing one or both of the file names"); } } if (caseSensitivity == null) { caseSensitivity = IOCase.SENSITIVE; } return caseSensitivity.checkEquals(filename1, filename2); }
/** * Construct an observer for the specified directory, file filter and * file comparator. * * @param rootEntry the root directory to observe * @param fileFilter The file filter or null if none * @param caseSensitivity what case sensitivity to use comparing file names, null means system sensitive */ protected FileAlterationObserver(FileEntry rootEntry, FileFilter fileFilter, IOCase caseSensitivity, boolean circulate) { if (rootEntry == null) { throw new IllegalArgumentException("Root entry is missing"); } if (rootEntry.getFile() == null) { throw new IllegalArgumentException("Root directory is missing"); } this.rootEntry = rootEntry; this.fileFilter = fileFilter; this.circulate = circulate; if (caseSensitivity == null || caseSensitivity.equals(IOCase.SYSTEM)) { this.comparator = NameFileComparator.NAME_SYSTEM_COMPARATOR; } else if (caseSensitivity.equals(IOCase.INSENSITIVE)) { this.comparator = NameFileComparator.NAME_INSENSITIVE_COMPARATOR; } else { this.comparator = NameFileComparator.NAME_COMPARATOR; } }
/** * The comparison between path is always case-sensitive in this general file system context. */ public PathAlterationObserver(final FileStatusEntry rootEntry, final PathFilter pathFilter) throws IOException { if (rootEntry == null) { throw new IllegalArgumentException("Root entry is missing"); } if (rootEntry.getPath() == null) { throw new IllegalArgumentException("Root directory is missing"); } this.rootEntry = rootEntry; this.pathFilter = pathFilter; this.fs = rootEntry.getPath().getFileSystem(new Configuration()); // By default, the comparsion is case sensitive. this.comparator = new Comparator<Path>() { @Override public int compare(Path o1, Path o2) { return IOCase.SENSITIVE.checkCompareTo(o1.toUri().toString(), o2.toUri().toString()); } }; }
public VFSManager(File systemDir, File userDir) { super(systemDir, userDir, new SuffixFileFilter(".xml", IOCase.INSENSITIVE)); Comparator<File> nameComparator = new Comparator<File>() { @Override public int compare(File f1, File f2) { // we want vfs.xml to loaded first, always. if (f1.getName().equals("x-vfs.xml")) return Integer.MIN_VALUE; if (f2.getName().equals("x-vfs.xml")) return Integer.MAX_VALUE; return f1.getName().compareToIgnoreCase(f2.getName()); } }; getSystemFiles().setNameComparator(nameComparator); }
public static void buildTrainingDataFromCorpus(String dataSetName, File corpusRoot, FVGenerator fvGenerator, File dest) throws IOException { Collection<File> children = FileUtils.listFiles(corpusRoot, new RegexFileFilter(".+\\.txt", IOCase.INSENSITIVE), DirectoryFileFilter.INSTANCE); ArffSaver saver = new ArffSaver(); saver.setFile(dest); saver.setRetrieval(Saver.INCREMENTAL); boolean first = true; for (File textFile : children) { Instances dataSet = buildTrainingDataFromFile(dataSetName, textFile, fvGenerator); if (first) { saver.setStructure(dataSet); first = false; } for (int i = 0; i < dataSet.numInstances(); ++i) { saver.writeIncremental(dataSet.instance(i)); } } saver.getWriter().flush(); }
/** * Construct a new regular expression filter with the specified flags case sensitivity. * * @param pattern regular string expression to match * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ public RegexFileFilter(String pattern, IOCase caseSensitivity) { if (pattern == null) { throw new IllegalArgumentException("Pattern is missing"); } int flags = 0; if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) { flags = Pattern.CASE_INSENSITIVE; } this.pattern = Pattern.compile(pattern, flags); }
/** * Construct a new name file filter specifying case-sensitivity. * * @param name the name to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the name is null */ public NameFileFilter(String name, IOCase caseSensitivity) { if (name == null) { throw new IllegalArgumentException("The wildcard must not be null"); } this.names = new String[] {name}; this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity); }
/** * Construct a new wildcard filter for a single wildcard specifying case-sensitivity. * * @param wildcard the wildcard to match, not null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ public WildcardFileFilter(String wildcard, IOCase caseSensitivity) { if (wildcard == null) { throw new IllegalArgumentException("The wildcard must not be null"); } this.wildcards = new String[] { wildcard }; this.caseSensitivity = (caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity); }
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; }
/** * Construct a new name file filter specifying case-sensitivity. * * @param name the name to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the name is null */ public NameFileFilter(String name, IOCase caseSensitivity) { if (name == null) { throw new IllegalArgumentException("The wildcard must not be null"); } this.names = new String[] {name}; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; }
/** * Construct a new wildcard filter for a single wildcard specifying case-sensitivity. * * @param wildcard the wildcard to match, not null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ public WildcardFileFilter(String wildcard, IOCase caseSensitivity) { if (wildcard == null) { throw new IllegalArgumentException("The wildcard must not be null"); } this.wildcards = new String[] { wildcard }; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; }
/** * 查找需要合并文件的临时文件信息 * * @param directory 临时文件所在的目录 * @param prefix 临时文件的前缀 * @param caseSensitivity 临时文件的大小写敏感 * @return collection */ public static Collection<File> searchPrefixFile(File directory, String prefix, boolean caseSensitivity) { IOCase iocase = IOCase.INSENSITIVE; if (caseSensitivity) { iocase = IOCase.SENSITIVE; } //创建相关的过滤器 IOFileFilter fileFilter = FileFilterUtils.prefixFileFilter(prefix, iocase); //检查相关的过滤信息 return FileUtils.listFiles(directory, fileFilter, FalseFileFilter.INSTANCE); }
public static String[] getModels(String[] modelNames) { File dir = new File(Config.getConfiguration().getString(MODELPATH)); LOG.info("Loading Models from... " + dir.getAbsolutePath()); List<String> wildCardPath = Arrays.stream(modelNames).map(model -> { return "en-ner-" + model + "*.bin"; }).collect(Collectors.toList()); FileFilter fileFilter = new WildcardFileFilter(wildCardPath, IOCase.INSENSITIVE); List<String> filePath = Arrays.asList(dir.listFiles(fileFilter)) .stream().map(file -> file.getAbsolutePath()) .collect(Collectors.toList()); return filePath.toArray(new String[filePath.size()]); }
/** * Construct a new regular expression filter with the specified flags case sensitivity. * * @param pattern regular string expression to match * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ public RegexFileFilter(final String pattern, final IOCase caseSensitivity) { if (pattern == null) { throw new IllegalArgumentException("Pattern is missing"); } int flags = 0; if (caseSensitivity != null && !caseSensitivity.isCaseSensitive()) { flags = Pattern.CASE_INSENSITIVE; } this.pattern = Pattern.compile(pattern, flags); }
/** * Construct a new name file filter specifying case-sensitivity. * * @param name the name to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the name is null */ public NameFileFilter(final String name, final IOCase caseSensitivity) { if (name == null) { throw new IllegalArgumentException("The wildcard must not be null"); } this.names = new String[] {name}; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; }
/** * Constructs a new name file filter for an array of names specifying case-sensitivity. * * @param names the names to allow, must not be null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the names array is null */ public NameFileFilter(final String[] names, final IOCase caseSensitivity) { if (names == null) { throw new IllegalArgumentException("The array of names must not be null"); } this.names = new String[names.length]; System.arraycopy(names, 0, this.names, 0, names.length); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; }
/** * Construct a new wildcard filter for a single wildcard specifying case-sensitivity. * * @param wildcard the wildcard to match, not null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern is null */ public WildcardFileFilter(final String wildcard, final IOCase caseSensitivity) { if (wildcard == null) { throw new IllegalArgumentException("The wildcard must not be null"); } this.wildcards = new String[] { wildcard }; this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; }
/** * Construct a new wildcard filter for an array of wildcards specifying case-sensitivity. * <p> * * @param wildcards the array of wildcards to match, not null * @param caseSensitivity how to handle case sensitivity, null means case-sensitive * @throws IllegalArgumentException if the pattern array is null */ public WildcardFileFilter(final String[] wildcards, final IOCase caseSensitivity) { if (wildcards == null) { throw new IllegalArgumentException("The wildcard array must not be null"); } this.wildcards = new String[wildcards.length]; System.arraycopy(wildcards, 0, this.wildcards, 0, wildcards.length); this.caseSensitivity = caseSensitivity == null ? IOCase.SENSITIVE : caseSensitivity; }
public static boolean existFile(File srcFile) { String absPath = srcFile.getAbsolutePath(); if (srcFile.exists()) { String canonicalPath; try { canonicalPath = srcFile.getCanonicalPath(); } catch (IOException ex) { return false; } return FilenameUtils.equals(canonicalPath, absPath, true, IOCase.SENSITIVE); } return false; }
private File getJavaSouceFile(FixtureDescription fixture, MetaInformation metaInformation, File fixtureSourceDirectory, String packageName) throws IOException { String fixtureFilename = fixture.getName() + JAVA_EXTENSION; File javaSouceFile = null; // we search in every imports List<String> imports = metaInformation.getImports(); for (String anImport : imports) { File packageDir = new File(fixtureSourceDirectory, replaceChars(anImport, DOT, separatorChar)); if (packageDir.isDirectory()) { Collection<File> files = listFiles(packageDir, new NameFileFilter(fixtureFilename, IOCase.INSENSITIVE), null); if (files.size() == 1) { javaSouceFile = files.iterator().next(); break; } else if (files.size() > 1) { LOGGER.error("You have multiple java sources with the same case insensitive names."); LOGGER.error("We can't choose the file to merge the fixture in."); LOGGER.error("Moreover, your build is platform dependant because of this issue."); LOGGER.error("Incriminating files:"); for (File file : files) { LOGGER.error("\t - {}", file.getAbsolutePath()); } break; } } } // if we didn't find the file if (javaSouceFile == null) { if (isNotBlank(packageName)) { File directoryForFixure = new File(fixtureSourceDirectory, replaceChars(packageName, DOT, separatorChar)); forceMkdir(directoryForFixure); javaSouceFile = new File(directoryForFixure, fixtureFilename); } else { forceMkdir(fixtureSourceDirectory); javaSouceFile = new File(fixtureSourceDirectory, fixtureFilename); LOGGER.warn("You have no default package defined. I can't choose any import packages. Generating the Fixture in the source root. This is generally not a good idea."); } } return javaSouceFile ; }