本文整理汇总了Java中org.apache.commons.vfs2.FileName类的典型用法代码示例。如果您正苦于以下问题:Java FileName类的具体用法?Java FileName怎么用?Java FileName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileName类属于org.apache.commons.vfs2包,在下文中一共展示了FileName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCheckIfInclude
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
@Test(dataProvider = "candidateFiles")
public void testCheckIfInclude(String path, boolean hiddenAttribute, boolean showHidden, boolean expected) throws Exception {
//given
VfsTableModelHiddenFileRowFilter rowFilter = new VfsTableModelHiddenFileRowFilter(showHidden);
FileObject fileObject = mock(FileObject.class);
FileName fileName = mock(FileName.class);
when(fileObject.getName()).thenReturn(fileName);
when(fileName.getBaseName()).thenReturn(path);
when(fileObject.isHidden()).thenReturn(hiddenAttribute);
//when
boolean result = rowFilter.checkIfInclude(fileObject);
//then
Assert.assertEquals(result, expected, String.format("Result for file \"%s\" with hidden attribute %s and showHidden checked %s should " +
"be %s, was %s", path,
hiddenAttribute, showHidden, result, expected));
}
示例2: testGetObjectShortName
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
private void testGetObjectShortName(String scheme, String url, String baseName, String output) {
// given
FileObject fileObjectMock = mock(FileObject.class);
FileName fileNameMock = mock(FileName.class);
when(fileObjectMock.getName()).thenReturn(fileNameMock);
when(fileNameMock.getScheme()).thenReturn(scheme);
when(fileNameMock.getURI()).thenReturn(url);
when(fileNameMock.getBaseName()).thenReturn(baseName);
// when
String fileObjectShortName = Utils.getFileObjectShortName(fileObjectMock);
// then
AssertJUnit.assertEquals(output, fileObjectShortName);
}
示例3: get
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Nullable
@Override
public IProject get(final FileObject resource) {
Preconditions.checkNotNull(resource);
@Nullable final FileObject artifactRoot = getArtifactRoot(resource);
if (artifactRoot == null)
return null;
final FileName artifactName = artifactRoot.getName();
@Nullable ArtifactProject project = this.projects.get(artifactName);
if (project == null) {
project = this.artifactProjectFactory.create(artifactRoot, null);
this.projects.put(artifactName, project);
}
return project;
}
示例4: checkAbsoluteNames
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* Tests resolution of absolute names.
*/
private void checkAbsoluteNames(final FileName name) throws Exception
{
// Root
assertSameName("/", name, "/");
assertSameName("/", name, "//");
assertSameName("/", name, "/.");
assertSameName("/", name, "/some file/..");
// Some absolute names
assertSameName("/a", name, "/a");
assertSameName("/a", name, "/./a");
assertSameName("/a", name, "/a/.");
assertSameName("/a/b", name, "/a/b");
// Some bad names
assertBadName(name, "/..", NameScope.FILE_SYSTEM);
assertBadName(name, "/a/../..", NameScope.FILE_SYSTEM);
}
示例5: getFile
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
public FileObject getFile(final FileSystem filesystem, final FileName name)
{
Map<FileName, Reference<FileObject>> files = getOrCreateFilesystemCache(filesystem);
lock.lock();
try
{
Reference<FileObject> ref = files.get(name);
if (ref == null)
{
return null;
}
FileObject fo = ref.get();
if (fo == null)
{
removeFile(filesystem, name);
}
return fo;
}
finally
{
lock.unlock();
}
}
示例6: getOrCreateFilesystemCache
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
protected Map<FileName, Reference<FileObject>> getOrCreateFilesystemCache(final FileSystem filesystem)
{
if (filesystemCache.size() < 1)
{
startThread();
}
Map<FileName, Reference<FileObject>> files;
do
{
files = filesystemCache.get(filesystem);
if (files != null)
{
break;
}
files = new HashMap<FileName, Reference<FileObject>>();
} while (filesystemCache.putIfAbsent(filesystem, files) == null);
return files;
}
示例7: createFile
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* Creates a file object. This method is called only if the requested
* file is not cached.
*/
@Override
protected FileObject createFile(final AbstractFileName name) throws Exception
{
// Find the file that the name points to
final FileName junctionPoint = getJunctionForFile(name);
final FileObject file;
if (junctionPoint != null)
{
// Resolve the real file
final FileObject junctionFile = junctions.get(junctionPoint);
final String relName = junctionPoint.getRelativeName(name);
file = junctionFile.resolveFile(relName, NameScope.DESCENDENT_OR_SELF);
}
else
{
file = null;
}
// Return a wrapper around the file
return new DelegateFileObject(name, this, file);
}
示例8: putFileIfAbsent
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
public boolean putFileIfAbsent(final FileObject file)
{
Map<FileName, FileObject> files = getOrCreateFilesystemCache(file.getFileSystem());
writeLock.lock();
try
{
FileName name = file.getName();
// System.err.println(">>> " + files.size() + " put:" + file.toString());
if (files.containsKey(name))
{
return false;
}
files.put(name, file);
return true;
}
finally
{
writeLock.unlock();
}
}
示例9: getChild
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* Returns a child of this file.
* @param name The name of the child to locate.
* @return The FileObject for the file or null if the child does not exist.
* @throws FileSystemException if an error occurs.
*/
public FileObject getChild(final String name) throws FileSystemException
{
// TODO - use a hashtable when there are a large number of children
FileObject[] children = getChildren();
for (int i = 0; i < children.length; i++)
{
// final FileObject child = children[i];
final FileName child = children[i].getName();
// TODO - use a comparator to compare names
// if (child.getName().getBaseName().equals(name))
if (child.getBaseName().equals(name))
{
return resolveFile(child);
}
}
return null;
}
示例10: removeFile
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
public void removeFile(final FileSystem filesystem, final FileName name)
{
Map<?, ?> files = getOrCreateFilesystemCache(filesystem);
writeLock.lock();
try
{
// System.err.println(">>> " + files.size() + " remove:" + name.toString());
files.remove(name);
if (files.size() < 1)
{
filesystemCache.remove(filesystem);
}
}
finally
{
writeLock.unlock();
}
}
示例11: getJunctionForFile
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* Locates the junction point for the junction containing the given file.
* @param name The FileName.
* @return the FileName where the junction occurs.
*/
private FileName getJunctionForFile(final FileName name)
{
if (junctions.containsKey(name))
{
// The name points to the junction point directly
return name;
}
// Find matching junction
for (Iterator<FileName> iterator = junctions.keySet().iterator(); iterator.hasNext();)
{
final FileName junctionPoint = iterator.next();
if (junctionPoint.isDescendent(name))
{
return junctionPoint;
}
}
// None
return null;
}
示例12: 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);
}
示例13: findFile
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* Locates a file object, by absolute URI.
* @param baseFile The base FileObject.
* @param uri The name of the file to locate.
* @param properties The FileSystemOptions.
* @return The FileObject if it is located, null otherwise.
* @throws FileSystemException if an error occurs.
*/
public FileObject findFile(final FileObject baseFile,
final String uri,
final FileSystemOptions properties) throws FileSystemException
{
// Split the URI up into its parts
final LayeredFileName name = (LayeredFileName) parseUri(baseFile != null ? baseFile.getName() : null, uri);
// Make the URI canonical
// Resolve the outer file name
final FileName fileName = name.getOuterName();
final FileObject file = getContext().resolveFile(baseFile, fileName.getURI(), properties);
// Create the file system
final FileObject rootFile = createFileSystem(name.getScheme(), file, properties);
// Resolve the file
return rootFile.resolveFile(name.getPath());
}
示例14: createFileSystem
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
/**
* Creates a layered file system.
* @param scheme The protocol to use.
* @param file a FileObject.
* @param fileSystemOptions Options to access the FileSystem.
* @return A FileObject associated with the new FileSystem.
* @throws FileSystemException if an error occurs.
*/
@Override
public synchronized FileObject createFileSystem(final String scheme,
final FileObject file,
final FileSystemOptions fileSystemOptions)
throws FileSystemException
{
// Check if cached
final FileName rootName = file.getName();
FileSystem fs = findFileSystem(rootName, null);
if (fs == null)
{
// Create the file system
fs = doCreateFileSystem(scheme, file, fileSystemOptions);
addFileSystem(rootName, fs);
}
return fs.getRoot();
}
示例15: parseUri
import org.apache.commons.vfs2.FileName; //导入依赖的package包/类
public FileName parseUri(final VfsComponentContext context, FileName base, final String filename)
throws FileSystemException
{
// FTP URI are generic URI (as per RFC 2396)
final StringBuilder name = new StringBuilder();
// Extract the scheme and authority parts
final Authority auth = extractToPath(filename, name);
// Decode and normalise the file name
UriParser.canonicalizePath(name, 0, name.length(), this);
UriParser.fixSeparators(name);
FileType fileType = UriParser.normalisePath(name);
final String path = name.toString();
return new GenericFileName(
auth.scheme,
auth.hostName,
auth.port,
defaultPort,
auth.userName,
auth.password,
path,
fileType);
}