Example usage for org.apache.commons.io FilenameUtils normalize

List of usage examples for org.apache.commons.io FilenameUtils normalize

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils normalize.

Prototype

public static String normalize(String filename) 

Source Link

Document

Normalizes a path, removing double and single dot path steps.

Usage

From source file:ch.unibas.fittingwizard.infrastructure.RealFitScript.java

public static List<File> getAllFitTabFiles(File rootDir) {
    logger.info("getAllFitTabFiles");
    List<File> files = new ArrayList<>(FileUtils.listFiles(rootDir, new IOFileFilter() {
        @Override//from   w  w  w . ja va2 s .  com
        public boolean accept(File file) {
            return file.getName().endsWith(MtpfittabExtension);
        }

        @Override
        public boolean accept(File dir, String name) {
            return false;
        }
    }, TrueFileFilter.TRUE));

    if (files.size() == 0) {
        throw new ScriptExecutionException("Could not find any fit tab results file in "
                + FilenameUtils.normalize(rootDir.getAbsolutePath()));
    }
    for (File file : files) {
        logger.info("Found fit tab file: " + FilenameUtils.normalize(file.getAbsolutePath()));
    }
    return files;
}

From source file:com.igormaznitsa.sciareto.preferences.FileHistoryManager.java

@Nonnull
private static String packToString(@Nonnull @MustNotContainNull final File[] files) {
    final StringBuilder result = new StringBuilder();
    for (final File f : files) {
        if (result.length() > 0) {
            result.append(File.pathSeparatorChar);
        }/*from  ww  w . j av  a 2  s . c  om*/
        result.append(FilenameUtils.normalize(f.getAbsolutePath()));
    }
    return result.toString();
}

From source file:com.enderville.enderinstaller.util.InstallerConfig.java

/**
 * The location of minecraft.jar.//ww w .ja va  2  s. c o  m
 *
 * @return
 */
public static String getMinecraftJar() {
    return FilenameUtils.normalize(FilenameUtils.concat(getMinecraftFolder(), "bin/minecraft.jar"));
}

From source file:energy.usef.environment.tool.config.ToolConfig.java

public static String getUsefRootFolder() {
    String usefRootFolder = null;
    String currentDirectory = FileUtil.getCurrentFolder();
    if (currentDirectory.endsWith("usef-environment-tool")) {
        usefRootFolder = currentDirectory + File.separator + "..";
    } else {/* w ww  . j  av a 2s .c om*/
        if (currentDirectory.endsWith("target")) {
            usefRootFolder = currentDirectory + File.separator + ".." + File.separator + "..";
        }
    }
    usefRootFolder = FilenameUtils.normalize(usefRootFolder);
    if (!FileUtil.isFolderExists(usefRootFolder)) {
        String error = "Trying to locate USEF environment folder and could not find the folder: "
                + usefRootFolder;
        LOGGER.error(error);
        throw new RuntimeException(error);
    }
    return usefRootFolder;
}

From source file:edu.umn.msi.tropix.storage.core.monitor.StorageMonitorClosureImpl.java

private void registerFile(final File newFile) {
    final String newId = UUID.randomUUID().toString(); // It is perhaps inappropriate to pick id here

    final File rootDirectory = findMatchingDirectory(newFile);
    if (newFile.equals(rootDirectory)) {
        return;/*from   w w w .  j a  v a 2 s  .  co m*/
    }

    final List<String> extractPathList = Lists.newArrayList();
    File parent = newFile.getParentFile();
    while (!rootDirectory.equals(parent)) {
        extractPathList.add(parent.getName());
        parent = parent.getParentFile();
    }
    Collections.reverse(extractPathList);

    final String rootFolderName = monitorConfig.getSharedFolderName(rootDirectory);
    final VirtualFolder rootSharedFolder = folderService.getOrCreateRootVirtualFolderWithName(getIdentity(),
            rootFolderName);
    final VirtualFolder child = folderService.getOrCreateVirtualPath(getIdentity(), rootSharedFolder.getId(),
            Iterables.toArray(extractPathList, String.class));

    final TropixFile tropixFile = new TropixFile();
    tropixFile.setFileId(newId);
    tropixFile.setCommitted(true);
    tropixFile.setName(newFile.getName());
    // TODO: FIX THIS
    // tropixFile.setFileSize(newFile.length());

    tropixFile.setStorageServiceUrl(storageServiceUrl);

    persistentFileMapperService.registerMapping(newId, FilenameUtils.normalize(newFile.getAbsolutePath()));
    final TropixFile returnedFile = tropixObjectService.createFile(getIdentity(), child.getId(), tropixFile,
            null);
    fileService.recordLength(newId, newFile.length());
    tropixObjectService.addToSharedFolder(getIdentity(), returnedFile.getId(), child.getId(), false);
}

