org.apache.commons.io.IOCase Java Examples

The following examples show how to use org.apache.commons.io.IOCase. 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: ImpalaLineageTool.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * This function figures out the right lineage file path+name to process sorted by the last
 * time they are modified. (old -> new)
 * @return get the lineage files from given directory with given prefix.
 */
public File[] getCurrentFiles() {
  try {
    LOG.info("Scanning: " + directoryName);
    File folder = new File(directoryName);
    File[] listOfFiles = folder.listFiles((FileFilter) new PrefixFileFilter(prefix, IOCase.SENSITIVE));

    if ((listOfFiles == null) || (listOfFiles.length == 0)) {
      LOG.info("Found no lineage files.");
      return new File[0];
    }

    if(listOfFiles.length > 1) {
      Arrays.sort(listOfFiles, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
    }

    LOG.info("Found {} lineage files" + listOfFiles.length);
    return listOfFiles;
  } catch(Exception e) {
    LOG.error("Import lineage file failed.", e);
  }
  return new File[0];
}
 
Example #2
Source File: FileAlterationObserver.java    From aion-germany with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #3
Source File: PathAlterationObserver.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
    }
  };
}
 
Example #4
Source File: FilesController.java    From AudioBookConverter with GNU General Public License v2.0 6 votes vote down vote up
private List<String> collectFiles(Collection<File> files) {
    List<String> fileNames = new ArrayList<>();
    ImmutableSet<String> extensions = ImmutableSet.copyOf(FILE_EXTENSIONS);

    for (File file : files) {
        if (file.isDirectory()) {
            SuffixFileFilter suffixFileFilter = new SuffixFileFilter(toSuffixes(".", FILE_EXTENSIONS), IOCase.INSENSITIVE);
            Collection<File> nestedFiles = FileUtils.listFiles(file, suffixFileFilter, TrueFileFilter.INSTANCE);
            nestedFiles.stream().map(File::getPath).forEach(fileNames::add);
        } else {
            boolean allowedFileExtension = extensions.contains(FilenameUtils.getExtension(file.getName()).toLowerCase());
            if (allowedFileExtension) {
                fileNames.add(file.getPath());
            }
        }
    }
    return fileNames;
}
 
Example #5
Source File: FileAlterationObserver.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
    }
}
 
Example #6
Source File: ElasticAgentProfilesAbstractDirective.java    From gocd with Apache License 2.0 5 votes vote down vote up
protected boolean matchesResourceToOperateWithin(String resource) {
    if (equalsIgnoreCase("*", this.resourceToOperateWithin)) {
        return true;
    }

    return FilenameUtils.wildcardMatch(resource, this.resourceToOperateWithin, IOCase.INSENSITIVE);
}
 
Example #7
Source File: FilePathUtil.java    From kalang with MIT License 5 votes vote down vote up
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;
}
 
Example #8
Source File: Generator.java    From synthea with Apache License 2.0 5 votes vote down vote up
private Predicate<String> getModulePredicate() {
  if (options.enabledModules == null) {
    return path -> true;
  }
  FilenameFilter filenameFilter = new WildcardFileFilter(options.enabledModules, 
      IOCase.INSENSITIVE);
  return path -> filenameFilter.accept(null, path);
}
 
Example #9
Source File: ModuleOverrides.java    From synthea with Apache License 2.0 5 votes vote down vote up
/**
 * Create a ModuleOverrides object which will process the modules according to the given options.
 * 
 * @param includeFields - List of field names to include
 * @param includeModulesList - list of module filename rules to include
 * @param excludeFields - list of field names to exclude
 * @param excludeModulesList - list of module filename rules to exclude
 */
public ModuleOverrides(List<String> includeFields, List<String> includeModulesList,
    List<String> excludeFields, List<String> excludeModulesList) {
  this.includeFields = includeFields;
  this.excludeFields = excludeFields;

  if (includeModulesList != null) {
    this.includeModules = new WildcardFileFilter(includeModulesList, IOCase.INSENSITIVE);
  }
  if (excludeModulesList != null) {
    this.excludeModules = new WildcardFileFilter(excludeModulesList, IOCase.INSENSITIVE);
  }
}
 
Example #10
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenGetFilewith_ANDFileFilter_thenFindsampletxt() throws IOException {

    String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();
    File dir = FileUtils.getFile(FilenameUtils.getFullPath(path));

    Assert.assertEquals("sample.txt", dir.list(new AndFileFilter(new WildcardFileFilter("*ple*", IOCase.INSENSITIVE), new SuffixFileFilter("txt")))[0]);
}
 
Example #11
Source File: NameFileFilter.java    From aion-germany with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: RangerServiceAtlas.java    From ranger with Apache License 2.0 5 votes vote down vote up
boolean emptyOrContainsMatch(List<String> list, String value) {
	if (list == null || list.isEmpty()) {
		return true;
	}

	for (String item : list) {
		if (StringUtils.equalsIgnoreCase(item, value) || FilenameUtils.wildcardMatch(value, item, IOCase.INSENSITIVE)) {
			return true;
		}
	}

	return false;
}
 
Example #13
Source File: CommonUtils.java    From sahagin-java with Apache License 2.0 5 votes vote down vote up
private static boolean filePathEquals(String path1, String path2) {
    // Mac is case-insensitive, but IOCase.SYSTEM.isCaseSenstive returns true,
    // so don't use this value for Mac.
    // (TODO but Mac can become case-sensitive if an user changes system setting..)
    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX) {
        return StringUtils.equalsIgnoreCase(path1, path2);
    }
    if (IOCase.SYSTEM.isCaseSensitive()) {
        return StringUtils.equals(path1, path2);
    } else {
        return StringUtils.equalsIgnoreCase(path1, path2);
    }
}
 
