本文整理汇总了Java中org.apache.commons.vfs.FileName类的典型用法代码示例。如果您正苦于以下问题:Java FileName类的具体用法?Java FileName怎么用?Java FileName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileName类属于org.apache.commons.vfs包,在下文中一共展示了FileName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseUri
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
/**
* Parses URI and constructs S3 file name.
*/
public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename) throws FileSystemException {
StringBuffer name = new StringBuffer();
String scheme = UriParser.extractScheme(filename, name);
UriParser.canonicalizePath(name, 0, name.length(), this);
// Normalize separators in the path
UriParser.fixSeparators(name);
// Normalise the path
FileType fileType = UriParser.normalisePath(name);
// Extract bucket name
final String bucketName = UriParser.extractFirstElement(name);
return new S3FileName(scheme, bucketName, name.toString(), fileType);
}
示例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.
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;
}
示例3: setInternalFilenameKettleVariables
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
private void setInternalFilenameKettleVariables(VariableSpace var) {
if (filename != null) // we have a filename that's defined.
{
try {
FileObject fileObject = KettleVFS.getFileObject(filename, var);
FileName fileName = fileObject.getName();
// The filename of the job
var.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, fileName.getBaseName());
// The directory of the job
FileName fileDir = fileName.getParent();
var.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, fileDir.getURI());
} catch (Exception e) {
var.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "");
var.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, "");
}
} else {
var.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, ""); //$NON-NLS-1$
var.setVariable(Const.INTERNAL_VARIABLE_JOB_FILENAME_NAME, ""); //$NON-NLS-1$
}
}
示例4: 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;
}
示例5: 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);
}
示例6: notifyParent
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
/**
* Notify the parent of a change to its children, when a child is created
* or deleted.
*/
private void notifyParent(FileName childName, FileType newType) throws Exception
{
if (parent == null)
{
FileName parentName = name.getParent();
if (parentName != null)
{
// Locate the parent, if it is cached
parent = fs.getFileFromCache(parentName);
}
}
if (parent != null)
{
FileObjectUtils.getAbstractFileObject(parent).childrenChanged(childName, newType);
}
}
示例7: removeFile
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
public void removeFile(final FileSystem filesystem, final FileName name)
{
synchronized (this)
{
Map files = getOrCreateFilesystemCache(filesystem);
// System.err.println(">>> " + files.size() + " remove:" + name.toString());
files.remove(name);
if (files.size() < 1)
{
filesystemCache.remove(filesystem);
}
}
}
示例8: createFile
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
/**
* Creates a file object. This method is called only if the requested
* file is not cached.
*/
protected FileObject createFile(final FileName 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 = (FileObject) 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);
}
示例9: testGetParentOnFilesystemRoot
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
@Test(expected = FileSystemException.class)
public void testGetParentOnFilesystemRoot() throws org.apache.commons.vfs.FileSystemException,
FileSystemException, MalformedURLException {
FileObject rootFileObject;
if (OperatingSystem.getOperatingSystem() == OperatingSystem.windows) {
rootFileObject = fileSystemManager.resolveFile(new File("c:\\").toURI().toURL().toString());
} else {
rootFileObject = fileSystemManager.resolveFile(new File("/").toURI().toURL().toString());
}
final FileName mountintPointFileName = rootFileObject.getName();
final FileObject rootAdaptee = rootFileObject;
ArrayList<String> fos = new ArrayList<String>();
fos.add("file:///");
final DataSpacesFileObject fo = new VFSFileObjectAdapter(rootAdaptee, spaceURI,
mountintPointFileName, fos);
fo.getParent();
}
示例10: findFile
import org.apache.commons.vfs.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());
}
示例11: testCd
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
/**
* @throws Exception
*/
@Test
public void testCd() throws Exception {
String path = "c:/windows";
FileName foldername = EgovFileUtil.getFileObject(path).getName();
EgovFileUtil.cd("");
String uri = EgovFileUtil.pwd().getURI();
log.debug("EgovFileUtil.pwd().getURI() : " + uri);
log.debug("foldername.getURI() : " + foldername.getURI());
assertFalse(foldername.getURI().equals(uri));
/////////////////////////////////////////////////////////////////
// c:\windows 로 이동
EgovFileUtil.cd(path);
uri = EgovFileUtil.pwd().getURI();
log.debug("EgovFileUtil.pwd().getURI() : " + uri);
log.debug("foldername.getURI() : " + foldername.getURI());
assertEquals(foldername.getURI(), EgovFileUtil.pwd().getURI());
}
示例12: getChild
import org.apache.commons.vfs.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;
}
示例13: 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);
}
示例14: findFile
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
/**
* Locates a file object, by absolute URI.
*
* @param baseFile The base file object.
* @param uri The URI of the file to locate
* @param fileSystemOptions The FileSystem options.
* @return The located FileObject
* @throws FileSystemException if an error occurs.
*/
public FileObject findFile(final FileObject baseFile,
final String uri,
final FileSystemOptions fileSystemOptions) throws FileSystemException
{
// Parse the URI
final FileName name;
try
{
name = parseUri(baseFile != null ? baseFile.getName() : null, uri);
}
catch (FileSystemException exc)
{
throw new FileSystemException("vfs.provider/invalid-absolute-uri.error", uri, exc);
}
// Locate the file
return findFile(name, fileSystemOptions);
}
示例15: AbstractFileSystem
import org.apache.commons.vfs.FileName; //导入依赖的package包/类
protected AbstractFileSystem(final FileName rootName,
final FileObject parentLayer,
final FileSystemOptions fileSystemOptions)
{
// this.parentLayer = parentLayer;
this.parentLayer = parentLayer;
this.rootName = rootName;
this.fileSystemOptions = fileSystemOptions;
FileSystemConfigBuilder builder = DefaultFileSystemConfigBuilder.getInstance();
String uri = builder.getRootURI(fileSystemOptions);
if (uri == null)
{
uri = rootName.getURI();
}
this.rootURI = uri;
}