List of usage examples for org.apache.commons.vfs FileObject getType
public FileType getType() throws FileSystemException;
From source file:cc.aileron.commons.util.ClassPattrnFinderUtils.java
/** * ??????//from w w w .j a v a2 s .com * * @param targetPackage * @param pattern * @return * @throws IOException * @throws URISyntaxException * @throws ResourceNotFoundException */ private static final List<Class<?>> tryGetClassNameList(final String targetPackage, final Pattern pattern) throws IOException, URISyntaxException, ResourceNotFoundException { final List<Class<?>> result = new ArrayList<Class<?>>(); final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final String path = targetPackage.replace('.', '/') + "/"; final Enumeration<URL> urls = classLoader.getResources(path); while (urls.hasMoreElements()) { final URL url = urls.nextElement(); final Resource resource = ResourceConvertUtils.convertUrl(url); for (final FileObject file : resource.toFileObject().getChildren()) { final String name = file.getName().getBaseName().split("\\.")[0]; if (!file.getType().equals(FileType.FILE) || !file.getName().getExtension().equals("class")) { continue; } if (pattern != null && !pattern.matcher(name).matches()) { continue; } final Class<?> classObject = getClass(targetPackage + "." + name); if (classObject != null) { result.add(classObject); } } } return result; }
From source file:com.rapleaf.ramhdfs.RamFileSystem.java
private static boolean isFile(FileObject fo) { try {/*from w w w . j a va2s . c om*/ return fo.getType() == FileType.FILE; } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:com.rapleaf.ramhdfs.RamFileSystem.java
private static boolean isDirectory(FileObject fo) { try {/*from ww w . j a v a 2 s . c om*/ return fo.getType() == FileType.FOLDER; } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private static void assertFolder(FileObject folder) throws Exception { assertTrue(folder.exists());/*from w w w .ja v a 2 s . c om*/ assertTrue(folder.isAttached()); // exists() causes attach assertTrue(folder.isReadable()); assertTrue(folder.isWriteable()); assertFalse(folder.isHidden()); assertTrue(folder.getType().hasChildren()); assertFalse(folder.getType().hasContent()); // TODO: with combined local option, local children of GAE folder will // have a different parent; maybe we can compare paths when GaeFileName // is modified to store abspath like LocalFileName // FileObject[] children = folder.getChildren(); // for ( FileObject child : children ) { // assertEquals( folder, child.getParent() ); // FileObject childObject = folder.getChild( child.getName().getURI() ); // assertEquals( child, childObject ); // assertEquals( folder, childObject.getParent() ); // } // TODO: use folder.findFiles( Selectors.SELECT_ALL) to get all // descendants, then test FileName.isDescendant() and isAncestor() }
From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Returns whether a file object is a directory * @param fileObject A file object representation * @return whether a file object is a directory *///from w ww.j a v a2 s. c om public static boolean isDirectory(FileObject fileObject) { try { return fileObject.getType().equals(FileType.FOLDER); } catch (FileSystemException ex) { return false; } }
From source file:com.threecrickets.sincerity.util.IoUtil.java
/** * Copies a file or a complete subdirectory tree using Apache Commons VFS. * //from ww w . jav a 2s.c o m * @param manager * The file system manager * @param file * The source file or directory * @param folder * The target folder * @throws IOException * In case of an I/O error */ public static void copyRecursive(FileSystemManager manager, FileObject file, FileObject folder) throws IOException { folder.createFolder(); FileType type = file.getType(); FileObject target = manager.resolveFile(folder + "/" + file.getName().getBaseName()); if (type == FileType.FILE) org.apache.commons.vfs.FileUtil.copyContent(file, target); else if (type == FileType.FOLDER) { for (FileObject child : file.getChildren()) copyRecursive(manager, child, target); } }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeVfsTestCase.java
public static void assertEquals(File file, FileObject fileObject) throws Exception { assertEqualPaths(file, fileObject);/* w w w. j a va 2 s .c o m*/ assertEquals(file.canRead(), fileObject.isReadable()); assertEquals(file.canWrite(), fileObject.isWriteable()); assertEquals(file.exists(), fileObject.exists()); if (file.getParentFile() == null) { assertNull(fileObject.getParent()); } else { assertEqualPaths(file.getParentFile(), fileObject.getParent()); } assertEquals(file.isDirectory(), fileObject.getType().hasChildren()); assertEquals(file.isFile(), fileObject.getType().hasContent()); assertEquals(file.isHidden(), fileObject.isHidden()); if (file.isFile()) { assertEquals(file.length(), fileObject.getContent().getSize()); } if (file.isDirectory()) { // same children File[] childFiles = file.listFiles(); FileObject[] childObjects = fileObject.getChildren(); assertEquals(childFiles.length, childObjects.length); for (int i = 0; i < childFiles.length; i++) { assertEqualPaths(childFiles[i], childObjects[i]); } } }
From source file:com.panet.imeta.core.fileinput.FileInputList.java
public static FileInputList createFileList(VariableSpace space, String[] fileName, String[] fileMask, String[] fileRequired, boolean[] includeSubdirs, FileTypeFilter[] fileTypeFilters) { FileInputList fileInputList = new FileInputList(); // Replace possible environment variables... final String realfile[] = space.environmentSubstitute(fileName); final String realmask[] = space.environmentSubstitute(fileMask); for (int i = 0; i < realfile.length; i++) { final String onefile = realfile[i]; final String onemask = realmask[i]; final boolean onerequired = YES.equalsIgnoreCase(fileRequired[i]); final boolean subdirs = includeSubdirs[i]; final FileTypeFilter filter = ((fileTypeFilters == null || fileTypeFilters[i] == null) ? FileTypeFilter.ONLY_FILES : fileTypeFilters[i]);/*w w w . j av a2s. c om*/ if (Const.isEmpty(onefile)) continue; // // If a wildcard is set we search for files // if (!Const.isEmpty(onemask)) { try { // Find all file names that match the wildcard in this directory // FileObject directoryFileObject = KettleVFS.getFileObject(onefile); if (directoryFileObject != null && directoryFileObject.getType() == FileType.FOLDER) // it's a directory { FileObject[] fileObjects = directoryFileObject.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return info.getDepth() == 0 || subdirs; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); try { if (fileObject != null && filter.isFileTypeAllowed(fileObject.getType())) { String name = fileObject.getName().getBaseName(); boolean matches = Pattern.matches(onemask, name); /* if (matches) { System.out.println("File match: URI: "+info.getFile()+", name="+name+", depth="+info.getDepth()); } */ return matches; } return false; } catch (FileSystemException ex) { // Upon error don't process the file. return false; } } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length; j++) { if (fileObjects[j].exists()) fileInputList.addFile(fileObjects[j]); } } if (Const.isEmpty(fileObjects)) { if (onerequired) fileInputList.addNonAccessibleFile(directoryFileObject); } // Sort the list: quicksort, only for regular files fileInputList.sortFiles(); } else { FileObject[] children = directoryFileObject.getChildren(); for (int j = 0; j < children.length; j++) { // See if the wildcard (regexp) matches... String name = children[j].getName().getBaseName(); if (Pattern.matches(onemask, name)) fileInputList.addFile(children[j]); } // We don't sort here, keep the order of the files in the archive. } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } } else // A normal file... { try { FileObject fileObject = KettleVFS.getFileObject(onefile); if (fileObject.exists()) { if (fileObject.isReadable()) { fileInputList.addFile(fileObject); } else { if (onerequired) fileInputList.addNonAccessibleFile(fileObject); } } else { if (onerequired) fileInputList.addNonExistantFile(fileObject); } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } } } return fileInputList; }
From source file:com.panet.imeta.core.fileinput.FileInputList.java
public static FileInputList createFolderList(VariableSpace space, String[] folderName, String[] folderRequired) { FileInputList fileInputList = new FileInputList(); // Replace possible environment variables... final String realfolder[] = space.environmentSubstitute(folderName); for (int i = 0; i < realfolder.length; i++) { final String onefile = realfolder[i]; final boolean onerequired = YES.equalsIgnoreCase(folderRequired[i]); final boolean subdirs = true; final FileTypeFilter filter = FileTypeFilter.ONLY_FOLDERS; if (Const.isEmpty(onefile)) continue; FileObject directoryFileObject = null; try {// w w w . ja v a 2 s.c om // Find all folder names in this directory // directoryFileObject = KettleVFS.getFileObject(onefile); if (directoryFileObject != null && directoryFileObject.getType() == FileType.FOLDER) // it's a directory { FileObject[] fileObjects = directoryFileObject.findFiles(new AllFileSelector() { public boolean traverseDescendents(FileSelectInfo info) { return info.getDepth() == 0 || subdirs; } public boolean includeFile(FileSelectInfo info) { // Never return the parent directory of a file list. if (info.getDepth() == 0) { return false; } FileObject fileObject = info.getFile(); try { if (fileObject != null && filter.isFileTypeAllowed(fileObject.getType())) { return true; } return false; } catch (FileSystemException ex) { // Upon error don't process the file. return false; } } }); if (fileObjects != null) { for (int j = 0; j < fileObjects.length; j++) { if (fileObjects[j].exists()) fileInputList.addFile(fileObjects[j]); } } if (Const.isEmpty(fileObjects)) { if (onerequired) fileInputList.addNonAccessibleFile(directoryFileObject); } // Sort the list: quicksort, only for regular files fileInputList.sortFiles(); } else { if (onerequired && !directoryFileObject.exists()) fileInputList.addNonExistantFile(directoryFileObject); } } catch (Exception e) { LogWriter.getInstance().logError("FileInputList", Const.getStackTracker(e)); } finally { try { if (directoryFileObject != null) directoryFileObject.close(); directoryFileObject = null; } catch (Exception e) { } ; } } return fileInputList; }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>// w ww.ja va 2 s . co m * ? ?? ? . * </p> * @param source * <code>String</code> * @param target * <code>String</code> * @throws Exception */ public static void cp(String source, String target) throws Exception { try { final FileObject src = manager.resolveFile(basefile, source); FileObject dest = manager.resolveFile(basefile, target); if (dest.exists() && dest.getType() == FileType.FOLDER) { dest = dest.resolveFile(src.getName().getBaseName()); } dest.copyFrom(src, Selectors.SELECT_ALL); } catch (FileSystemException fse) { log.error(fse.toString()); ; throw new FileSystemException(fse); } }