Search in sources :

Example 6 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 in project jackrabbit by apache.

the class VFSFileSystem method list.

@Override
public String[] list(String folderPath) throws FileSystemException {
    try {
        final FileObject fo = resolveFileObject(folderPath);
        final FileObject[] children = fo.getChildren();
        final int size = children.length;
        final String[] entries = new String[size];
        for (int i = 0; i < size; i++) {
            entries[i] = children[i].getName().getBaseName();
        }
        return entries;
    } catch (org.apache.commons.vfs2.FileSystemException e) {
        final String msg = "Failed to list children of the folder at " + folderPath + ".";
        log.debug(msg, e);
        throw new FileSystemException(msg, e);
    }
}
Also used : FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 7 with org.apache.commons.vfs2

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

the class SftpFileSystemWindows method executeCommandWinClass.

/**
 * {@link  org.apache.commons.vfs2.provider.sftp.SftpFileSystem#executeCommand(java.lang.String,
 * java.lang.StringBuilder) }
 */
// S106  Complains about using System.err as the error stream; System.err is fine here
// S2276 Suggests using this.wait instead of Thread.sleep in case this thread is holding a lock.
// No other methods that call this one are synchronized
@SuppressWarnings({ "squid:S106", "squid:S2276" })
private synchronized int executeCommandWinClass(String command, StringBuilder output) throws JSchException, IOException {
    this.ensureSession();
    ChannelExec channel = (ChannelExec) this.subclassSession.openChannel("exec");
    channel.setCommand(command);
    channel.setInputStream((InputStream) null);
    InputStreamReader stream = new InputStreamReader(channel.getInputStream());
    channel.setErrStream(System.err, true);
    channel.connect();
    char[] buffer = new char[128];
    int read;
    while ((read = stream.read(buffer, 0, buffer.length)) >= 0) {
        output.append(buffer, 0, read);
    }
    stream.close();
    while (!channel.isClosed()) {
        try {
            Thread.sleep(100L);
        } catch (Exception exc) {
            log.logMinimal("Warning: Error session closing. " + exc.getMessage());
        }
    }
    channel.disconnect();
    return channel.getExitStatus();
}
Also used : InputStreamReader(java.io.InputStreamReader) ChannelExec(com.jcraft.jsch.ChannelExec) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 8 with org.apache.commons.vfs2

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

the class AccumuloDFSBase method miniDfsClusterSetup.

@BeforeClass
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/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) BeforeClass(org.junit.BeforeClass)

Example 9 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 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/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 10 with org.apache.commons.vfs2

use of org.apache.commons.vfs2 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);
    }
}
Also used : IPlugin(org.apache.hop.core.plugins.IPlugin) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) IVfs(org.apache.hop.core.vfs.plugin.IVfs) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) HopException(org.apache.hop.core.exception.HopException) HopException(org.apache.hop.core.exception.HopException) HopFileException(org.apache.hop.core.exception.HopFileException) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) org.apache.commons.vfs2(org.apache.commons.vfs2) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)13 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)11 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)5 IOException (java.io.IOException)4 UserAuthenticationData (org.apache.commons.vfs2.UserAuthenticationData)4 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)4 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)4 FileContentInfoFilenameFactory (org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory)4 GenericFileName (org.apache.commons.vfs2.provider.GenericFileName)4 JSchException (com.jcraft.jsch.JSchException)3 File (java.io.File)3 HdfsFileProvider (org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider)3 ChannelExec (com.jcraft.jsch.ChannelExec)2 InputStreamReader (java.io.InputStreamReader)2 LinkedList (java.util.LinkedList)2 DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)2 AbstractFileObject (org.apache.commons.vfs2.provider.AbstractFileObject)2 HttpClient (org.apache.http.client.HttpClient)2 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)2