Search in sources :

Example 6 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project pentaho-kettle by pentaho.

the class GoogleDriveFileProviderTest method testFileProvider.

@Test
public void testFileProvider() throws Exception {
    GoogleDriveFileProvider fileProvider = new GoogleDriveFileProvider();
    assertTrue(fileProvider.SCHEME.equals(SCHEME));
    assertTrue(fileProvider.DISPLAY_NAME.equals(DISPLAY_NAME));
    FileName fileName = mock(FileName.class);
    FileSystemOptions options = new FileSystemOptions();
    assertNotNull(fileProvider.doCreateFileSystem(fileName, options));
}
Also used : FileName(org.apache.commons.vfs2.FileName) GoogleDriveFileProvider(org.pentaho.googledrive.vfs.GoogleDriveFileProvider) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 7 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project pentaho-kettle by pentaho.

the class ConcurrentFileSystemManager method closeEmbeddedFileSystem.

public void closeEmbeddedFileSystem(String embeddedMetastoreKey) {
    lock.readLock().lock();
    Map<String, FileProvider> providers;
    try {
        // Close the file system
        java.lang.reflect.Field field = null;
        try {
            field = this.getClass().getSuperclass().getSuperclass().getDeclaredField("providers");
            field.setAccessible(true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
        providers = (Map<String, FileProvider>) field.get(this);
        FileProvider provider = providers.get("hc");
        if (provider != null) {
            ((VfsEmbeddedFileSystemCloser) provider).closeFileSystem(embeddedMetastoreKey);
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } finally {
        lock.readLock().unlock();
    }
}
Also used : VfsEmbeddedFileSystemCloser(org.pentaho.di.core.osgi.api.VfsEmbeddedFileSystemCloser) FileProvider(org.apache.commons.vfs2.provider.FileProvider)

Example 8 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class BasicOperationsTest method setUp.

/**
 * JUnit Fixture: Prepare a simple FSM.
 *
 * @throws FileSystemException for runtime problems
 */
@BeforeEach
public void setUp() throws FileSystemException {
    manager = new DefaultFileSystemManager();
    final FileProvider fp = new DefaultLocalFileProvider();
    manager.addProvider("file", fp);
    manager.init();
}
Also used : FileProvider(org.apache.commons.vfs2.provider.FileProvider) DefaultLocalFileProvider(org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider) DefaultLocalFileProvider(org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class DefaultFileSystemManager method resolveName.

/**
 * Resolves a name, relative to the root.
 *
 * @param base the base file name
 * @param name the name
 * @param scope the {@link NameScope}
 * @return The FileName of the file.
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException {
    FileSystemException.requireNonNull(base, "Invalid base FileName.");
    FileSystemException.requireNonNull(name, "Invalid name FileName.");
    final FileName realBase;
    if (VFS.isUriStyle() && base.isFile()) {
        realBase = base.getParent();
    } else {
        realBase = base;
    }
    final StringBuilder buffer = new StringBuilder(name);
    // Adjust separators
    UriParser.fixSeparators(buffer);
    String scheme = UriParser.extractScheme(getSchemes(), buffer.toString());
    // Determine whether to prepend the base path
    if (name.isEmpty() || scheme == null && buffer.charAt(0) != FileName.SEPARATOR_CHAR) {
        // Supplied path is not absolute
        if (!VFS.isUriStyle()) {
            // when using URIs the parent already do have the trailing "/"
            buffer.insert(0, FileName.SEPARATOR_CHAR);
        }
        buffer.insert(0, realBase.getPath());
    }
    // Normalise the path
    final FileType fileType = UriParser.normalisePath(buffer);
    // Check the name is ok
    final String resolvedPath = buffer.toString();
    if (!AbstractFileName.checkName(realBase.getPath(), resolvedPath, scope)) {
        throw new FileSystemException("vfs.provider/invalid-descendent-name.error", name);
    }
    final String fullPath;
    if (scheme != null) {
        fullPath = resolvedPath;
    } else {
        scheme = realBase.getScheme();
        fullPath = realBase.getRootURI() + resolvedPath;
    }
    final FileProvider provider = providers.get(scheme);
    if (provider != null) {
        return provider.parseUri(realBase, fullPath);
    }
    // An unknown scheme - hand it to the default provider - if possible
    if (scheme != null && defaultProvider != null) {
        return defaultProvider.parseUri(realBase, fullPath);
    }
    // this happens if we have a virtual filesystem (no provider for scheme)
    return ((AbstractFileName) realBase).createName(resolvedPath, fileType);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileType(org.apache.commons.vfs2.FileType) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName) FileName(org.apache.commons.vfs2.FileName) LocalFileProvider(org.apache.commons.vfs2.provider.LocalFileProvider) AbstractFileProvider(org.apache.commons.vfs2.provider.AbstractFileProvider) FileProvider(org.apache.commons.vfs2.provider.FileProvider) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName)

Example 10 with FileProvider

use of org.apache.commons.vfs2.provider.FileProvider in project commons-vfs by apache.

the class DefaultFileSystemManager method resolveFile.

/**
 * Resolves a URI, relative to a base file with specified FileSystem configuration.
 *
 * @param baseFile The base file.
 * @param uri The file name. May be a fully qualified or relative path or a url.
 * @param fileSystemOptions Options to pass to the file system.
 * @return A FileObject representing the target file.
 * @throws FileSystemException if an error occurs accessing the file.
 */
public FileObject resolveFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final FileObject realBaseFile;
    if (baseFile != null && VFS.isUriStyle() && baseFile.getName().isFile()) {
        realBaseFile = baseFile.getParent();
    } else {
        realBaseFile = baseFile;
    }
    // TODO: use resolveName and use this name to resolve the fileObject
    UriParser.checkUriEncoding(uri);
    if (uri == null) {
        throw new IllegalArgumentException();
    }
    // Extract the scheme
    final String scheme = UriParser.extractScheme(getSchemes(), uri);
    if (scheme != null) {
        // An absolute URI - locate the provider
        final FileProvider provider = providers.get(scheme);
        if (provider != null) {
            return provider.findFile(realBaseFile, uri, fileSystemOptions);
        }
    // Otherwise, assume a local file
    }
    // Handle absolute file names
    if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
        return localFileProvider.findLocalFile(uri);
    }
    if (scheme != null) {
        // An unknown scheme - hand it to the default provider
        FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
        return defaultProvider.findFile(realBaseFile, uri, fileSystemOptions);
    }
    // Assume a relative name - use the supplied base file
    FileSystemException.requireNonNull(realBaseFile, "vfs.impl/find-rel-file.error", uri);
    return realBaseFile.resolveFile(uri);
}
Also used : LocalFileProvider(org.apache.commons.vfs2.provider.LocalFileProvider) AbstractFileProvider(org.apache.commons.vfs2.provider.AbstractFileProvider) FileProvider(org.apache.commons.vfs2.provider.FileProvider) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileProvider (org.apache.commons.vfs2.provider.FileProvider)10 AbstractFileProvider (org.apache.commons.vfs2.provider.AbstractFileProvider)6 LocalFileProvider (org.apache.commons.vfs2.provider.LocalFileProvider)6 FileName (org.apache.commons.vfs2.FileName)2 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)1 FileType (org.apache.commons.vfs2.FileType)1 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)1 AbstractFileName (org.apache.commons.vfs2.provider.AbstractFileName)1 DefaultLocalFileProvider (org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider)1 Test (org.junit.Test)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 VfsEmbeddedFileSystemCloser (org.pentaho.di.core.osgi.api.VfsEmbeddedFileSystemCloser)1 GoogleDriveFileProvider (org.pentaho.googledrive.vfs.GoogleDriveFileProvider)1