org.apache.commons.io.FilenameUtils#getPrefixLength ( )源码实例Demo

下面列出了org.apache.commons.io.FilenameUtils#getPrefixLength ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cyberduck   文件: Local.java
private String parent(final String absolute) {
    final String prefix = FilenameUtils.getPrefix(absolute);
    if(absolute.equals(prefix)) {
        return null;
    }
    int index = absolute.length() - 1;
    if(absolute.charAt(index) == this.getDelimiter()) {
        if(index > 0) {
            index--;
        }
    }
    final int cut = absolute.lastIndexOf(this.getDelimiter(), index);
    if(cut > FilenameUtils.getPrefixLength(absolute)) {
        return absolute.substring(0, cut);
    }
    return String.valueOf(prefix);
}
 
private ApplicationArchiveReader getApplicationArchiveReaderForAbsolutePath() {
    return new ApplicationArchiveReader() {
        @Override
        protected void validateEntry(ZipEntry entry) {
            String path = entry.getName();
            if (!path.equals(FilenameUtils.normalize(path, true))) {
                throw new IllegalArgumentException(MessageFormat.format(FileUtils.PATH_SHOULD_BE_NORMALIZED, path));
            }
            if (FilenameUtils.getPrefixLength(path) != 0 || Paths.get(path)
                                                                 .isAbsolute()) {
                throw new IllegalArgumentException(MessageFormat.format(FileUtils.PATH_SHOULD_NOT_BE_ABSOLUTE, path));
            }
        }
    };
}
 
源代码3 项目: sldeditor   文件: RelativePath.java
/**
 * Checks if is file is a relative path.
 *
 * @param path the path
 * @return true if the path is relative
 */
public static Boolean isRelativePath(String path) {
    if (path == null) {
        return false;
    }

    int prefixLen = FilenameUtils.getPrefixLength(path);
    return !(testPathWin(path, prefixLen) || testPathLinux(prefixLen));
}
 
源代码4 项目: sejda   文件: PdfFileSourceListAdapter.java
/**
 * Parse fileset definitions <filelist><fileset>[...]</fileset></filelist> ignoring the rest of the document
 * 
 * @param doc
 * @return a list of string matching the contents of the <filelist><fileset> tags in the document
 * @throws XPathExpressionException
 */
private List<String> parseFileSets(Document doc, File configFile) throws XPathExpressionException {
    List<String> result = new ArrayList<>();

    NodeList nodeList = getNodeListMatchingXpath("//filelist/fileset/file", doc);
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        Node fileSet = node.getParentNode();

        String parentDirPath = nullSafeGetStringAttribute(fileSet, "dir");
        if (parentDirPath == null) {
            parentDirPath = configFile.getAbsoluteFile().getParent();
        }

        String filePath = extractFilePath(node);

        // warn if file in fileset is using absolute path mode
        if (FilenameUtils.getPrefixLength(filePath) > 0) {
            LOG.warn("File " + filePath + " in fileset "
                    + StringUtils.defaultIfBlank(nullSafeGetStringAttribute(fileSet, "dir"), "")
                    + " seems to be an absolute path. Will _not_ be resolved relative to the <fileset>, but as an absolute path. Normally you would want to use relative paths in a //filelist/fileset/file, and absolute paths in a //filelist/file.");
        }

        result.add(FilenameUtils.concat(parentDirPath, filePath));
    }

    return result;
}
 
源代码5 项目: multiapps-controller   文件: MtaPathValidator.java
private static boolean isAbsolute(String path) {
    return FilenameUtils.getPrefixLength(path) != 0;
}
 
源代码6 项目: cyberduck   文件: WorkdirPrefixer.java
private boolean isAbsolute(final String path) {
    return FilenameUtils.getPrefixLength(path) != 0;
}
 
源代码7 项目: analysis-model   文件: MsBuildParser.java
private boolean canResolveRelativeFileName(final String fileName, final String projectDir) {
    return StringUtils.isNotBlank(projectDir) && FilenameUtils.getPrefixLength(fileName) == 0
            && !"MSBUILD".equals(fileName.trim());
}