Example usage for org.apache.commons.io IOCase SYSTEM

List of usage examples for org.apache.commons.io IOCase SYSTEM

Introduction

In this page you can find the example usage for org.apache.commons.io IOCase SYSTEM.

Prototype

IOCase SYSTEM

To view the source code for org.apache.commons.io IOCase SYSTEM.

Click Source Link

Document

The constant for case sensitivity determined by the current operating system.

Usage

From source file:com.sangupta.andruil.utils.ArgumentUtils.java

/**
 * Resolve the supplied file argument which may contain wildcards
 * to a list of all valid files./*from  w w w .  j av  a 2  s  .c o m*/
 * 
 * @param arg
 * @return
 */
public static File[] resolveFiles(final File currentDir, String arg) {
    if (arg == null) {
        return null;
    }

    if (!hasWildcards(arg)) {
        File file = new File(currentDir, arg);
        return new File[] { file };
    }

    // the argument does have wild cards
    // resolve it
    FileFilter wildcardFileFilter = new WildcardFileFilter(arg, IOCase.SYSTEM);
    File[] files = currentDir.listFiles(wildcardFileFilter);
    return files;
}

From source file:com.github.neio.filesystem.paths.DirectoryPath.java

@Override
protected boolean amIEqual(Directory path) {
    return FilenameUtils.equals(super.path, path.getPath(), true, IOCase.SYSTEM);
}

From source file:com.sangupta.codefix.AbstractCodeFixCommand.java

/**
 * Get a list of all matched files/*from   ww w  . j  ava2s .c  o  m*/
 * 
 * @return
 */
protected List<File> getMatchedFiles() {
    if (this.workingFolder == null || this.workingFolder.isEmpty()) {
        this.workingFolder = ".";
    }

    final File currentDir = new File(this.workingFolder);
    if (!currentDir.exists() || !currentDir.isDirectory()) {
        System.out.println("Directory does not exists: " + this.workingFolder);
        return null;
    }

    final FileFilter wildcardFileFilter = new WildcardFileFilter(this.pattern, IOCase.SYSTEM);

    if (!this.recursive) {
        File[] files = currentDir.listFiles(wildcardFileFilter);
        return Arrays.asList(files);
    }

    // we need to go recursive
    List<File> files = new ArrayList<File>();
    getMatchedFiles(files, currentDir, wildcardFileFilter);

    return files;
}

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. ja v  a 2 s .  c  o m*/
 * @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:com.moneydance.modules.features.importlist.io.FileAdmin.java

private void setFileMonitorToCurrentImportDir() {
    if (this.getBaseDirectory() == null) {
        return;/* ww  w.j a  v  a 2 s .c  om*/
    }
    this.observer = new FileAlterationObserver(this.getBaseDirectory(), this.readableFileFilter, IOCase.SYSTEM);
    this.observer.addListener(this.listener);
    this.monitor.addObserver(this.observer);
}

From source file:BackupService.java

/**
 * Create filter for finding files. Compile one filter using or operator.
 * <p/>/*from   www . ja v a2 s  .c o m*/
 * Example: list of texts: *.bak, *.o -> object repsents: *.bak or *.o
 *
 * @param excludes list of user defined wildcard filters
 *
 * @return It takes into account lists
 */
private IOFileFilter getWildcardsFilter(List<String> excludes) {
    IOFileFilter result;
    if (CollectionUtils.isNotEmpty(excludes)) {
        List<IOFileFilter> fileFilterList = new ArrayList<>(excludes.size());
        for (String exclude : excludes) {
            fileFilterList.add(new WildcardFileFilter(exclude, IOCase.SYSTEM));
        }
        //noinspection SuspiciousToArrayCall
        final IOFileFilter orFiler = FileFilterUtils
                .or(fileFilterList.toArray(new WildcardFileFilter[excludes.size()]));
        result = FileFilterUtils.notFileFilter(orFiler);
    } else {
        result = FileFilterUtils.trueFileFilter();
    }
    return result;
}

From source file:com.sangupta.jerry.util.FileUtils.java

/**
 * List the files in the given path string with wild cards.
 * /* w  w w .j a  v  a2 s .c o m*/
 * @param baseDir
 *            the base directory to search for files in
 * 
 * @param filePathWithWildCards
 *            the file path to search in - can be absolute
 * 
 * @param recursive
 *            whether to look in sub-directories or not
 * 
 * @param additionalFilters
 *            additional file filters that need to be used when scanning for
 *            files
 * 
 * @return the list of files and directories that match the criteria
 */
