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));
}
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());
}
}
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;
}
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);
}
}
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();
}
Aggregations