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

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

Introduction

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

Prototype

public static String getFullPathNoEndSeparator(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path, and also excluding the final directory separator.

Usage

From source file:com.kamike.misc.FsNameUtils.java

public static String getIncomingName(String fileName) {
    String name = FilenameUtils.getFullPathNoEndSeparator(fileName);
    ////  ww w .j a  v a 2s .  c o  m
    int end = FilenameUtils.indexOfLastSeparator(name);
    String parent = name.substring(end);
    int lastEnd = FilenameUtils.indexOfLastSeparator(parent);
    return parent.substring(lastEnd, end);
}

From source file:de.tudarmstadt.ukp.dkpro.keyphrases.bookindexing.util.SerializationUtils.java

/**
 * @param object/*from  w  w w.  j  av  a  2 s  .co  m*/
 *          object to be serialized
 * @param filePath
 *          the object will be written at this location, directories will be
 *          created according to path
 * @throws Exception exception
 */
public static void serializeToDisk(Serializable object, String filePath) throws Exception {
    File dir = new File(FilenameUtils.getFullPathNoEndSeparator(filePath));
    if (!dir.exists()) {
        FileUtils.forceMkdir(dir);
    } else {
        if (dir.isFile()) {
            throw new IOException("Path to dir is a file!");
        }
    }
    ObjectOutputStream objOut = null;
    objOut = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filePath)));
    objOut.writeObject(object);
    objOut.flush();
    objOut.close();
}

From source file:com.streamsets.pipeline.lib.el.FileEL.java

@ElFunction(prefix = "file", name = "parentPath", description = "Returns parent path to given file or directory. Returns path without separator (e.g. result will not end with slash).")
public static String parentPath(@ElParam("filePath") String filePath) {
    if (isEmpty(filePath)) {
        return null;
    }//from w  ww .  j  a  va  2  s  . c o m
    return FilenameUtils.getFullPathNoEndSeparator(filePath);
}

From source file:de.mas.wiiu.jnus.utils.FSTUtils.java

public static Optional<FSTEntry> getFSTEntryByFullPath(FSTEntry root, String givenFullPath) {
    String fullPath = givenFullPath.replace(File.separator, "/");
    if (!fullPath.startsWith("/")) {
        fullPath = "/" + fullPath;
    }//  w w  w.  j  av  a 2s.  com

    String dirPath = FilenameUtils.getFullPathNoEndSeparator(fullPath);
    Optional<FSTEntry> pathOpt = Optional.of(root);
    if (!dirPath.equals("/")) {
        pathOpt = getFileEntryDir(root, dirPath);
    }

    String path = fullPath;

    return pathOpt.flatMap(e -> e.getChildren().stream().filter(c -> c.getFullPath().equals(path)).findAny());
}

From source file:eu.europeana.enrichment.common.Utils.java

public static List<File> expandFileTemplateFrom(File dir, String... pattern) throws IOException {
    List<File> files = new ArrayList<File>();

    for (String p : pattern) {

        File fdir = new File(new File(dir, FilenameUtils.getFullPathNoEndSeparator(p)).getCanonicalPath());
        if (!fdir.isDirectory())
            throw new IOException("Error: " + fdir.getCanonicalPath() + ", expanded from directory "
                    + dir.getCanonicalPath() + " and pattern " + p + " does not denote a directory");
        if (!fdir.canRead())
            throw new IOException("Error: " + fdir.getCanonicalPath() + " is not readable");
        FileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(p));
        File[] list = fdir.listFiles(fileFilter);
        if (list == null)
            throw new IOException("Error: " + fdir.getCanonicalPath()
                    + " does not denote a directory or something else is wrong");
        if (list.length == 0)
            throw new IOException("Error: no files found, template " + p + " from dir " + dir.getCanonicalPath()
                    + " where we recognised " + fdir.getCanonicalPath() + " as path and " + fileFilter
                    + " as file mask");
        for (File file : list) {
            if (!file.exists()) {
                throw new FileNotFoundException(
                        "File not found: " + file + " resolved to " + file.getCanonicalPath());
            }//  w  w w.j ava  2s .  com
        }
        files.addAll(Arrays.asList(list));
    }

    return files;
}

From source file:com.creactiviti.piper.core.taskhandler.io.FilePath.java

@Override
public Object handle(Task aTask) {
    return FilenameUtils.getFullPathNoEndSeparator(aTask.getRequiredString("filename"));
}

From source file:hoot.services.utils.FileUtils.java

