Search in sources :

Example 16 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project pentaho-kettle by pentaho.

the class ConnectionFileProviderTest method setup.

@Before
public void setup() throws Exception {
    connectionManager = ConnectionManager.getInstance();
    connectionManager.setMetastoreSupplier(() -> memoryMetaStore);
    addOne();
    DefaultFileSystemManager fsm = (DefaultFileSystemManager) KettleVFS.getInstance().getFileSystemManager();
    if (!fsm.hasProvider(ConnectionFileProvider.SCHEME)) {
        fsm.addProvider(ConnectionFileProvider.SCHEME, new ConnectionFileProvider());
    }
    if (!fsm.hasProvider(TestFileProvider.SCHEME)) {
        fsm.addProvider(TestFileProvider.SCHEME, new TestFileProvider());
    }
    if (!fsm.hasProvider(TestFileWithDomainProvider.SCHEME)) {
        fsm.addProvider(TestFileWithDomainProvider.SCHEME, new TestFileWithDomainProvider());
    }
}
Also used : TestFileWithDomainProvider(org.pentaho.di.connections.common.domain.TestFileWithDomainProvider) TestFileProvider(org.pentaho.di.connections.common.bucket.TestFileProvider) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) Before(org.junit.Before)

Example 17 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project accumulo by apache.

the class AccumuloVFSClassLoader method generateVfs.

public static FileSystemManager generateVfs() throws FileSystemException {
    DefaultFileSystemManager vfs = new DefaultFileSystemManager();
    vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
    vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
    vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
    vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
    vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
    vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
    vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
    vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
    vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
    vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
    vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
    vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
    vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
    vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
    vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
    vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
    vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
    vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
    vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
    vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
    vfs.addProvider("hdfs", new HdfsFileProvider());
    vfs.addExtensionMap("jar", "jar");
    vfs.addExtensionMap("zip", "zip");
    vfs.addExtensionMap("gz", "gz");
    vfs.addExtensionMap("tar", "tar");
    vfs.addExtensionMap("tbz2", "tar");
    vfs.addExtensionMap("tgz", "tar");
    vfs.addExtensionMap("bz2", "bz2");
    vfs.addMimeTypeMap("application/java-archive", "jar");
    vfs.addMimeTypeMap("application/x-tar", "tar");
    vfs.addMimeTypeMap("application/x-gzip", "gz");
    vfs.addMimeTypeMap("application/zip", "zip");
    vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
    vfs.setFilesCache(new SoftRefFilesCache());
    File cacheDir = computeTopCacheDir();
    vfs.setReplicator(new UniqueFileReplicator(cacheDir));
    vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    vfs.init();
    vfsInstances.add(new WeakReference<>(vfs));
    return vfs;
}
Also used : HdfsFileProvider(org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File)

Example 18 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project accumulo by apache.

the class AccumuloDFSBase method miniDfsClusterSetup.

