org.apache.commons.vfs2.impl.StandardFileSystemManager Java Examples

The following examples show how to use org.apache.commons.vfs2.impl.StandardFileSystemManager. 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: VFSUtils.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the global filesystem manager
 *
 * @return the global filesystem manager
 */
public static FileSystemManager getFileSystemManager() {
  aLock.readLock().lock();

  try {
    if (fileSystemManager == null) {
      try {
        StandardFileSystemManager fm = new StandardFileSystemManager();
        fm.setCacheStrategy(CacheStrategy.MANUAL);
        fm.init();
        LOGGER.info("Supported schemes: {} ", Joiner.on(", ").join(fm.getSchemes()));
        fileSystemManager = fm;
      } catch (Exception exc) {
        throw new RuntimeException(exc);
      }
    }

    return fileSystemManager;
  } finally {
    aLock.readLock().unlock();
  }
}
 
Example #2
Source File: Shell.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
private Shell() throws IOException {
    final String providers = System.getProperty("providers");
    final URL providersUrl = (providers != null) ? Shell.class.getResource("/" + providers) : null;

    if (providersUrl != null) {
        mgr = new StandardFileSystemManager();
        System.out.println("Custom providers configuration used: " + providersUrl);
        ((StandardFileSystemManager) mgr).setConfiguration(providersUrl);
        ((StandardFileSystemManager) mgr).init();
    } else {
        mgr = VFS.getManager();
    }

    cwd = mgr.toFileObject(new File(System.getProperty("user.dir")));
    reader = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
}
 
Example #3
Source File: StorageObject.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private FileSystemManager getFileSystemManager() throws Exception {
	if (FILESYSTEMANAGERINSTANCE == null) {
		synchronized (StorageObject.class) {
			if (FILESYSTEMANAGERINSTANCE == null) {
				StandardFileSystemManager fs = new StandardFileSystemManager();
				fs.setFilesCache(new NullFilesCache());
				fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
				fs.init();
				FILESYSTEMANAGERINSTANCE = fs;
			}
		}
	}
	return FILESYSTEMANAGERINSTANCE;
}
 
Example #4
Source File: VfsTestHelper.java    From ant-ivy with Apache License 2.0 5 votes vote down vote up
public VfsTestHelper() throws Exception {
    // setup and initialize VFS
    fsManager = new StandardFileSystemManager() {
        protected void configurePlugins() throws FileSystemException {
            // disable automatic loading of potentially unsupported extensions
        }
    };
    fsManager.setConfiguration(getClass().getResource(VFS_CONF).toString());
    fsManager.init();

    // setup and initialize ivy
    ivy = new Ivy();
    ivy.configure(new File(IVY_CONFIG_FILE));
}
 
Example #5
Source File: VfsTask.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves a URI to a file, relative to the project's base directory.
 *
 * @param uri The URI to resolve.
 * @return resolved file object.
 * @throws FileSystemException If an error occurred.
 */
protected FileObject resolveFile(final String uri) throws FileSystemException {
    if (manager == null) {
        final StandardFileSystemManager mngr = new StandardFileSystemManager();
        mngr.setLogger(new AntLogger());
        mngr.init();
        manager = mngr;
        getProject().addBuildListener(new CloseListener());
    }
    return manager.resolveFile(getProject().getBaseDir(), uri);
}
 
Example #6
Source File: VFSTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Tests {@link FileSystemManager#close()}.
 *
 * @throws FileSystemException
 * @since 2.5.0
 */
@Test
public void test_close() throws FileSystemException {
    try (FileSystemManager fileSystemManager = new StandardFileSystemManager()) {
        VFS.setManager(fileSystemManager);
        VFS.setManager(null);
    }
    Assert.assertNotNull(VFS.getManager());
    Assert.assertFalse(VFS.getManager().resolveFile(Paths.get("DoesNotExist.not").toUri()).exists());
}
 
Example #7
Source File: VFSTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Test
public void test_setManager() throws FileSystemException {
    final StandardFileSystemManager fileSystemManager = new StandardFileSystemManager();
    VFS.setManager(fileSystemManager);
    Assert.assertEquals(fileSystemManager, VFS.getManager());
    // Reset global for other tests
    VFS.setManager(null);
    Assert.assertNotNull(VFS.getManager());
    Assert.assertNotEquals(fileSystemManager, VFS.getManager());
}
 
Example #8
Source File: DelegatingFileSystemOptionsBuilderTest.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    // get a full blown, fully functional manager
    fsm = new StandardFileSystemManager();
    fsm.init();
}
 
Example #9
Source File: KettleVFS.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * @see StandardFileSystemManager#freeUnusedResources()
 */
public static void freeUnusedResources() {
  ( (StandardFileSystemManager) getInstance().getFileSystemManager() ).freeUnusedResources();
}