public static boolean validateFilePath(String expectedPath, String actualPath) {
    String path = FilenameUtils.getFullPathNoEndSeparator(actualPath);
    boolean isValid = expectedPath.equals(path);
    return isValid;
}

From source file:de.thischwa.pmcms.tool.file.FileComparator.java

@Override
public int compare(final File f1, final File f2) {
    if (f1.getAbsolutePath().equals(f2.getAbsolutePath()))
        return 0;

    String path1 = FilenameUtils.getFullPath(f1.getAbsolutePath());
    String path2 = FilenameUtils.getFullPath(f2.getAbsolutePath());
    String name1 = FilenameUtils.getName(f1.getAbsolutePath());
    String name2 = FilenameUtils.getName(f2.getAbsolutePath());
    if (path1.equals(path2) || (StringUtils.isBlank(path1) && StringUtils.isBlank(path2)))
        return name1.compareTo(name2);
    String[] pathParts1 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path1), File.separatorChar);
    String[] pathParts2 = StringUtils.split(FilenameUtils.getFullPathNoEndSeparator(path2), File.separatorChar);

    if (pathParts1.length < pathParts2.length)
        return -1;
    if (pathParts1.length > pathParts2.length)
        return +1;

    int i = 0;/*w ww  .  j  a  v  a  2 s . c o m*/
    while (i < pathParts1.length && i < pathParts2.length) {
        if (!pathParts1[i].equals(pathParts2[i]))
            return pathParts1[i].compareTo(pathParts2[i]);
        i++;
    }
    return 0;
}

From source file:eu.annocultor.common.Utils.java

public static List<File> expandFileTemplateFrom(File dir, String... pattern) throws IOException {
    List<File> files = new ArrayList<File>();

    for (String p : pattern) {
        File fdir = new File(new File(dir, FilenameUtils.getFullPathNoEndSeparator(p)).getCanonicalPath());
        if (!fdir.isDirectory())
            throw new IOException("Error: " + fdir.getCanonicalPath() + ", expanded from directory "
                    + dir.getCanonicalPath() + " and pattern " + p + " does not denote a directory");
        if (!fdir.canRead())
            throw new IOException("Error: " + fdir.getCanonicalPath() + " is not readable");
        FileFilter fileFilter = new WildcardFileFilter(FilenameUtils.getName(p));
        File[] list = fdir.listFiles(fileFilter);
        if (list == null)
            throw new IOException("Error: " + fdir.getCanonicalPath()
                    + " does not denote a directory or something else is wrong");
        if (list.length == 0)
            throw new IOException("Error: no files found, template " + p + " from dir " + dir.getCanonicalPath()
                    + " where we recognised " + fdir.getCanonicalPath() + " as path and " + fileFilter
                    + " as file mask");
        for (File file : list) {
            if (!file.exists()) {
                throw new FileNotFoundException(
                        "File not found: " + file + " resolved to " + file.getCanonicalPath());
            }//  w  w w  .  j  a v  a 2 s  .  co  m
        }
        files.addAll(Arrays.asList(list));
    }

    return files;
}

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

/**
 * Read directory creating FileInfo for each file found, include sub-directories.
 *///from   w w  w.  j  a  v  a  2s  .com
public List<FileInfo> readFiles(final String path, final List<String> filesAndDirectoriesToIgnore)
        throws IOException, InstantiationException, IllegalAccessException {
    final List<File> filesToIgnore = convertStringsToFiles(filesAndDirectoriesToIgnore);
    log.debug("Scanning directory: " + path);
    final File directory = new File(path);
    final Collection<File> allFiles = getAllFiles(directory, filesToIgnore);
    if (allFiles.isEmpty()) {
        log.warn("No files found in directory: " + path);
    }
    final List<FileInfo> allFilesInfo = new ArrayList<FileInfo>(allFiles.size());
    final String canonicalBaseDirectory = directory.getCanonicalPath();
    for (final File file : allFiles) {
        final FileInfo fileInfo = new FileInfo(log, file);
        // Remove base directory to derive sub-directory
        final String canonicalFilePath = FilenameUtils.getFullPathNoEndSeparator(file.getCanonicalPath());
        final String subDirectory = FilenameUtils
                .normalize(StringUtils.replaceOnce(canonicalFilePath, canonicalBaseDirectory, ""));
        fileInfo.setRelativeSubDirectory(subDirectory);
        allFilesInfo.add(fileInfo);
    }
    return allFilesInfo;
}