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);
}
}
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project agileway by fangjinuo.
the class AgilewaySftpProviderTests method testListChildren.
@Test
public void testListChildren() throws Throwable {
DefaultFileSystemManager fileSystemManager = (DefaultFileSystemManager) VFS.getManager();
String url = "sftp://fangjinuo:fjn13570@192.168.1.70:22/test2/vfs_sftp_test";
FileSystemOptions fileSystemOptions = new FileSystemOptions();
SftpFileSystemConfigBuilder configBuilder = SftpFileSystemConfigBuilder.getInstance();
configBuilder.setUserDirIsRoot(fileSystemOptions, true);
FileObject fileObject = fileSystemManager.resolveFile(url, fileSystemOptions);
System.out.println("===============Show remote directory==============");
showFile(0, fileObject);
System.out.println("===============Copy remote files to local==============");
url = "file://d:/tmp002";
FileObject localFileObject = fileSystemManager.resolveFile(url);
if (fileObject.isFolder()) {
if (!localFileObject.exists()) {
localFileObject.createFolder();
} else {
localFileObject.delete(Selectors.EXCLUDE_SELF);
}
localFileObject.copyFrom(fileObject, Selectors.EXCLUDE_SELF);
} else {
// 单独测试 文件时,将上面的 url 改成一个 文件的url即可
long writeSize = fileObject.getContent().write(localFileObject);
long expectedSize = fileObject.getContent().getSize();
Preconditions.checkTrue(writeSize == expectedSize);
localFileObject.copyFrom(fileObject, Selectors.SELECT_SELF);
}
System.out.println("================Copy local files to remote=============");
url = "sftp://fangjinuo:fjn13570@192.168.1.70:22/test2/vfs_sftp_test2";
fileObject = fileSystemManager.resolveFile(url, fileSystemOptions);
if (!fileObject.exists()) {
fileObject.createFolder();
} else {
fileObject.delete(Selectors.EXCLUDE_SELF);
}
fileObject.copyFrom(localFileObject, Selectors.EXCLUDE_SELF);
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project commons-vfs by apache.
the class LRUFilesCacheTests method testClass.
@Test
public void testClass() {
@SuppressWarnings("resource") final DefaultFileSystemManager manager = getManager();
Assertions.assertNotNull(manager, "manager");
final FilesCache filesCache = manager.getFilesCache();
assertTrue(Objects.toString(filesCache), filesCache instanceof LRUFilesCache);
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project commons-vfs by apache.
the class NullFilesCacheTests method testClass.
@Test
public void testClass() {
final DefaultFileSystemManager manager = getManager();
Assertions.assertNotNull(manager, "This test should not have a null DefaultFileSystemManager");
assertTrue(manager.getFilesCache() instanceof NullFilesCache);
}
use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project commons-vfs by apache.
the class LargeTarTest method setUp.
@BeforeEach
public void setUp() throws Exception {
manager = new DefaultFileSystemManager();
manager.setFilesCache(new SoftRefFilesCache());
manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
manager.addProvider("file", new DefaultLocalFileProvider());
manager.addProvider("tgz", new TarFileProvider());
manager.addProvider("tar", new TarFileProvider());
// if test is run standalone
new File(baseDir).mkdir();
createLargeFile(largeFilePath, largeFileName);
}
Aggregations