List of usage examples for org.apache.commons.vfs2 VFS getManager
public static synchronized FileSystemManager getManager() throws FileSystemException
From source file:ShowProperties.java
public static void main(String[] args) throws FileSystemException { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return;//w w w . j a v a 2s.c om } 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()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > 5) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (FileSystemException ex) { ex.printStackTrace(); } } }
From source file:hadoopInstaller.Main.java
public static void main(String[] args) { // Disable VFS logging to console by default System.setProperty("org.apache.commons.logging.Log", //$NON-NLS-1$ "org.apache.commons.logging.impl.NoOpLog"); //$NON-NLS-1$ // Configure SimpleLog to show date and omit log name System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); //$NON-NLS-1$//$NON-NLS-2$ System.setProperty("org.apache.commons.logging.simplelog.showlogname", "false"); //$NON-NLS-1$//$NON-NLS-2$ System.setProperty("org.apache.commons.logging.simplelog.showShortLogname", "false"); //$NON-NLS-1$//$NON-NLS-2$ try (PrintStream filePrintStream = new PrintStream(VFS.getManager() .resolveFile(MessageFormat.format("file://{0}/{1}", //$NON-NLS-1$ System.getProperty("user.dir"), Main.FILE_LOG_NAME)) //$NON-NLS-1$ .getContent().getOutputStream(true))) { CompositeLog log = new CompositeLog(); Integer logLevel = detectLogLevel(args); PrintStreamLog consoleLog = new PrintStreamLog(Installer.INSTALLER_NAME, System.out); consoleLog.setLevel(logLevel);//w ww. ja v a 2 s.com log.addLog(consoleLog); PrintStreamLog fileLog = new PrintStreamLog(Installer.INSTALLER_NAME, filePrintStream); fileLog.setLevel(logLevel); log.addLog(fileLog); boolean deploy = Arrays.asList(args).contains("-deploy"); //$NON-NLS-1$ try { new Installer(log, deploy).run(); } catch (InstallationFatalError e) { log.fatal(e.getLocalizedMessage()); log.fatal(e.getCause().getLocalizedMessage()); log.trace(e.getLocalizedMessage(), e); } } catch (FileSystemException e) { new PrintStreamLog(Installer.INSTALLER_NAME, System.err).fatal(e.getLocalizedMessage(), e); System.exit(1); } /* * TODO-- ssh-ask * * Consider using a configuration that doesn't require password-less * authentication, but set's it up for the final cluster. */ }
From source file:maspack.fileutil.ZipUtility.java
public static void unzip(URIx src, final File dest) throws IOException { dest.mkdirs();// w ww.j a v a 2 s . co m final FileSystemManager fileSystemManager = VFS.getManager(); final FileObject zipFileObject = fileSystemManager.resolveFile(src.toString()); try { final FileObject fileSystem = fileSystemManager.createFileSystem(zipFileObject); try { fileSystemManager.toFileObject(dest).copyFrom(fileSystem, new AllFileSelector()); } finally { fileSystem.close(); } } finally { zipFileObject.close(); } }
From source file:fulcrum.xml.ParserTest.java
private static InputStream getInputStream(String location) { InputStream is = null;//from w w w .jav a2s . c o m try { FileSystemManager fsManager = VFS.getManager(); FileObject fileObj = fsManager.resolveFile(location); if (fileObj != null && fileObj.exists() && fileObj.isReadable()) { FileContent content = fileObj.getContent(); is = content.getInputStream(); } } catch (Exception e) { e.printStackTrace(); } return is; }
From source file:architecture.common.util.vfs.VFSUtils.java
public static FileObject resolveFile(File file, String filename) { try {/*from w w w .j a va 2 s . co m*/ FileObject fo = VFS.getManager().resolveFile(file, filename); return fo; } catch (FileSystemException e) { } return null; }
From source file:architecture.common.util.vfs.VFSUtils.java
public static FileObject resolveFile(FileObject file, String filename) { try {/*w w w .ja v a 2 s . c o m*/ FileObject fo = VFS.getManager().resolveFile(file, filename); return fo; } catch (FileSystemException e) { } return null; }
From source file:fi.mystes.synapse.mediator.vfs.VFSTestHelper.java
public static void deleteDirectory(String dirPath) throws FileSystemException { FileObject dir = VFS.getManager().resolveFile(dirPath); dir.delete(new AllFileSelector()); dir.delete();/*from www . j a va 2 s . c om*/ }
From source file:fi.mystes.synapse.mediator.vfs.VFSTestHelper.java
public static void createDirectory(String dirPath) throws FileSystemException { FileObject dir = VFS.getManager().resolveFile(dirPath); if (!dir.exists()) { dir.createFolder();//from ww w. j a v a 2s . com } }
From source file:architecture.common.util.vfs.VFSUtils.java
public static FileObject resolveFile(String uri) { try {/*from ww w . j a v a 2s . c om*/ return VFS.getManager().resolveFile(uri); } catch (FileSystemException e) { log.warn(e); } return null; }
From source file:mondrian.spi.impl.ApacheVfs2VirtualFileHandler.java
public InputStream readVirtualFile(String url) throws FileSystemException { // Treat catalogUrl as an Apache VFS (Virtual File System) URL. // VFS handles all of the usual protocols (http:, file:) // and then some. FileSystemManager fsManager = VFS.getManager(); if (fsManager == null) { throw Util.newError("Cannot get virtual file system manager"); }/*w w w . j a v a 2s . c o m*/ File userDir = new File("").getAbsoluteFile(); FileObject file = fsManager.resolveFile(userDir, url); FileContent fileContent = null; try { if (!file.isReadable()) { throw Util.newError("Virtual file is not readable: " + url); } fileContent = file.getContent(); } finally { file.close(); } if (fileContent == null) { throw Util.newError("Cannot get virtual file content: " + url); } return fileContent.getInputStream(); }