Search in sources :

Example 21 with DefaultFileSystemManager

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

Example 22 with DefaultFileSystemManager

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);
}
Also used : DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) SftpFileSystemConfigBuilder(com.jn.agileway.vfs.provider.sftp.SftpFileSystemConfigBuilder) FileObject(org.apache.commons.vfs2.FileObject) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 23 with DefaultFileSystemManager

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);
}
Also used : DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FilesCache(org.apache.commons.vfs2.FilesCache) Test(org.junit.Test)

Example 24 with DefaultFileSystemManager

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

Example 25 with DefaultFileSystemManager

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);
}
Also used : SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) DefaultLocalFileProvider(org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)45 File (java.io.File)13 FileSystemException (org.apache.commons.vfs2.FileSystemException)13 Test (org.junit.Test)13 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)10 FileObject (org.apache.commons.vfs2.FileObject)9 IOException (java.io.IOException)6 DefaultLocalFileProvider (org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider)5 Before (org.junit.Before)5 AmazonS3 (com.amazonaws.services.s3.AmazonS3)4 ArrayList (java.util.ArrayList)4 FilesCache (org.apache.commons.vfs2.FilesCache)4 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)4 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)4 VfsComponentContext (org.apache.commons.vfs2.provider.VfsComponentContext)4 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)3 DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)3 FileContentInfoFilenameFactory (org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory)3