From source file:com.enderville.enderinstaller.util.InstallerConfig.java

/**
 * The "mods" folder in the target minecraft installation.
 *
 * @return//  w w  w  .  j  a  va  2s. c  o m
 */
public static String getMinecraftModsFolder() {
    return FilenameUtils.normalize(FilenameUtils.concat(getMinecraftFolder(), "mods"));
}

From source file:com.googlecode.fascinator.portal.services.impl.PortalManagerImpl.java

@Override
public void save(Portal portal) {
    String portalName = portal.getName();

    File portalFile = new File(new File(portalsDir, FilenameUtils.normalize(portalName)), PORTAL_JSON);
    portalFile.getParentFile().mkdirs();
    try {//ww  w .j  a  v  a 2 s  .  c  o m
        FileWriter writer = new FileWriter(portalFile);
        writer.write(portal.toString(true));
        writer.close();
    } catch (IOException ioe) {
    }
}

From source file:cross.io.InputDataFactory.java

/**
 * Create a collection of files from the given string resource paths.
 *
 * @param input the string resource paths
 * @return a collection of files//from  w  w w.j  av a  2  s  .c om
 */
@Override
public Collection<File> getInputFiles(String[] input) {
    LinkedHashSet<File> files = new LinkedHashSet<>();
    for (String inputString : input) {
        log.debug("Processing input string {}", inputString);
        //separate wildcards from plain files
        String name = FilenameUtils.getName(inputString);
        boolean isWildcard = name.contains("?") || name.contains("*");
        String fullPath = FilenameUtils.getFullPath(inputString);
        File path = new File(fullPath);
        File baseDirFile = new File(this.basedir);
        if (!baseDirFile.exists()) {
            throw new ExitVmException("Input base directory '" + baseDirFile + "' does not exist!");
        }
        if (!baseDirFile.isDirectory()) {
            throw new ExitVmException("Input base directory '" + baseDirFile + "' is not a directory!");
        }
        log.debug("Path is absolute: {}", path.isAbsolute());
        //identify absolute and relative files
        if (!path.isAbsolute()) {
            log.info("Resolving relative file against basedir: {}", this.basedir);
            path = new File(this.basedir, fullPath);
        }
        //normalize filenames
        fullPath = FilenameUtils.normalize(path.getAbsolutePath());
        log.debug("After normalization: {}", fullPath);
        IOFileFilter dirFilter = this.recurse ? TrueFileFilter.INSTANCE : null;
        if (isWildcard) {
            log.debug("Using wildcard matcher for {}", name);
            files.addAll(FileUtils.listFiles(new File(fullPath),
                    new WildcardFileFilter(name, IOCase.INSENSITIVE), dirFilter));
        } else {
            log.debug("Using name for {}", name);
            File f = new File(fullPath, name);
            if (!f.exists()) {
                throw new ExitVmException("Input file '" + f + "' does not exist!");
            }
            files.add(f);
        }
    }
    return files;
}

From source file:com.ariht.maven.plugins.config.DirectoryReader.java

private List<File> processFilesToIgnore(final List<String> filesToIgnore) {
    if (filesToIgnore == null || filesToIgnore.isEmpty()) {
        return EMPTY_FILE_LIST;
    }//from ww  w.  j  a va 2s . co m
    final List<File> filesIgnored = new ArrayList<File>(filesToIgnore.size());
    for (String fileToIgnore : new LinkedHashSet<String>(filesToIgnore)) {
        if (StringUtils.isNotBlank(fileToIgnore)) {
            fileToIgnore = FilenameUtils.separatorsToSystem(FilenameUtils.normalize(fileToIgnore.trim()));
            final File file = new File(fileToIgnore);
            if (file.exists()) {
                log.debug("Adding ignore for file: " + file.getAbsolutePath());
                filesIgnored.add(file);
            }
        }
    }
    return filesIgnored;
}

From source file:com.izforge.izpack.util.file.FileUtils.java

/**
 * Removes a leading path from a second path.
 *
 * @param leading The leading path, must not be null, must be absolute.
 * @param path    The path to remove from, must not be null, must be absolute.
 * @return path's normalized absolute if it doesn't start with
 *         leading; path's path with leading's path removed otherwise.
 *//*from   ww w . j a  v  a  2 s  .c  om*/
public static String removeLeadingPath(File leading, File path) throws Exception {
    String l = FilenameUtils.normalize(leading.getAbsolutePath());
    String p = FilenameUtils.normalize(path.getAbsolutePath());
    if (l.equals(p)) {
        return "";
    }

    // ensure that l ends with a /
    // so we never think /foo was a parent directory of /foobar
    if (!l.endsWith(File.separator)) {
        l += File.separator;
    }
    return (p.startsWith(l)) ? p.substring(l.length()) : p;
}