public static List<File> listFiles(File baseDir, String filePathWithWildCards, boolean recursive,
        List<IOFileFilter> additionalFilters) {
    if (filePathWithWildCards == null) {
        throw new IllegalArgumentException("Filepath cannot be null");
    }

    // change *.* to *
    filePathWithWildCards = filePathWithWildCards.replace("*.*", "*");

    // normalize
    filePathWithWildCards = FilenameUtils.normalize(filePathWithWildCards);

    if (filePathWithWildCards.endsWith(File.pathSeparator)) {
        filePathWithWildCards += "*";
    }

    // check if this is an absolute path or not
    String prefix = FilenameUtils.getPrefix(filePathWithWildCards);
    final boolean isAbsolute = !prefix.isEmpty();

    // change the base dir if absolute directory
    if (isAbsolute) {
        baseDir = new File(filePathWithWildCards);
        if (!baseDir.isDirectory()) {
            // not a directory - get the base directory
            filePathWithWildCards = baseDir.getName();
            if (filePathWithWildCards.equals("~")) {
                filePathWithWildCards = "*";
            }

            if (AssertUtils.isEmpty(filePathWithWildCards)) {
                filePathWithWildCards = "*";
            }

            baseDir = baseDir.getParentFile();
            if (baseDir == null) {
                baseDir = getUsersHomeDirectory();
            }
        }
    }

    // check if the provided argument is a directory
    File dir = new File(filePathWithWildCards);
    if (dir.isDirectory()) {
        baseDir = dir.getAbsoluteFile();
        filePathWithWildCards = "*";
    } else {
        // let's check for base directory
        File parent = dir.getParentFile();
        if (parent != null) {
            baseDir = parent.getAbsoluteFile();
            filePathWithWildCards = dir.getName();
        }
    }

    // check for user home
    String basePath = baseDir.getPath();
    if (basePath.startsWith("~")) {
        basePath = getUsersHomeDirectory().getAbsolutePath() + File.separator + basePath.substring(1);
        basePath = FilenameUtils.normalize(basePath);
        baseDir = new File(basePath);
    }

    // now read the files
    WildcardFileFilter wildcardFileFilter = new WildcardFileFilter(filePathWithWildCards, IOCase.SYSTEM);
    IOFileFilter finalFilter = wildcardFileFilter;
    if (AssertUtils.isNotEmpty(additionalFilters)) {
        additionalFilters.add(0, wildcardFileFilter);
        finalFilter = new AndFileFilter(additionalFilters);
    }

    Collection<File> files = org.apache.commons.io.FileUtils.listFiles(baseDir, finalFilter,
            recursive ? TrueFileFilter.INSTANCE : FalseFileFilter.INSTANCE);

    return (List<File>) files;
}

From source file:com.matteoveroni.model.copy.FilenameUtils.java

/**
 * Determines whether the {@code parent} directory contains the {@code child} element (a file or directory).
 * <p>//  ww  w  .  j a  v a  2s  .  com
 * The files names are expected to be normalized.
 * </p>
 * 
 * Edge cases:
 * <ul>
 * <li>A {@code directory} must not be null: if null, throw IllegalArgumentException</li>
 * <li>A directory does not contain itself: return false</li>
 * <li>A null child file is not contained in any parent: return false</li>
 * </ul>
 * 
 * @param canonicalParent
 *            the file to consider as the parent.
 * @param canonicalChild
 *            the file to consider as the child.
 * @return true is the candidate leaf is under by the specified composite. False otherwise.
 * @throws IOException
 *             if an IO error occurs while checking the files.
 * @since 2.2
 * @see FileUtils#directoryContains(File, File)
 */
public static boolean directoryContains(final String canonicalParent, final String canonicalChild)
        throws IOException {

    // Fail fast against NullPointerException
    if (canonicalParent == null) {
        throw new IllegalArgumentException("Directory must not be null");
    }

    if (canonicalChild == null) {
        return false;
    }

    if (IOCase.SYSTEM.checkEquals(canonicalParent, canonicalChild)) {
        return false;
    }

    return IOCase.SYSTEM.checkStartsWith(canonicalChild, canonicalParent);
}

From source file:com.github.aliteralmind.codelet.util.FilenameBlackWhiteList.java

/**
   <p>Creates a new white-or-blacklist from a set of string-variables as found in a configuration text file.</p>
        //from   ww  w.  j  a v a  2  s. co m
 * @param  black_white_off  Is this a {@linkplain com.github.aliteralmind.codelet.util.BlackOrWhite#BLACK blacklist}, {@linkplain com.github.aliteralmind.codelet.util.BlackOrWhite#WHITE whitelist}, or nothing? Must be {@code "black"}, {@code "white"}, or {@code "off"} (the case of this parameter's value is ignored). If {@code "off"}, this function <i><b>returns</b></i> a new {@code FilenameBlackWhiteList} that {@linkplain #newForAcceptAll(Appendable) accepts everything}.
 * @param  ignore_require_system  Should case be {@linkplain org.apache.commons.io.IOCase#INSENSITIVE ignored}, {@linkplain org.apache.commons.io.IOCase#SENSITIVE <i>not</i> ignored}, or determined by the operating {@linkplain org.apache.commons.io.IOCase#SYSTEM system}? Must be {@code "ignore"}, {@code "require"}, or {@code "system"} (the case of <i>this parameter's value</i> is ignored).
 * @param  separator  The character used to separate each proper and override value. Such as a comma ({@code ","}), {@linkplain com.github.xbn.lang.XbnConstants#LINE_SEP line-separator} ({@code "\r\n"}), or tab ({@code "\t"}). May not be {@code null}, empty, or contain any letters, digits, underscores ({@code '_'}), question-marks ({@code '?'}), or asterisks ({@code '*'}).
 * @param  separated_propers  The separated list of &quot;proper&quot; items. Must be separated by {@code separator}, and otherwise must conform to the restrictions for the {@link #FilenameBlackWhiteList(BlackOrWhite, IOCase, String[], String[], Appendable) proper_items} constructor parameter.
 * @param  separated_overrides  The separated list of override items. Must be non-{@code null} (if none, this must be the empty string: {@code ""}), separated by {@code separator}, and otherwise must conform to the restrictions for the {@code override_items} constructor parameter.
 * @see  #newFromProperties(Properties, String, String, String, String, String, Appendable, Appendable) newFromProperties
 */
