Example usage for org.apache.commons.vfs2 CacheStrategy ON_RESOLVE

List of usage examples for org.apache.commons.vfs2 CacheStrategy ON_RESOLVE

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 CacheStrategy ON_RESOLVE.

Prototype

CacheStrategy ON_RESOLVE

To view the source code for org.apache.commons.vfs2 CacheStrategy ON_RESOLVE.

Click Source Link

Document

Refresh the data every time you request a file from FileSystemManager#resolveFile .

Usage

From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java

/**
 * Open./*from  www .  j av  a2 s  .c  om*/
 * 
 * @param user the user
 * @param pwd the pwd
 * @param scheme the scheme
 * 
 * @throws MotuException the motu exception
 */
public void open(String user, String pwd, String scheme, String host) throws MotuException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("open(String, String, String) - entering");
    }

    if (isOpened()) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("open(String, String, String) - exiting");
        }
        return;
    }

    standardFileSystemManager = new StandardFileSystemManager();
    standardFileSystemManager.setLogger(LogFactory.getLog(VFS.class));
    standardFileSystemManager.setClassLoader(this.getClass().getClassLoader());
    try {
        standardFileSystemManager
                .setConfiguration(ConfigLoader.getInstance().get(Organizer.getVFSProviderConfig()));
        //standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL);
        standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        // standardFileSystemManager.setFilesCache(new SoftRefFilesCache());
        // standardFileSystemManager.addProvider("jar", new JarFileProvider());
        standardFileSystemManager.init();
        open = true;
    } catch (FileSystemException e) {
        LOG.fatal("Error in VFS initialisation - Unable to intiialize VFS", e);
        throw new MotuException("Error in VFS initialisation - Unable to intiialize VFS", e);
    } catch (IOException e) {
        LOG.fatal("Error in VFS initialisation - Unable to intiialize VFS", e);
        throw new MotuException("Error in VFS initialisation - Unable to intiialize VFS", e);
    }

    opts = new FileSystemOptions();

    setUserInfo(user, pwd);
    setSchemeOpts(scheme, host);

    if (LOG.isDebugEnabled()) {
        LOG.debug("open(String, String, String) - exiting");
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignManager.java

protected CacheStrategy getVFSCacheStrategy() {
    return CacheStrategy.ON_RESOLVE;
}

From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java

public static void testVFS(String user, String pwd, String scheme, String host, String file) {

    StandardFileSystemManager fsManager = null;

    try {/*from  w  ww  .  java 2 s.  c o  m*/
        fsManager = new StandardFileSystemManager();
        fsManager.setLogger(_LOG);

        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pwd);

        fsManager.setConfiguration(ConfigLoader.getInstance().get(Organizer.getVFSProviderConfig()));
        fsManager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        // fsManager.addProvider("moi", new DefaultLocalFileProvider());
        fsManager.init();

        FileSystemOptions opts = new FileSystemOptions();
        FileSystemConfigBuilder fscb = fsManager.getFileSystemConfigBuilder(scheme);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

        System.out.println(fsManager.getProviderCapabilities(scheme));

        if (fscb instanceof FtpFileSystemConfigBuilder) {
            FtpFileSystemConfigBuilder ftpFscb = (FtpFileSystemConfigBuilder) fscb;
            ftpFscb.setUserDirIsRoot(opts, true);
            ftpFscb.setPassiveMode(opts, true);

        }
        if (fscb instanceof HttpFileSystemConfigBuilder) {
            HttpFileSystemConfigBuilder httpFscb = (HttpFileSystemConfigBuilder) fscb;
            httpFscb.setProxyHost(opts, "proxy.cls.fr");
            httpFscb.setProxyPort(opts, 8080);

        }
        if (fscb instanceof SftpFileSystemConfigBuilder) {
            SftpFileSystemConfigBuilder sftpFscb = (SftpFileSystemConfigBuilder) fscb;
            sftpFscb.setUserDirIsRoot(opts, false);

            // TrustEveryoneUserInfo trustEveryoneUserInfo = new TrustEveryoneUserInfo();
            // trustEveryoneUserInfo.promptYesNo("eddfsdfs");
            // sftpFscb.setUserInfo(opts, new TrustEveryoneUserInfo());
            sftpFscb.setTimeout(opts, 5000);
            // SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
            // SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");

        }
        // FileObject fo =
        // fsManager.resolveFile("ftp://ftp.cls.fr/pub/oceano/AVISO/NRT-SLA/maps/rt/j2/h/msla_rt_j2_err_21564.nc.gz",
        // opts);

        // String uri = String.format("%s://%s/%s", scheme, host, file);
        // String uri = String.format("%s://%s/", scheme, host);
        // FileObject originBase = fsManager.resolveFile(uri, opts);
        // fsManager.setBaseFile(originBase);

        File tempDir = new File("c:/tempVFS");
        // File tempFile = File.createTempFile("AsciiEnvisat", ".txt", tempDir);
        File hostFile = new File(file);
        String fileName = hostFile.getName();
        File newFile = new File(tempDir, fileName);
        newFile.createNewFile();

        DefaultFileReplicator dfr = new DefaultFileReplicator(tempDir);
        fsManager.setTemporaryFileStore(dfr);
        // System.out.println(fsManager.getBaseFile());
        // System.out.println(dfr);
        // System.out.println(fsManager.getTemporaryFileStore());

        // FileObject ff = fsManager.resolveFile("sftp://t:t@CLS-EARITH.pc.cls.fr/AsciiEnvisat.txt",
        // opts);
        String uri = String.format("%s://%s/%s", scheme, host, file);
        FileObject ff = fsManager.resolveFile(uri, opts);
        FileObject dest = fsManager.toFileObject(newFile);

        //ff.getContent().getInputStream();
        dest.copyFrom(ff, Selectors.SELECT_ALL);
        //dest.copyFrom(ff, Selectors.SELECT_ALL);

        //            
        // URL url = ff.getURL();
        //            
        // url.openConnection();
        // URLConnection conn = url.openConnection();
        // InputStream in = conn.getInputStream();
        // in.close();

        // InputStream in = ff.getContent().getInputStream();

    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MotuException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        // fsManager.close();
        // fsManager.freeUnusedResources();
    }

}

