Search in sources :

Example 1 with AbstractFileName

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);
}
Also used : FileType(org.apache.commons.vfs2.FileType)

Example 2 with AbstractFileName

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();
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry)

Example 3 with AbstractFileName

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);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName) FileName(org.apache.commons.vfs2.FileName) DelegateFileObject(org.apache.commons.vfs2.provider.DelegateFileObject) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName) FileSystemException(org.apache.commons.vfs2.FileSystemException)

Example 4 with AbstractFileName

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);
}
Also used : AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName) FileName(org.apache.commons.vfs2.FileName) DelegateFileObject(org.apache.commons.vfs2.provider.DelegateFileObject) FileObject(org.apache.commons.vfs2.FileObject) DelegateFileObject(org.apache.commons.vfs2.provider.DelegateFileObject)

Example 5 with AbstractFileName

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();
}
Also used : AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName)

Aggregations

AbstractFileName (org.apache.commons.vfs2.provider.AbstractFileName)8 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 FileName (org.apache.commons.vfs2.FileName)3 IOException (java.io.IOException)2 FileObject (org.apache.commons.vfs2.FileObject)2 FileType (org.apache.commons.vfs2.FileType)2 DelegateFileObject (org.apache.commons.vfs2.provider.DelegateFileObject)2 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 ZipEntry (java.util.zip.ZipEntry)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)1 AbstractFileObject (org.apache.commons.vfs2.provider.AbstractFileObject)1 AbstractFileProvider (org.apache.commons.vfs2.provider.AbstractFileProvider)1 FileProvider (org.apache.commons.vfs2.provider.FileProvider)1 LocalFileProvider (org.apache.commons.vfs2.provider.LocalFileProvider)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 VFSConnectionDetails (org.pentaho.di.connections.vfs.VFSConnectionDetails)1