本文整理汇总了Java中org.apache.commons.vfs.FileName.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java FileName.getPath方法的具体用法?Java FileName.getPath怎么用?Java FileName.getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.vfs.FileName
的用法示例。
在下文中一共展示了FileName.getPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFilename
import org.apache.commons.vfs.FileName; //导入方法依赖的package包/类
public static String getFilename(FileObject fileObject)
{
FileName fileName = fileObject.getName();
String root = fileName.getRootURI();
if (!root.startsWith("file:")) return fileName.getURI(); // nothing we can do about non-normal files.
if (root.endsWith(":/")) // Windows
{
root = root.substring(8,10);
}
else // *nix & OSX
{
root = "";
}
String fileString = root + fileName.getPath();
if (!"/".equals(Const.FILE_SEPARATOR))
{
fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR);
}
return fileString;
}
示例2: getFilename
import org.apache.commons.vfs.FileName; //导入方法依赖的package包/类
public static String getFilename(FileObject fileObject)
{
FileName fileName = fileObject.getName();
String root = fileName.getRootURI();
if (!root.startsWith("file:")) return fileName.getURI(); // nothing we can do about non-normal files. //$NON-NLS-1$
if (root.startsWith("file:////")) return fileName.getURI(); // we'll see 4 forward slashes for a windows/smb network share
if (root.endsWith(":/")) // Windows //$NON-NLS-1$
{
root = root.substring(8,10);
}
else // *nix & OSX
{
root = ""; //$NON-NLS-1$
}
String fileString = root + fileName.getPath();
if (!"/".equals(Const.FILE_SEPARATOR)) //$NON-NLS-1$
{
fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR); //$NON-NLS-1$
}
return fileString;
}
示例3: testChildName
import org.apache.commons.vfs.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);
}
示例4: testDescendentName
import org.apache.commons.vfs.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);
}
示例5: getFilename
import org.apache.commons.vfs.FileName; //导入方法依赖的package包/类
public static String getFilename(FileObject fileObject)
{
FileName fileName = fileObject.getName();
String root = fileName.getRootURI();
if(!root.startsWith("file:")) return fileName.getURI();
if(root.endsWith(":/"))
root = root.substring(8, 10);
else
root = root.substring(7, root.length() - 1);
String fileString = root + fileName.getPath();
if(!"/".equals(Const.FILE_SEPARATOR)) fileString = Const.replace(fileString, "/", Const.FILE_SEPARATOR);
return fileString;
}
示例6: checkDescendentNames
import org.apache.commons.vfs.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);
}
示例7: getRelativeName
import org.apache.commons.vfs.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 StringBuffer buffer = new StringBuffer();
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();
}
示例8: testNameResolution
import org.apache.commons.vfs.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");
}