use of org.apache.commons.vfs2.provider.AbstractFileName in project pentaho-kettle by pentaho.
the class ConnectionFileNameParser method parseUri.
public static AbstractFileName parseUri(String uri, FileNameParser fileNameParser) throws FileSystemException {
StringBuilder name = new StringBuilder();
String scheme = UriParser.extractScheme(uri, name);
UriParser.canonicalizePath(name, 0, name.length(), fileNameParser);
UriParser.fixSeparators(name);
FileType fileType = UriParser.normalisePath(name);
// Extract the named connection name
final String connection = UriParser.extractFirstElement(name);
String path = name.toString();
return new ConnectionFileName(scheme, connection, path, fileType);
}
use of org.apache.commons.vfs2.provider.AbstractFileName in project commons-vfs by apache.
the class TarFileSystem method init.
@Override
public void init() throws FileSystemException {
super.init();
// Build the index
try {
TarArchiveEntry entry;
while ((entry = getTarFile().getNextTarEntry()) != null) {
final AbstractFileName name = (AbstractFileName) getFileSystemManager().resolveName(getRootName(), UriParser.encode(entry.getName(), ENC));
// Create the file
TarFileObject fileObj;
if (entry.isDirectory() && getFileFromCache(name) != null) {
fileObj = (TarFileObject) getFileFromCache(name);
fileObj.setTarEntry(entry);
continue;
}
fileObj = createTarFileObject(name, entry);
putFileToCache(fileObj);
// Make sure all ancestors exist
// TODO - create these on demand
TarFileObject parent = null;
for (AbstractFileName parentName = (AbstractFileName) name.getParent(); parentName != null; fileObj = parent, parentName = (AbstractFileName) parentName.getParent()) {
// Locate the parent
parent = (TarFileObject) getFileFromCache(parentName);
if (parent == null) {
parent = createTarFileObject(parentName, null);
putFileToCache(parent);
}
// Attach child to parent
parent.attachChild(fileObj.getName());
}
}
} catch (final IOException e) {
throw new FileSystemException(e);
} finally {
closeCommunicationLink();
}
}
use of org.apache.commons.vfs2.provider.AbstractFileName in project commons-vfs by apache.
the class VirtualFileSystem method addJunction.
/**
* Adds a junction to this file system.
*
* @param junctionPoint The location of the junction.
* @param targetFile The target file to base the junction on.
* @throws FileSystemException if an error occurs.
*/
@Override
public void addJunction(final String junctionPoint, final FileObject targetFile) throws FileSystemException {
final FileName junctionName = getFileSystemManager().resolveName(getRootName(), junctionPoint);
// Check for nested junction - these are not supported yet
if (getJunctionForFile(junctionName) != null) {
throw new FileSystemException("vfs.impl/nested-junction.error", junctionName);
}
try {
// Add to junction table
junctions.put(junctionName, targetFile);
// Attach to file
final DelegateFileObject junctionFile = (DelegateFileObject) getFileFromCache(junctionName);
if (junctionFile != null) {
junctionFile.setFile(targetFile);
}
// Create ancestors of junction point
FileName childName = junctionName;
boolean done = false;
for (AbstractFileName parentName = (AbstractFileName) childName.getParent(); !done && parentName != null; childName = parentName, parentName = (AbstractFileName) parentName.getParent()) {
DelegateFileObject file = (DelegateFileObject) getFileFromCache(parentName);
if (file == null) {
file = new DelegateFileObject(parentName, this, null);
putFileToCache(file);
} else {
done = file.exists();
}
// As this is the parent of our junction it has to be a folder
file.attachChild(childName, FileType.FOLDER);
}
// TODO - attach all cached children of the junction point to their real file
} catch (final Exception e) {
throw new FileSystemException("vfs.impl/create-junction.error", junctionName, e);
}
}
use of org.apache.commons.vfs2.provider.AbstractFileName in project commons-vfs by apache.
the class VirtualFileSystem method createFile.
/**
* 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);
}
use of org.apache.commons.vfs2.provider.AbstractFileName in project commons-vfs by apache.
the class VirtualFileProvider method createFileSystem.
/**
* Creates a virtual file system, with the supplied file as its root.
*
* @param rootFile The root of the file system.
* @return A FileObject in the FileSystem.
* @throws FileSystemException if an error occurs.
*/
public FileObject createFileSystem(final FileObject rootFile) throws FileSystemException {
final AbstractFileName rootName = (AbstractFileName) getContext().getFileSystemManager().resolveName(rootFile.getName(), FileName.ROOT_PATH);
final VirtualFileSystem fs = new VirtualFileSystem(rootName, rootFile.getFileSystem().getFileSystemOptions());
addComponent(fs);
fs.addJunction(FileName.ROOT_PATH, rootFile);
return fs.getRoot();
}
Aggregations