From source file:org.apache.accumulo.start.classloader.vfs.AccumuloVFSClassLoader.java

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();/*  ww  w.ja  va2 s. co m*/
    vfsInstances.add(new WeakReference<DefaultFileSystemManager>(vfs));
    return vfs;
}

From source file:org.apache.accumulo.start.classloader.vfs.providers.HdfsFileSystem.java

@Override
public FileObject resolveFile(final FileName name) throws FileSystemException {

    synchronized (this) {
        if (null == this.fs) {
            final String hdfsUri = name.getRootURI();
            final Configuration conf = new Configuration(true);
            conf.set(org.apache.hadoop.fs.FileSystem.FS_DEFAULT_NAME_KEY, hdfsUri);
            this.fs = null;
            try {
                fs = org.apache.hadoop.fs.FileSystem.get(conf);
            } catch (final IOException e) {
                log.error("Error connecting to filesystem " + hdfsUri, e);
                throw new FileSystemException("Error connecting to filesystem " + hdfsUri, e);
            }// ww  w  .j a  va2s .co  m
        }
    }

    boolean useCache = (null != getContext().getFileSystemManager().getFilesCache());
    FileObject file;
    if (useCache) {
        file = this.getFileFromCache(name);
    } else {
        file = null;
    }
    if (null == file) {
        String path = null;
        try {
            path = URLDecoder.decode(name.getPath(), UTF_8.name());
        } catch (final UnsupportedEncodingException e) {
            path = name.getPath();
        }
        final Path filePath = new Path(path);
        file = new HdfsFileObject((AbstractFileName) name, this, fs, filePath);
        if (useCache) {
            this.putFileToCache(file);
        }

    }

    /**
     * resync the file information if requested
     */
    if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
        file.refresh();
    }

    return file;
}

From source file:org.apache.accumulo.start.test.AccumuloDFSBase.java

@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());
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 1024); // 1M blocksize

    try {/*ww w  . ja  va2  s.c o  m*/
        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);
    }

}

From source file:org.apache.accumulo.test.AccumuloDFSBase.java

@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());
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 1024); // 1M blocksize

    try {/*w w w  .  j  a  v a2s . c  o  m*/
        cluster = new MiniDFSCluster(conf, 1, true, null);
        cluster.waitActive();
        // 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);
    }

}

From source file:org.apache.metron.common.utils.VFSClassloaderUtil.java

/**
 * Create a FileSystem manager suitable for our purposes.
 * This manager supports files of the following types:
 * * res - resource files// ww  w .  j  av a2  s.  c om
 * * jar
 * * tar
 * * bz2
 * * tgz
 * * zip
 * * HDFS
 * * FTP
 * * HTTP/S
 * * file
 * @return
 * @throws FileSystemException
 */
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());
    vfs.setReplicator(new UniqueFileReplicator(new File(System.getProperty("java.io.tmpdir"))));
    vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    vfs.init();
    return vfs;
}

From source file:org.celeria.minecraft.backup.FileSystemManagerProvider.java

private void build() throws FileSystemException {
    manager.addProvider("file", provider);
    manager.setFilesCache(cache);//from w w w. j av a2 s .c o m
    manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    manager.setBaseFile(new File("."));
}

From source file:org.pentaho.googledrive.vfs.GoogleDriveFileSystem.java

private synchronized FileObject processFile(FileName name, boolean useCache) throws FileSystemException {
    if (!super.getRootName().getRootURI().equals(name.getRootURI())) {
        throw new FileSystemException("vfs.provider/mismatched-fs-for-name.error",
                new Object[] { name, super.getRootName(), name.getRootURI() });
    } else {/*from  w  w w .  j  a  v a  2  s .c o m*/
        FileObject file;
        if (useCache) {
            file = super.getFileFromCache(name);
        } else {
            file = null;
        }

        if (file == null) {
            try {
                file = this.createFile((AbstractFileName) name);
            } catch (Exception var5) {
                return null;
            }

            file = super.decorateFileObject(file);
            if (useCache) {
                super.putFileToCache(file);
            }
        }

        if (super.getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
            file.refresh();
        }

        return file;
    }
}