@BeforeAll
public static void miniDfsClusterSetup() {
    System.setProperty("java.io.tmpdir", System.getProperty("user.dir") + "/target");
    // System.setProperty("org.apache.commons.logging.Log",
    // "org.apache.commons.logging.impl.NoOpLog");
    // Logger.getRootLogger().setLevel(Level.ERROR);
    // Put the MiniDFSCluster directory in the target directory
    System.setProperty("test.build.data", "target/build/test/data");
    // Setup HDFS
    conf = new Configuration();
    conf.set("hadoop.security.token.service.use_ip", "true");
    conf.set("dfs.datanode.data.dir.perm", MiniDFSUtil.computeDatanodeDirectoryPermission());
    // 1M blocksize
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 1024);
    try {
        cluster = new MiniDFSCluster.Builder(conf).build();
        cluster.waitClusterUp();
        // We can't assume that the hostname of "localhost" will still be "localhost" after
        // starting up the NameNode. We may get mapped into a FQDN via settings in /etc/hosts.
        HDFS_URI = cluster.getFileSystem().getUri();
    } catch (IOException e) {
        throw new RuntimeException("Error setting up mini cluster", e);
    }
    // Set up the VFS
    vfs = new DefaultFileSystemManager();
    try {
        vfs.setFilesCache(new DefaultFilesCache());
        vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
        vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
        vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
        vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
        vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
        vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
        vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
        vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
        vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
        vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
        vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
        vfs.addProvider("hdfs", new HdfsFileProvider());
        vfs.addExtensionMap("jar", "jar");
        vfs.addExtensionMap("zip", "zip");
        vfs.addExtensionMap("gz", "gz");
        vfs.addExtensionMap("tar", "tar");
        vfs.addExtensionMap("tbz2", "tar");
        vfs.addExtensionMap("tgz", "tar");
        vfs.addExtensionMap("bz2", "bz2");
        vfs.addMimeTypeMap("application/java-archive", "jar");
        vfs.addMimeTypeMap("application/x-tar", "tar");
        vfs.addMimeTypeMap("application/x-gzip", "gz");
        vfs.addMimeTypeMap("application/zip", "zip");
        vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
        vfs.setFilesCache(new SoftRefFilesCache());
        vfs.setReplicator(new DefaultFileReplicator(new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-" + System.getProperty("user.name", "nouser"))));
        vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        vfs.init();
    } catch (FileSystemException e) {
        throw new RuntimeException("Error setting up VFS", e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsFileProvider(org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) DefaultFilesCache(org.apache.commons.vfs2.cache.DefaultFilesCache) IOException(java.io.IOException) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator) File(java.io.File) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 19 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project carbon-mediation by wso2.

the class FilePollingConsumerParameterizedTest method testOutFileUri.

@Test
public void testOutFileUri() throws Exception {
    Properties vfsProperties = new Properties();
    String basePath = "";
    if ("file".equals(protocol)) {
        basePath = new File(getClass().getClassLoader().getResource("").getFile()).getAbsolutePath() + "/";
    } else if ("ftp".equals(protocol)) {
        basePath = "ftp://localhost/";
    }
    String inFileAbsoluteUri = basePath + inFileUri;
    vfsProperties.put(VFSConstants.TRANSPORT_FILE_FILE_URI, inFileAbsoluteUri);
    // Create PollingConsumer
    Constructor constructor = FilePollingConsumer.class.getConstructor(Properties.class, String.class, SynapseEnvironment.class, long.class);
    FilePollingConsumer pollingConsumer = (FilePollingConsumer) constructor.newInstance(vfsProperties, null, null, 10);
    // Initialize consumer
    Method initFileCheck = pollingConsumer.getClass().getDeclaredMethod("initFileCheck");
    initFileCheck.setAccessible(true);
    initFileCheck.invoke(pollingConsumer);
    // Resolve file object
    DefaultFileSystemManager fsManager;
    FileSystemOptions fso;
    StandardFileSystemManager fsm = new StandardFileSystemManager();
    fsm.setConfiguration(getClass().getClassLoader().getResource("providers.xml"));
    fsm.init();
    fsManager = fsm;
    String processingFileUri = basePath + fileUri;
    fso = VFSUtils.attachFileSystemOptions(VFSUtils.parseSchemeFileOptions(processingFileUri, vfsProperties), fsManager);
    FileObject fileObject = fsManager.resolveFile(processingFileUri, fso);
    // Invoke test method
    Class[] paramString = new Class[2];
    paramString[0] = FileObject.class;
    paramString[1] = String.class;
    Method resolveActualOutUrl = pollingConsumer.getClass().getDeclaredMethod("resolveActualOutUrl", paramString);
    resolveActualOutUrl.setAccessible(true);
    String resolvedOutPath = (String) resolveActualOutUrl.invoke(pollingConsumer, fileObject, basePath + outFileUri);
    Assert.assertEquals(basePath + expectedResult, resolvedOutPath);
}
Also used : Constructor(java.lang.reflect.Constructor) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) Method(java.lang.reflect.Method) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileObject(org.apache.commons.vfs2.FileObject) Properties(java.util.Properties) File(java.io.File) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions) Test(org.junit.Test)

Example 20 with DefaultFileSystemManager

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");
}
Also used : FileSystemManager(org.apache.commons.vfs2.FileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) SftpFileProvider(com.jn.agileway.vfs.provider.sftp.SftpFileProvider)

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