use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project hop by apache.
the class HopVfs method createFileSystemManager.
/**
* Make sure to close when done using!
*
* @return A new standard file system manager
* @throws HopException
*/
private static DefaultFileSystemManager createFileSystemManager() throws HopException {
try {
DefaultFileSystemManager fsm = new DefaultFileSystemManager();
fsm.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
fsm.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
fsm.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
fsm.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
fsm.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
fsm.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
fsm.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
fsm.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
fsm.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
fsm.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
fsm.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
fsm.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
fsm.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
fsm.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
fsm.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
fsm.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
fsm.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
fsm.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
fsm.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
fsm.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
fsm.addProvider("files-cache", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
fsm.addExtensionMap("jar", "jar");
fsm.addExtensionMap("zip", "zip");
fsm.addExtensionMap("gz", "gz");
fsm.addExtensionMap("tar", "tar");
fsm.addExtensionMap("tbz2", "tar");
fsm.addExtensionMap("tgz", "tar");
fsm.addExtensionMap("bz2", "bz2");
fsm.addMimeTypeMap("application/x-tar", "tar");
fsm.addMimeTypeMap("application/x-gzip", "gz");
fsm.addMimeTypeMap("application/zip", "zip");
fsm.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
fsm.setReplicator(new DefaultFileReplicator());
fsm.setFilesCache(new SoftRefFilesCache());
fsm.setCacheStrategy(CacheStrategy.ON_RESOLVE);
// Here are extra VFS plugins to register
//
PluginRegistry registry = PluginRegistry.getInstance();
List<IPlugin> plugins = registry.getPlugins(VfsPluginType.class);
for (IPlugin plugin : plugins) {
IVfs iVfs = registry.loadClass(plugin, IVfs.class);
try {
fsm.addProvider(iVfs.getUrlSchemes(), iVfs.getProvider());
} catch (Exception e) {
throw new HopException("Error registering provider for VFS plugin " + plugin.getIds()[0] + " : " + plugin.getName() + " : ", e);
}
}
fsm.init();
return fsm;
} catch (Exception e) {
throw new HopException("Error creating file system manager", e);
}
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project hop by apache.
the class HopVfs method startsWithScheme.
/**
* Check if filename starts with one of the known protocols like file: zip: ram: smb: jar: etc. If
* yes, return true otherwise return false
*
* @param vfsFileName
* @return boolean
*/
public static boolean startsWithScheme(String vfsFileName) {
lock.readLock().lock();
try {
DefaultFileSystemManager fsManager = getFileSystemManager();
boolean found = false;
String[] schemes = fsManager.getSchemes();
for (int i = 0; i < schemes.length; i++) {
if (vfsFileName.startsWith(schemes[i] + ":")) {
found = true;
break;
}
}
return found;
} finally {
lock.readLock().unlock();
}
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project hop by apache.
the class S3FileObjectTest method setUp.
@Before
public void setUp() throws Exception {
s3ServiceMock = mock(AmazonS3.class);
S3Object s3Object = new S3Object();
s3Object.setKey(OBJECT_NAME);
s3Object.setBucketName(BUCKET_NAME);
filename = new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME, FileType.FOLDER);
S3FileName rootFileName = new S3FileName(SCHEME, "", "", FileType.FOLDER);
S3HopProperty s3HopProperty = mock(S3HopProperty.class);
when(s3HopProperty.getPartSize()).thenReturn("5MB");
S3FileSystem fileSystem = new S3FileSystem(rootFileName, new FileSystemOptions(), new StorageUnitConverter(), s3HopProperty);
fileSystemSpy = spy(fileSystem);
VfsComponentContext context = mock(VfsComponentContext.class);
final DefaultFileSystemManager fsm = new DefaultFileSystemManager();
FilesCache cache = mock(FilesCache.class);
fsm.setFilesCache(cache);
fsm.setCacheStrategy(CacheStrategy.ON_RESOLVE);
when(context.getFileSystemManager()).thenReturn(fsm);
fileSystemSpy.setContext(context);
S3FileObject s3FileObject = new S3FileObject(filename, fileSystemSpy);
s3FileObjectBucketSpy = spy(s3FileObject);
s3FileObjectFileSpy = spy(new S3FileObject(new S3FileName(SCHEME, BUCKET_NAME, BUCKET_NAME + "/" + origKey, FileType.IMAGINARY), fileSystemSpy));
S3FileObject s3FileObjectRoot = new S3FileObject(rootFileName, fileSystemSpy);
s3FileObjectSpyRoot = spy(s3FileObjectRoot);
// specify the behaviour of S3 Service
// when( s3ServiceMock.getBucket( BUCKET_NAME ) ).thenReturn( testBucket );
when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object);
when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object);
when(s3ServiceMock.listBuckets()).thenReturn(createBuckets());
when(s3ServiceMock.doesBucketExistV2(BUCKET_NAME)).thenReturn(true);
childObjectListing = mock(ObjectListing.class);
when(childObjectListing.getObjectSummaries()).thenReturn(createObjectSummaries(0)).thenReturn(new ArrayList<>());
when(childObjectListing.getCommonPrefixes()).thenReturn(new ArrayList<>()).thenReturn(createCommonPrefixes(3));
when(childObjectListing.isTruncated()).thenReturn(true).thenReturn(false);
when(s3ServiceMock.listObjects(any(ListObjectsRequest.class))).thenReturn(childObjectListing);
when(s3ServiceMock.listObjects(anyString(), anyString())).thenReturn(childObjectListing);
when(s3ServiceMock.listNextBatchOfObjects(any(ObjectListing.class))).thenReturn(childObjectListing);
s3ObjectMock = mock(S3Object.class);
s3ObjectInputStream = mock(S3ObjectInputStream.class);
s3ObjectMetadata = mock(ObjectMetadata.class);
when(s3ObjectMock.getObjectContent()).thenReturn(s3ObjectInputStream);
when(s3ServiceMock.getObjectMetadata(anyString(), anyString())).thenReturn(s3ObjectMetadata);
when(s3ObjectMetadata.getContentLength()).thenReturn(contentLength);
when(s3ObjectMetadata.getLastModified()).thenReturn(testDate);
when(s3ServiceMock.getObject(anyString(), anyString())).thenReturn(s3ObjectMock);
when(fileSystemSpy.getS3Client()).thenReturn(s3ServiceMock);
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project agileway by fangjinuo.
the class AgilewayVFSManagerBootstrap method startup.
public static void startup() throws Throwable {
FileSystemManager defaultFSManager = VFS.getManager();
VFSUtils.addFileProvider((DefaultFileSystemManager) defaultFSManager, new SftpFileProvider(), "sftp");
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project agileway by fangjinuo.
the class VFSUtils method removeFileProvider.
public static void removeFileProvider(final DefaultFileSystemManager fileSystemManager, String uriSchema) {
if (fileSystemManager.hasProvider(uriSchema)) {
FileProvider provider = getAllProviders(fileSystemManager).remove(uriSchema);
if (provider != null) {
FileProvider defaultProvider = Reflects.getFieldValue(defaultFileSystemManager_defaultProvider, fileSystemManager, true, false);
if (defaultProvider == provider) {
Reflects.setFieldValue(defaultFileSystemManager_defaultProvider, fileSystemManager, null, true, false);
}
List<Object> components = Reflects.getFieldValue(defaultFileSystemManager_components, fileSystemManager, true, false);
components.remove(provider);
}
}
}
Aggregations