List of usage examples for org.apache.commons.vfs.impl DefaultFileSystemManager toFileObject
public FileObject toFileObject(final File file) throws FileSystemException
From source file:com.pongasoft.kiwidoc.builder.doclet.SourceCodeParser.java
/** * Parses the sources using a doclet. It is ok to provide a big number of files, since it will * automatically be split in chunks./*from www. j ava 2 s .c om*/ * * @param library the library to store the results * @param sources the sources * @return the number of processed files * @throws IOException if there is an issue reading the files */ public int parseSources(LibraryModelBuilder library, FileObject sources, String overviewFilename, FileObject javadoc, Collection<FileObject> dependencies) throws IOException, InternalException { DefaultFileSystemManager dfs = new DefaultFileSystemManager(); dfs.addProvider("file", new DefaultLocalFileProvider()); dfs.setReplicator(new DefaultFileReplicator(IOUtils.createTempDirectory("SourceCodeParser", ""))); dfs.init(); try { File localSources = dfs.getReplicator().replicateFile(sources, SourcesSelector.INSTANCE); sources = dfs.toFileObject(localSources); FileObject[] allSources = sources.findFiles(JavaSelector.INSTANCE); if (allSources == null || allSources.length == 0) return 0; List<String> sourcePath = new ArrayList<String>(); for (FileObject sourceFile : allSources) { // if(javadoc != null) // { // String name = sources.getName().getRelativeName(sourceFile.getName()); // name = name.substring(0, name.length() - JAVA_EXTENSION.length()); // name += HTML_EXTENSION; // if(javadoc.resolveFile(name, NameScope.DESCENDENT).exists()) // sourcePath.add(sourceFile.getName().getPath()); // } // else // { // sourcePath.add(sourceFile.getName().getPath()); // } sourcePath.add(sourceFile.getName().getPath()); } List<String> deps = new ArrayList<String>(); if (dependencies != null) { for (FileObject dependency : dependencies) { if (dependency.exists()) { File localDependency = dfs.getReplicator().replicateFile(dependency, DependenciesSelector.INSTANCE); deps.add(localDependency.getCanonicalPath()); } } } FileObject overviewFile = sources.resolveFile(overviewFilename, NameScope.CHILD); String overviewPath = null; if (overviewFile.exists()) overviewPath = overviewFile.getName().getPath(); parseSources(library, overviewPath, sourcePath, deps); return sourcePath.size(); } finally { dfs.close(); } }
From source file:egovframework.rte.fdl.filehandling.FilehandlingServiceTest.java
@Test public void testCaching1() throws Exception { String testFolder = "d:/workspace/java/e-gov/eGovFramework/RTE/DEV/trunk/Foundation/egovframework.rte.fdl.filehandling/test"; FileSystemManager manager = VFS.getManager(); EgovFileUtil.writeFile(testFolder + "/file1.txt", text, "UTF-8"); /*/*from w w w . ja v a2s .c o m*/ * ? Manager ? * CacheStrategy.MANUAL : Deal with cached data manually. Call FileObject.refresh() to refresh the object data. * CacheStrategy.ON_RESOLVE : Refresh the data every time you request a file from FileSystemManager.resolveFile * CacheStrategy.ON_CALL : Refresh the data every time you call a method on the fileObject. You'll use this only if you really need the latest info as this setting is a major performance loss. */ DefaultFileSystemManager fs = new DefaultFileSystemManager(); fs.setFilesCache(manager.getFilesCache()); // zip, jar, tgz, tar, tbz2, file if (!fs.hasProvider("file")) { fs.addProvider("file", new DefaultLocalFileProvider()); } // StandardFileSystemManager fs = new StandardFileSystemManager(); fs.setCacheStrategy(CacheStrategy.ON_RESOLVE); fs.init(); // ? ? ? //FileObject foBase2 = fs.resolveFile(testFolder); log.debug("####1"); FileObject cachedFile = fs.toFileObject(new File(testFolder + "/file1.txt")); log.debug("####2"); FilesCache filesCache = fs.getFilesCache(); log.debug("####3"); filesCache.putFile(cachedFile); FileObject obj = filesCache.getFile(cachedFile.getFileSystem(), cachedFile.getName()); //FileObject baseFile = fs.getBaseFile(); // log.debug("### cachedFile.getContent().getSize() is " + cachedFile.getContent().getSize()); // long fileSize = cachedFile.getContent().getSize(); // log.debug("#########size is " + fileSize); //FileObject cachedFile1 = cachedFile.resolveFile("file2.txt"); // FileObject scratchFolder = manager.resolveFile(testFolder); // scratchFolder.delete(Selectors.EXCLUDE_SELF); EgovFileUtil.delete(new File(testFolder + "/file1.txt")); // obj.createFile(); // log.debug("#########obj is " + obj.toString()); // log.debug("#########size is " + obj.getContent().getSize()); log.debug("#########file is " + obj.exists()); fs.close(); }