当前位置: 首页>>代码示例>>Java>>正文


Java FileName.getPath方法代码示例

本文整理汇总了Java中org.apache.commons.vfs2.FileName.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java FileName.getPath方法的具体用法?Java FileName.getPath怎么用?Java FileName.getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.vfs2.FileName的用法示例。


在下文中一共展示了FileName.getPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testChildName

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
/**
 * Tests child file names.
 */
public void testChildName() throws Exception
{
    final FileName baseName = getReadFolder().getName();
    final String basePath = baseName.getPath();
    final FileName name = getManager().resolveName(baseName, "some-child", NameScope.CHILD);

    // Test path is absolute
    assertTrue("is absolute", basePath.startsWith("/"));

    // Test base name
    assertEquals("base name", "some-child", name.getBaseName());

    // Test absolute path
    assertEquals("absolute path", basePath + "/some-child", name.getPath());

    // Test parent path
    assertEquals("parent absolute path", basePath, name.getParent().getPath());

    // Try using a compound name to find a child
    assertBadName(name, "a/b", NameScope.CHILD);

    // Check other invalid names
    checkDescendentNames(name, NameScope.CHILD);
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:28,代码来源:NamingTests.java

示例2: testDescendentName

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
/**
 * Tests descendent name resolution.
 */
public void testDescendentName()
    throws Exception
{
    final FileName baseName = getReadFolder().getName();

    // Test direct child
    String path = baseName.getPath() + "/some-child";
    assertSameName(path, baseName, "some-child", NameScope.DESCENDENT);

    // Test compound name
    path = path + "/grand-child";
    assertSameName(path, baseName, "some-child/grand-child", NameScope.DESCENDENT);

    // Test relative names
    assertSameName(path, baseName, "./some-child/grand-child", NameScope.DESCENDENT);
    assertSameName(path, baseName, "./nada/../some-child/grand-child", NameScope.DESCENDENT);
    assertSameName(path, baseName, "some-child/./grand-child", NameScope.DESCENDENT);

    // Test badly formed descendent names
    checkDescendentNames(baseName, NameScope.DESCENDENT);
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:25,代码来源:NamingTests.java

示例3: checkDescendentNames

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
/**
 * Name resolution tests that are common for CHILD or DESCENDENT scope.
 */
private void checkDescendentNames(final FileName name,
                                  final NameScope scope)
    throws Exception
{
    // Make some assumptions about the name
    assertTrue(!name.getPath().equals("/"));
    assertTrue(!name.getPath().endsWith("/a"));
    assertTrue(!name.getPath().endsWith("/a/b"));

    // Test names with the same prefix
    String path = name.getPath() + "/a";
    assertSameName(path, name, path, scope);
    assertSameName(path, name, "../" + name.getBaseName() + "/a", scope);

    // Test an empty name
    assertBadName(name, "", scope);

    // Test . name
    assertBadName(name, ".", scope);
    assertBadName(name, "./", scope);

    // Test ancestor names
    assertBadName(name, "..", scope);
    assertBadName(name, "../a", scope);
    assertBadName(name, "../" + name.getBaseName() + "a", scope);
    assertBadName(name, "a/..", scope);

    // Test absolute names
    assertBadName(name, "/", scope);
    assertBadName(name, "/a", scope);
    assertBadName(name, "/a/b", scope);
    assertBadName(name, name.getPath(), scope);
    assertBadName(name, name.getPath() + "a", scope);
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:38,代码来源:NamingTests.java

示例4: pathFromRoot

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
/**
 * @param file the file
 * @return the full path
 */
public final String pathFromRoot(FileObject file) {
    FileName rootFolderName = rootFolder.getName();
    FileName fileName = file.getName();
    try {
        return rootFolderName.getRelativeName(fileName);
    } catch (FileSystemException e) {
        throw new AutomationException("Error resolving relative path " +
                rootFolderName.getPath() + " -> " + fileName.getPath(), e);
    }
}
 
开发者ID:AludraTest,项目名称:aludratest,代码行数:15,代码来源:FileServiceConfiguration.java

示例5: FileNameWrapper

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
public FileNameWrapper(FileName fileName) {
  super(fileName.getScheme(), fileName.getPath(), fileName.getType());
  this.fileName = fileName;
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:5,代码来源:FileNameWrapper.java

示例6: getRelativeName

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
/**
 * Converts a file name to a relative name, relative to this file name.
 * @param name The FileName.
 * @return The relative path to the file.
 * @throws FileSystemException if an error occurs.
 */
public String getRelativeName(final FileName name) throws FileSystemException
{
    final String path = name.getPath();

    // Calculate the common prefix
    final int basePathLen = getPath().length();
    final int pathLen = path.length();

    // Deal with root
    if (basePathLen == 1 && pathLen == 1)
    {
        return ".";
    }
    else if (basePathLen == 1)
    {
        return path.substring(1);
    }

    final int maxlen = Math.min(basePathLen, pathLen);
    int pos = 0;
    for (; pos < maxlen && getPath().charAt(pos) == path.charAt(pos); pos++)
    {
    }

    if (pos == basePathLen && pos == pathLen)
    {
        // Same names
        return ".";
    }
    else if (pos == basePathLen && pos < pathLen && path.charAt(pos) == SEPARATOR_CHAR)
    {
        // A descendent of the base path
        return path.substring(pos + 1);
    }

    // Strip the common prefix off the path
    final StringBuilder buffer = new StringBuilder();
    if (pathLen > 1 && (pos < pathLen || getPath().charAt(pos) != SEPARATOR_CHAR))
    {
        // Not a direct ancestor, need to back up
        pos = getPath().lastIndexOf(SEPARATOR_CHAR, pos);
        buffer.append(path.substring(pos));
    }

    // Prepend a '../' for each element in the base path past the common
    // prefix
    buffer.insert(0, "..");
    pos = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
    while (pos != -1)
    {
        buffer.insert(0, "../");
        pos = getPath().indexOf(SEPARATOR_CHAR, pos + 1);
    }

    return buffer.toString();
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:63,代码来源:AbstractFileName.java

示例7: testNameResolution

import org.apache.commons.vfs2.FileName; //导入方法依赖的package包/类
/**
 * Tests relative name resolution, relative to the base folder.
 */
public void testNameResolution() throws Exception
{
    final FileName baseName = getReadFolder().getName();
    final String parentPath = baseName.getParent().getPath();
    final String path = baseName.getPath();
    final String childPath = path + "/some-child";

    // Test empty relative path
    assertSameName(path, baseName, "");

    // Test . relative path
    assertSameName(path, baseName, ".");

    // Test ./ relative path
    assertSameName(path, baseName, "./");

    // Test .// relative path
    assertSameName(path, baseName, ".//");

    // Test .///.///. relative path
    assertSameName(path, baseName, ".///.///.");
    assertSameName(path, baseName, "./\\/.\\//.");

    // Test <elem>/.. relative path
    assertSameName(path, baseName, "a/..");

    // Test .. relative path
    assertSameName(parentPath, baseName, "..");

    // Test ../ relative path
    assertSameName(parentPath, baseName, "../");

    // Test ..//./ relative path
    assertSameName(parentPath, baseName, "..//./");
    assertSameName(parentPath, baseName, "..//.\\");

    // Test <elem>/../.. relative path
    assertSameName(parentPath, baseName, "a/../..");

    // Test <elem> relative path
    assertSameName(childPath, baseName, "some-child");

    // Test ./<elem> relative path
    assertSameName(childPath, baseName, "./some-child");

    // Test ./<elem>/ relative path
    assertSameName(childPath, baseName, "./some-child/");

    // Test <elem>/././././ relative path
    assertSameName(childPath, baseName, "./some-child/././././");

    // Test <elem>/../<elem> relative path
    assertSameName(childPath, baseName, "a/../some-child");

    // Test <elem>/<elem>/../../<elem> relative path
    assertSameName(childPath, baseName, "a/b/../../some-child");
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:61,代码来源:NamingTests.java


注:本文中的org.apache.commons.vfs2.FileName.getPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。