Search in sources :

Example 26 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project commons-vfs by apache.

the class TemporaryProviderTestCase method prepare.

/**
 * Prepares the file system manager.
 */
@Override
public void prepare(final DefaultFileSystemManager manager) throws Exception {
    final File baseDir = getTestDirectoryFile();
    manager.addProvider("tmp", new TemporaryFileProvider(baseDir));
}
Also used : VfsTestUtils.getTestDirectoryFile(org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile) File(java.io.File)

Example 27 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project commons-vfs by apache.

the class WindowsFileNameTests method testWindowsRoots.

@Test
public void testWindowsRoots() throws Exception {
    // valid URI forms of the filesystem root
    final String[] tests = { "file:///C:/", "file://C:/", "file:/C:/", "file:C:/" };
    for (final String name : tests) {
        final DefaultFileSystemManager manager = getManager();
        Assertions.assertNotNull(manager, "Unexpected null manager for test " + this);
        final FileName fn = manager.resolveFile(name).getName();
        // the following tests work for Windows file names only
        assertSame(WindowsFileName.class, fn.getClass());
        // all should result in the same FileName
        assertEquals("file:///C:/", fn.toString());
        assertEquals("/", fn.getPath());
        assertEquals("/", fn.getPathDecoded());
        assertEquals("file:///C:/", fn.getRootURI());
        assertEquals("file:///C:/", fn.getFriendlyURI());
        assertEquals("file:///C:/", fn.getRoot().toString());
        assertEquals("", fn.getExtension());
        assertEquals("", fn.getBaseName());
    }
}
Also used : FileName(org.apache.commons.vfs2.FileName) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) Test(org.junit.Test)

Example 28 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project metron by apache.

the class VFSClassloaderUtil method generateVfs.