public static final FilenameBlackWhiteList newFromConfigStringVars(String black_white_off,
        String ignore_require_system, String separator, String separated_propers, String separated_overrides,
        Appendable dbgLoading_ifNonNull, Appendable dbgAccept_ifNonNull) {
    TextAppenter dbgAptr = NewTextAppenterFor.appendableUnusableIfNull(dbgLoading_ifNonNull);

    if (dbgAptr.isUseable()) {
        dbgAptr.appentln("FilenameBlackWhiteList newFromConfigStringVars:");
    }

    try {
        if (black_white_off.toLowerCase().equals("off")) {
            if (dbgAptr.isUseable()) {
                dbgAptr.appentln(" - newForAcceptAll(dbgAccept_ifNonNull). DONE");
            }
            return newForAcceptAll(dbgAccept_ifNonNull);
        }
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(black_white_off, "black_white_off", null, rx);
    }

    BlackOrWhite bw = EnumUtil.toValueWithNullDefault(black_white_off, "black_white_off", IgnoreCase.YES,
            DefaultValueFor.NOTHING, BlackOrWhite.BLACK);

    if (dbgAptr.isUseable()) {
        dbgAptr.appentln(" - BlackOrWhite." + bw);
    }

    IOCase ioc = null;
    try {
        switch (ignore_require_system.toUpperCase()) {
        case "IGNORE":
            ioc = IOCase.INSENSITIVE;
            break;
        case "REQUIRE":
            ioc = IOCase.SENSITIVE;
            break;
        case "SYSTEM":
            ioc = IOCase.SYSTEM;
            break;
        default:
            throw new IllegalArgumentException(
                    "ignore_require_system.toUpperCase() (\"" + ignore_require_system.toUpperCase()
                            + "\") does not equal \"IGNORE\", \"REQUIRE\", or \"SYSTEM\".");
        }
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(ignore_require_system, "ignore_require_system", null, rx);
    }

    if (dbgAptr.isUseable()) {
        dbgAptr.appentln(" - IOCase." + ioc);
    }

    CrashIfString.nullEmpty(separator, "separator", null);
    if (Pattern.compile("[?*\\w]").matcher(separator).find()) {
        throw new IllegalArgumentException("separator (\"" + separator + "\") contains an illegal character.");
    }

    if (dbgAptr.isUseable()) {
        dbgAptr.appentln(" - separator valid: \"" + separator + "\"");
    }

    String[] propers = null;
    try {
        propers = separated_propers.split(separator);
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(separated_propers, "separated_propers", null, rx);
    }

    if (dbgAptr.isUseable()) {
        dbgAptr.appentln(" - Propers: " + Arrays.toString(propers));
    }

    String[] overrides = null;
    try {
        if (separated_overrides.length() == 0) {
            overrides = EMPTY_STRING_ARRAY;
        } else {
            overrides = separated_overrides.split(separator);
        }
    } catch (RuntimeException rx) {
        throw CrashIfObject.nullOrReturnCause(separated_overrides, "separated_overrides", null, rx);
    }

    if (dbgAptr.isUseable()) {
        dbgAptr.appentln(" - Overrides: " + Arrays.toString(overrides) + "...DONE");
    }

    return new FilenameBlackWhiteList(bw, ioc, propers, overrides, dbgAccept_ifNonNull);
}

From source file:com.matteoveroni.model.copy.FilenameUtils.java

/**
 * Checks whether two filenames are equal using the case rules of the system.
 * <p>/* w  w  w.j a  v  a2s .  c o m*/
 * No processing is performed on the filenames other than comparison.
 * The check is case-sensitive on Unix and case-insensitive on Windows.
 *
 * @param filename1  the first filename to query, may be null
 * @param filename2  the second filename to query, may be null
 * @return true if the filenames are equal, null equals null
 * @see IOCase#SYSTEM
 */
public static boolean equalsOnSystem(String filename1, String filename2) {
    return equals(filename1, filename2, false, IOCase.SYSTEM);
}