Java Code Examples for org.apache.commons.vfs2.impl.DefaultFileSystemManager#init()

The following examples show how to use org.apache.commons.vfs2.impl.DefaultFileSystemManager#init() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderCacheStrategyTests.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Test the on_call strategy
 */
public void testOnCallCache() throws Exception {
    final FileObject scratchFolder = getWriteFolder();
    if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class)
            || scratchFolder.getFileSystem() instanceof VirtualFileSystem) {
        // cant check ram filesystem as every manager holds its own ram filesystem data
        return;
    }

    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    final DefaultFileSystemManager fs = createManager();
    fs.setCacheStrategy(CacheStrategy.ON_CALL);
    fs.init();
    final FileObject foBase2 = getBaseTestFolder(fs);

    final FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    FileObject[] fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    scratchFolder.resolveFile("file1.txt").createFile();

    fos = cachedFolder.getChildren();
    assertContains(fos, "file1.txt");
}
 
Example 2
Source File: DefaultFileSystemManagerProvider.java    From spoofax with Apache License 2.0 6 votes vote down vote up
@Override public FileSystemManager get() {
    try {
        final DefaultFileSystemManager manager = new DefaultFileSystemManager();

        manager.setFilesCache(new DefaultFilesCache());
        manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);

        final String baseTmpDir = System.getProperty("java.io.tmpdir");
        final File tempDir = new File(baseTmpDir, "vfs_cache" + new Random().nextLong()).getAbsoluteFile();
        final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir);
        manager.setTemporaryFileStore(replicator);
        manager.setReplicator(replicator);

        addDefaultProvider(manager);
        addProviders(manager);
        setBaseFile(manager);

        manager.init();

        return manager;
    } catch(FileSystemException e) {
        throw new RuntimeException("Cannot initialize resource service: " + e.getMessage(), e);
    }
}
 
Example 3
Source File: BasicOperationsTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * JUnit Fixture: Prepare a simple FSM.
 *
 * @throws FileSystemException for runtime problems
 */
@Before
public void setUp() throws FileSystemException {
    manager = new DefaultFileSystemManager();
    final FileProvider fp = new DefaultLocalFileProvider();
    manager.addProvider("file", fp);
    manager.init();
}
 
Example 4
Source File: CustomRamProviderTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    manager = new DefaultFileSystemManager();
    manager.addProvider("ram", new RamFileProvider());
    manager.init();

    // File Systems Options
    RamFileSystemConfigBuilder.getInstance().setMaxSize(zeroSizedFso, 0L);
    RamFileSystemConfigBuilder.getInstance().setMaxSize(smallSizedFso, 10L);
}
 
Example 5
Source File: HdfsFileProviderTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    Logger.getRootLogger().setLevel(Level.ERROR);

    // Put the MiniDFSCluster directory in the target directory
    final File data = new File("target/test/hdfstestdata").getAbsoluteFile();
    data.mkdirs();
    System.setProperty("test.build.data", data.toString());
    FileUtils.cleanDirectory(data);

    // Setup HDFS
    conf = new Configuration();
    conf.set(FileSystem.FS_DEFAULT_NAME_KEY, HDFS_URI);
    conf.set("hadoop.security.token.service.use_ip", "true");
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 1024); // 1M blocksize

    setUmask(conf);

    cluster = new MiniDFSCluster(PORT, conf, 1, true, true, true, null, null, null, null);
    cluster.waitActive();

    // Set up the VFS
    manager = new DefaultFileSystemManager();
    manager.addProvider("hdfs", new HdfsFileProvider());
    manager.init();
    hdfs = cluster.getFileSystem();
}
 
Example 6
Source File: ProviderCacheStrategyTests.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Test the manual cache strategy
 */
public void testManualCache() throws Exception {
    final FileObject scratchFolder = getWriteFolder();
    if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class)
            || scratchFolder.getFileSystem() instanceof VirtualFileSystem) {
        // cant check ram filesystem as every manager holds its own ram filesystem data
        return;
    }

    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    final DefaultFileSystemManager fs = createManager();
    fs.setCacheStrategy(CacheStrategy.MANUAL);
    fs.init();
    final FileObject foBase2 = getBaseTestFolder(fs);

    final FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    FileObject[] fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    scratchFolder.resolveFile("file1.txt").createFile();

    fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    cachedFolder.refresh();
    fos = cachedFolder.getChildren();
    assertContains(fos, "file1.txt");
}
 
Example 7
Source File: ProviderCacheStrategyTests.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Test the on_resolve strategy
 */
public void testOnResolveCache() throws Exception {
    final FileObject scratchFolder = getWriteFolder();
    if (FileObjectUtils.isInstanceOf(getBaseFolder(), RamFileObject.class)
            || scratchFolder.getFileSystem() instanceof VirtualFileSystem) {
        // cant check ram filesystem as every manager holds its own ram filesystem data
        return;
    }

    scratchFolder.delete(Selectors.EXCLUDE_SELF);

    final DefaultFileSystemManager fs = createManager();
    fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
    fs.init();
    final FileObject foBase2 = getBaseTestFolder(fs);

    FileObject cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());

    FileObject[] fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    scratchFolder.resolveFile("file1.txt").createFile();

    fos = cachedFolder.getChildren();
    assertContainsNot(fos, "file1.txt");

    cachedFolder = foBase2.resolveFile(scratchFolder.getName().getPath());
    fos = cachedFolder.getChildren();
    assertContains(fos, "file1.txt");
}
 
Example 8
Source File: VFSClassloaderUtil.java    From metron with Apache License 2.0 4 votes vote down vote up
/**
 * Create a FileSystem manager suitable for our purposes.
 * This manager supports files of the following types:
 * * res - resource files
 * * jar
 * * tar
 * * bz2
 * * tgz
 * * zip
 * * HDFS
 * * FTP
 * * HTTP/S
 * * file
 * @return vfs
 * @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;
}