List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private static void assertFolder(FileObject folder) throws Exception { assertTrue(folder.exists()); assertTrue(folder.isAttached()); // exists() causes attach assertTrue(folder.isReadable());/* w w w . ja v a2 s .com*/ 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:cc.aileron.commons.resource.ResourceLoaders.java
/** * try-load/*w w w . j ava 2 s . co m*/ * * @param path * @return * @throws URISyntaxException * @throws MalformedURLException * @throws ResourceNotFoundException */ private static Resource tryLoad(final String path) throws URISyntaxException, MalformedURLException, ResourceNotFoundException { for (final Entry<Type, Loader> entry : map.entrySet()) { final ResourceLoaders.Type type = entry.getKey(); final ResourceLoaders.Loader loader = entry.getValue(); try { final FileObject file = loader.get(path); if (file.exists()) { return new ResourceImpl(file.getContent(), type); } } catch (final Exception e)// ????? { } } throw new ResourceNotFoundException(path); }
From source file:com.panet.imeta.core.vfs.KettleVFS.java
public static boolean fileExists(String vfsFilename) throws IOException { FileObject fileObject = getFileObject(vfsFilename); return fileObject.exists(); }
From source file:com.panet.imeta.core.vfs.KettleVFS.java
public static OutputStream getOutputStream(FileObject fileObject, boolean append) throws IOException { FileObject parent = fileObject.getParent(); if (parent != null) { if (!parent.exists()) { throw new IOException( Messages.getString("KettleVFS.Exception.ParentDirectoryDoesNotExist", getFilename(parent))); }//from ww w . j a va 2s . c o m } try { fileObject.createFile(); FileContent content = fileObject.getContent(); return content.getOutputStream(append); } catch (FileSystemException e) { // Perhaps if it's a local file, we can retry using the standard // File object. This is because on Windows there is a bug in VFS. // if (fileObject instanceof LocalFile) { try { String filename = getFilename(fileObject); return new FileOutputStream(new File(filename), append); } catch (Exception e2) { throw e; // throw the original exception: hide the retry. } } else { throw e; } } }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeVfsTestCase.java
public static void assertEquals(File file, FileObject fileObject) throws Exception { assertEqualPaths(file, fileObject);/*from w ww . j a v a 2 s.com*/ 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.pongasoft.util.io.IOUtils.java
/** * Wraps the provided file object within a jar file object * (ex: <code>createJarFileObject(file:///tmp/foo.jar)</code> will return * <code>jar:file:///tmp.foo.jar!/</code> * * @param fileObject the orginal jar file * @return the wrapped file object (note that it the orignial object does not exists, it * is simply returned (as wrapping it throws an exception...) * @throws IOException if there is something wrong *//* w w w . ja va 2 s .co m*/ public static FileObject createJarFileObject(FileObject fileObject) throws IOException { if (fileObject == null) return null; if (fileObject.exists()) { FileSystemManager fsm = fileObject.getFileSystem().getFileSystemManager(); return fsm.resolveFile("jar:" + fileObject.getURL() + "!/"); } else return fileObject; }
From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Returns the root file system of a file representation * @param fileObject A file abstraction//from w ww . j a va2s .co m * @return the root file system of a file representation */ public static FileObject getRootFileSystem(FileObject fileObject) { try { if ((fileObject == null) || !fileObject.exists()) { return null; } return fileObject.getFileSystem().getRoot(); } catch (FileSystemException ex) { return null; } }
From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Tells whether a file exists//from www . j a v a2 s .c om * @param fileObject A file representation * @return whether a file exists */ public static boolean exists(FileObject fileObject) { if (fileObject == null) { return false; } try { return fileObject.exists(); } catch (FileSystemException ex) { return false; } }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>//from ww w. j a v a 2s . co m * ? ??. * </p> * @param changDirectory * <code>String</code> * @throws Exception */ public static void cd(final String changDirectory) throws Exception { final String path; if (!EgovStringUtil.isNull(changDirectory)) { path = changDirectory; } else { path = System.getProperty("user.home"); } // Locate and validate the folder FileObject tmp = manager.resolveFile(basefile, path); if (tmp.exists()) { basefile = tmp; } else { log.info("Folder does not exist: " + tmp.getName()); } log.info("Current folder is " + basefile.getName()); }
From source file:egovframework.rte.fdl.filehandling.EgovFileUtil.java
/** * <p>//from w w w. ja va 2s . 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); } }