Example #14
Source File: AbstractDirective.java    From gocd with Apache License 2.0 5 votes vote down vote up
protected boolean matchesResource(String resource) {
    if (equalsIgnoreCase("*", this.resource)) {
        return true;
    }

    return FilenameUtils.wildcardMatch(resource, this.resource, IOCase.INSENSITIVE);
}
 
Example #15
Source File: ImportWorker.java    From magarena with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a filter that returns everything in the "mods" folder except
 * the specified cubes which are distributed with each new release and
 * any existing themes which are now found in the "themes" folder.
 */
private FileFilter getModsFileFilter() {
    final String[] excludedCubes = new String[]{
        "legacy_cube.txt", "modern_cube.txt", "standard_cube.txt", "extended_cube.txt", "ubeefx_cube.txt"
    };
    final IOFileFilter cubesFilter = new NameFileFilter(excludedCubes, IOCase.INSENSITIVE);
    final IOFileFilter excludeCubes = FileFilterUtils.notFileFilter(cubesFilter);
    final IOFileFilter excludeThemes = FileFilterUtils.notFileFilter(new WildcardFileFilter("*_theme*"));
    return FileFilterUtils.and(excludeCubes, excludeThemes);
}
 
Example #16
Source File: WildcardFileFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenSortDirWithPathFileComparator_thenFirstFileaaatxt() throws IOException {

    PathFileComparator pathFileComparator = new PathFileComparator(IOCase.INSENSITIVE);
    String path = FilenameUtils.getFullPath(getClass().getClassLoader().getResource("fileTest.txt").getPath());
    File dir = new File(path);
    File[] files = dir.listFiles();

    pathFileComparator.sort(files);

    Assert.assertEquals("aaa.txt", files[0].getName());
}
 
Example #18
Source File: WildcardFileFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source File: DistributionUpdater.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
public static File getWindupDistributionSubdir(File tempFolder) throws WindupException
{
    File[] matchingDirs = tempFolder.listFiles((FilenameFilter) FileFilterUtils.prefixFileFilter("windup-distribution-", IOCase.INSENSITIVE));
    if (matchingDirs.length == 0)
        return null;
    return matchingDirs[0];
}
 
Example #20
Source File: NameFileFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #21
Source File: NameFileFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source File: GoServer.java    From gocd with Apache License 2.0 5 votes vote down vote up
private List<File> getAddonJarFiles() {
    File addonsPath = new File(systemEnvironment.get(SystemEnvironment.ADDONS_PATH));
    if (!addonsPath.exists() || !addonsPath.canRead()) {
        return new ArrayList<>();
    }

    return new ArrayList<>(FileUtils.listFiles(addonsPath, new SuffixFileFilter("jar", IOCase.INSENSITIVE), FalseFileFilter.INSTANCE));
}
 
Example #23
Source File: RegexFileFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #24
Source File: WMRouterTransform.java    From WMRouter with Apache License 2.0 5 votes vote down vote up
/**
 * 扫描由注解生成器生成到包 {@link Const#GEN_PKG_SERVICE} 里的初始化类
 */
private void scanDir(File dir, Set<String> initClasses) throws IOException {
    File packageDir = new File(dir, INIT_SERVICE_DIR);
    if (packageDir.exists() && packageDir.isDirectory()) {
        Collection<File> files = FileUtils.listFiles(packageDir,
                new SuffixFileFilter(SdkConstants.DOT_CLASS, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE);
        for (File f : files) {
            String className = trimName(f.getAbsolutePath(), dir.getAbsolutePath().length() + 1)
                    .replace(File.separatorChar, '.');
            initClasses.add(className);
            WMRouterLogger.info("    find ServiceInitClass: %s", className);
        }
    }
}
 
Example #25
Source File: RangerAbstractResourceMatcher.java    From ranger with Apache License 2.0 4 votes vote down vote up
@Override
boolean isMatch(String resourceValue, Map<String, Object> evalContext) {
	return FilenameUtils.wildcardMatch(resourceValue, getExpandedValue(evalContext), IOCase.SENSITIVE);
}
 
Example #26
Source File: BatchFileLookupableHelperServiceImpl.java    From kfs with GNU Affero General Public License v3.0 4 votes vote down vote up
protected IOFileFilter getFileNameBasedFilter(String fileNamePattern) {
    if (StringUtils.isNotBlank(fileNamePattern)) {
        return new WildcardFileFilter(fileNamePattern, IOCase.INSENSITIVE);
    }
    return null;
}
 
Example #27
Source File: GameDataFileUtilsTest.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private boolean isCandidateFileName(final String fileName) {
  return GameDataFileUtils.isCandidateFileName(fileName, IOCase.SENSITIVE);
}
 
Example #28
Source File: GameDataFileUtilsTest.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
private String addExtensionIfAbsent(final String fileName) {
  return GameDataFileUtils.addExtensionIfAbsent(fileName, IOCase.INSENSITIVE);
}
 
Example #29
Source File: GameDataFileUtils.java    From triplea with GNU General Public License v3.0 4 votes vote down vote up
@VisibleForTesting
static boolean isCandidateFileName(final String fileName, final IOCase ioCase) {
  return getCandidateExtensions().stream()
      .anyMatch(extension -> ioCase.checkEndsWith(fileName, extension));
}
 
Example #30
Source File: NameFileComparator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Construct a case sensitive file name comparator instance.
 */
public NameFileComparator() {
    this.caseSensitivity = IOCase.SENSITIVE;
}