Package org.apache.commons.vfs2

Examples of org.apache.commons.vfs2.FileSystemManager

@author Commons VFS team

{
    private final static int NUOF_RESOLVES = 100000;

    public static void main(String[] args) throws FileSystemException
    {
        FileSystemManager mgr = VFS.getManager();

        FileObject root = mgr
                .resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr");
        FileName rootName = root.getName();

        testNames(mgr, rootName);
View Full Code Here


     * Sanity test.
     */
    public void testDefaultInstance() throws Exception
    {
        // Locate the default manager
        final FileSystemManager manager = VFS.getManager();

        // Lookup a test jar file
        final File jarFile = getTestResource("test.jar");
        FileObject file = manager.toFileObject(jarFile);
        assertNotNull(file);
        assertTrue(file.exists());
        assertSame(FileType.FILE, file.getType());

        // Expand it
        file = manager.createFileSystem(file);
        assertNotNull(file);
        assertTrue(file.exists());
        assertSame(FileType.FOLDER, file.getType());
    }
View Full Code Here

        }
        for (int i = 0; i < args.length; i++)
        {
            try
            {
                FileSystemManager mgr = VFS.getManager();
                System.out.println();
                System.out.println("Parsing: " + args[i]);
                FileObject file = mgr.resolveFile(args[i]);
                System.out.println("URL: " + file.getURL());
                System.out.println("getName(): " + file.getName());
                System.out.println("BaseName: " + file.getName().getBaseName());
                System.out.println("Extension: " + file.getName().getExtension());
                System.out.println("Path: " + file.getName().getPath());
View Full Code Here

        ConfigurationAssert.assertEquals(conf, newConfig);
    }

    private FileObject getFile(String fileName) throws Exception
    {
        FileSystemManager manager = VFS.getManager();
        FileName file = manager.resolveURI(fileName);
        FileName base = file.getParent();
        FileName path = manager.resolveName(base, file.getBaseName());
        FileSystemOptions opts = new FileSystemOptions();
        return manager.resolveFile(path.getURI(), opts);
    }
View Full Code Here

    RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
    return factory.getScriptEngine(createSession(servletContext));
  }

  public static Session createSession(ServletContext servletContext) {
    FileSystemManager fileSystemManager;
    try {
      fileSystemManager = createFileSystemManager(servletContext);
    } catch (FileSystemException e) {
      LOG.log(Level.SEVERE, "Failed to initialize VFS file system manager", e);
      throw new RuntimeException(e);
    }
    try {

      // initialize our master context here; a fresh but shallow copy will
      // be forked on each incoming request
      Session session = new SessionBuilder()
      .withFileSystemManager(fileSystemManager)
      .withDefaultPackages()
      .build();
     
      session.setWorkingDirectory(fileSystemManager.resolveFile("file:///"));
     
      return session;
    } catch (IOException e) {
      LOG.log(Level.SEVERE, "Failed to initialize master context", e);
      throw new RuntimeException(e);
View Full Code Here

  public void test() throws FileSystemException {

    File basePath = new File(getClass().getResource("/jarfiletest.jar").getFile())
                      .getParentFile();

    FileSystemManager dfsm = AppEngineContextFactory.createFileSystemManager(
        new AppEngineLocalFilesSystemProvider(basePath));

    FileObject jarFile = dfsm.resolveFile("/jarfiletest.jar");
    assertThat(jarFile.getName().getURI(), equalTo("file:///jarfiletest.jar"));
    assertThat(jarFile.exists(), equalTo(true));

    FileObject jarRoot = dfsm.resolveFile("jar:file:///jarfiletest.jar!/r/library");
    assertThat(jarRoot.exists(), equalTo(true));
    assertThat(jarRoot.getType(), equalTo(FileType.FOLDER));
    assertThat(jarRoot.getChildren().length, equalTo(1));
  }
View Full Code Here

public class AppEngineContextFactoryTest {

  @Test
  public void rootFile() throws IOException {
    DefaultLocalFileProvider localFileProvider = new DefaultLocalFileProvider();
    FileSystemManager fsm = AppEngineContextFactory.createFileSystemManager(localFileProvider);

    Session session = new SessionBuilder()
    .withFileSystemManager(fsm)
    .build();
   
View Full Code Here

    ReloadingClassLoader localLoader = loader;
    while (null == localLoader) {
      synchronized (lock) {
        if (null == loader) {
         
          FileSystemManager vfs = generateVfs();
         
          // Set up the 2nd tier class loader
          if (null == parent) {
            parent = AccumuloClassLoader.getClassLoader();
          }
View Full Code Here

            return null;
        }

        try
        {
            FileSystemManager fsManager = VFS.getManager();
            String uri = resolveFileURI();
            if (uri == null)
            {
                throw new ConfigurationRuntimeException("Unable to determine file to monitor");
            }
            return fsManager.resolveFile(uri);
        }
        catch (FileSystemException fse)
        {
            String msg = "Unable to monitor " + getFileHandler().getURL().toString();
            log.error(msg);
View Full Code Here

    public OutputStream getOutputStream(URL url) throws ConfigurationException
    {
        try
        {
            FileSystemOptions opts = getOptions(url.getProtocol());
            FileSystemManager fsManager = VFS.getManager();
            FileObject file = (opts == null) ? fsManager.resolveFile(url.toString())
                    : fsManager.resolveFile(url.toString(), opts);
            // throw an exception if the target URL is a directory
            if (file == null || file.getType() == FileType.FOLDER)
            {
                throw new ConfigurationException("Cannot save a configuration to a directory");
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.vfs2.FileSystemManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.