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));
}
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();
}
}
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();
}
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);
}
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);
}
Aggregations