/**
 * 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;
}
Also used : HdfsFileProvider(org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider) UniqueFileReplicator(org.apache.accumulo.start.classloader.vfs.UniqueFileReplicator) 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 29 with DefaultFileSystemManager

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

the class AccumuloVFSClassLoader method close.

public static void close() {
    for (WeakReference<DefaultFileSystemManager> vfsInstance : vfsInstances) {
        DefaultFileSystemManager ref = vfsInstance.get();
        if (ref != null) {
            FileReplicator replicator;
            try {
                replicator = ref.getReplicator();
                if (replicator instanceof UniqueFileReplicator) {
                    ((UniqueFileReplicator) replicator).close();
                }
            } catch (FileSystemException e) {
                log.error("FileSystemException", e);
            }
            ref.close();
        }
    }
    try {
        FileUtils.deleteDirectory(computeTopCacheDir());
    } catch (IOException e) {
        log.error("IOException", e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) FileReplicator(org.apache.commons.vfs2.provider.FileReplicator)

Example 30 with DefaultFileSystemManager

use of org.apache.commons.vfs2.impl.DefaultFileSystemManager in project Portofino by ManyDesigns.

the class GrizzlyMain method main.

public static void main(String[] args) throws Exception {
    File currentDirectory = new File("");
    FileSystemManager manager = VFS.getManager();
    if (manager instanceof DefaultFileSystemManager) {
        ((DefaultFileSystemManager) manager).setBaseFile(currentDirectory);
    }
    String rootPath = currentDirectory.getAbsolutePath();
    if (args.length > 0) {
        rootPath = args[0];
    }
    FileObject codeBaseRoot;
    try {
        codeBaseRoot = VFS.getManager().resolveFile("res:");
    } catch (Exception e) {
        codeBaseRoot = VFS.getManager().resolveFile("res:com/manydesigns/portofino/dispatcher/main/GrizzlyMain.class").getParent().getParent().getParent().getParent().getParent().getParent();
    }
    CodeBase codeBase = new JavaCodeBase(codeBaseRoot);
    codeBase = new GroovyCodeBase(codeBaseRoot, codeBase);
    ResourceResolvers resourceResolver = new ResourceResolvers();
    resourceResolver.resourceResolvers.add(new JavaResourceResolver(codeBase));
    resourceResolver.resourceResolvers.add(new GroovyResourceResolver(codeBase));
    FileObject root = manager.resolveFile(rootPath);
    logger.info("Codebase rootFactory: " + codeBaseRoot.getURL());
    logger.info("Root path: " + root.getURL());
    DocumentedApiRoot.setRootFactory(() -> Root.get(root, resourceResolver));
    String host = System.getProperty("portofino.web.host", "0.0.0.0");
    String port = System.getProperty("portofino.web.port", "8090");
    ResourceConfig config = new ResourceConfig(ApplicationRoot.class, OpenApiResource.class);
    config.property(ServletProperties.FILTER_FORWARD_ON_404, true);
    try {
        config.register(Class.forName("org.glassfish.jersey.jackson.JacksonFeature"));
        ResourceResolver jacksonRR = (ResourceResolver) Class.forName("com.manydesigns.portofino.dispatcher.resolvers.JacksonResourceResolver").newInstance();
        resourceResolver.resourceResolvers.add(new CachingResourceResolver(jacksonRR));
    } catch (ClassNotFoundException e) {
    // Jackson not available
    }
    try {
        config.register(Class.forName("com.manydesigns.portofino.dispatcher.security.ShiroResourceFilter"));
    } catch (ClassNotFoundException e) {
    // Shiro not available
    }
    /* TODO
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setSchemes(new String[]{"http"});
        beanConfig.setHost(host + ":" + port);
        beanConfig.setBasePath("/");
        beanConfig.setResourcePackage(ApplicationRoot.class.getPackage().getName());
        beanConfig.setScan(true);*/
    URI uri = URI.create("http://" + host + ":" + port + "/");
    HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(uri, config);
    // https://scalajamsession.wordpress.com/2015/06/27/how-to-serve-static-files-with-jerseygrizzly-setup-and-control-access-to-static-content/
    ClassLoader loader = GrizzlyMain.class.getClassLoader();
    CLStaticHttpHandler webjarsHandler = new CLStaticHttpHandler(loader, "META-INF/resources/webjars/");
    httpServer.getServerConfiguration().addHttpHandler(webjarsHandler, "/webjars/");
    httpServer.start();
}
Also used : CLStaticHttpHandler(org.glassfish.grizzly.http.server.CLStaticHttpHandler) ResourceResolvers(com.manydesigns.portofino.dispatcher.resolvers.ResourceResolvers) JavaResourceResolver(com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver) CodeBase(com.manydesigns.portofino.code.CodeBase) JavaCodeBase(com.manydesigns.portofino.code.JavaCodeBase) GroovyCodeBase(com.manydesigns.portofino.code.GroovyCodeBase) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) URI(java.net.URI) CachingResourceResolver(com.manydesigns.portofino.dispatcher.resolvers.CachingResourceResolver) GroovyResourceResolver(com.manydesigns.portofino.dispatcher.resolvers.GroovyResourceResolver) GroovyCodeBase(com.manydesigns.portofino.code.GroovyCodeBase) ResourceResolver(com.manydesigns.portofino.dispatcher.ResourceResolver) GroovyResourceResolver(com.manydesigns.portofino.dispatcher.resolvers.GroovyResourceResolver) CachingResourceResolver(com.manydesigns.portofino.dispatcher.resolvers.CachingResourceResolver) JavaResourceResolver(com.manydesigns.portofino.dispatcher.resolvers.JavaResourceResolver) HttpServer(org.glassfish.grizzly.http.server.HttpServer) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileObject(org.apache.commons.vfs2.FileObject) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) File(java.io.File) JavaCodeBase(com.manydesigns.portofino.code.JavaCodeBase)

Aggregations

DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)45 File (java.io.File)13 FileSystemException (org.apache.commons.vfs2.FileSystemException)13 Test (org.junit.Test)13 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)10 FileObject (org.apache.commons.vfs2.FileObject)9 IOException (java.io.IOException)6 DefaultLocalFileProvider (org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider)5 Before (org.junit.Before)5 AmazonS3 (com.amazonaws.services.s3.AmazonS3)4 ArrayList (java.util.ArrayList)4 FilesCache (org.apache.commons.vfs2.FilesCache)4 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)4 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)4 VfsComponentContext (org.apache.commons.vfs2.provider.VfsComponentContext)4 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)3 DefaultFileReplicator (org.apache.commons.vfs2.impl.DefaultFileReplicator)3 FileContentInfoFilenameFactory (org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory)3