List of usage examples for org.apache.commons.vfs FileObject getParent
public FileObject getParent() throws FileSystemException;
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 www . j a v a 2s .c om*/ } 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.GaeFolderTestCase.java
private static void assertSubFolders(FileObject testFolder, String[] subFolderNames) throws Exception { FileName rootName = testFolder.getFileSystem().getRootName(); FileObject[] subFolders = testFolder.findFiles(Selectors.EXCLUDE_SELF); assertEquals(subFolders.length, subFolderNames.length); for (int i = 0; i < subFolders.length; i++) { FileObject subObject = subFolders[i]; assertTrue(subObject.getName().getPath().endsWith(subFolderNames[i])); assertFolder(subObject);/*from w w w. ja va 2 s .co m*/ assertEquals(subObject.getParent(), i == subFolders.length - 1 ? testFolder : subFolders[i + 1]); assertTrue(rootName.isDescendent(subObject.getName())); assertTrue(subObject.getName().isAncestor(rootName)); } }
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 w w . j a va 2 s. co 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:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Tells whether a file is the root file system * @param fileObject A file representation * @return whether a file is the root file system *//*from w w w.j a va 2s . c om*/ public static boolean isRoot(FileObject fileObject) { try { return fileObject.getParent() == null; } catch (FileSystemException ex) { return false; } }
From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Returns the parent directory of a file object * @param fileObject A file representation * @return the parent directory of a file object *//* ww w . j a v a2s.c o m*/ public static FileObject getParentDirectory(FileObject fileObject) { try { return fileObject.getParent(); } catch (FileSystemException ex) { return fileObject; } }
From source file:net.sf.vfsjfilechooser.utils.VFSUtils.java
/** * Returns whether a folder contains a given file * @param folder A folder/*w w w . j a v a 2s .c om*/ * @param file A file * @return whether a folder contains a given file */ public static boolean isParent(FileObject folder, FileObject file) { try { FileObject parent = file.getParent(); if (parent == null) { return false; } return parent.equals(folder); } catch (FileSystemException ex) { return false; } }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private FileObject testCreateTestFolder(FileObject rootObject) throws Exception { FileObject testFolder = GaeVFS.resolveFile("testFolder"); assertFalse(testFolder.exists());/*w ww . j a va 2s. co m*/ testFolder.createFolder(); assertFolder(testFolder); assertEquals(rootObject, testFolder.getParent()); assertTrue(testFolder.getName().isAncestor(rootObject.getName())); assertTrue(rootObject.getName().isDescendent(testFolder.getName())); assertChildren(rootObject, rootChildren); assertEntity(rootObject); return testFolder; }
From source file:com.newatlanta.appengine.junit.vfs.gae.GaeFolderTestCase.java
private FileObject testRootObject() throws Exception { FileObject rootObject = GaeVFS.resolveFile("/"); assertTrue(rootObject.exists());//from w ww . j a v a2s. c o m assertEquals(rootObject.getName().getScheme(), "gae"); assertFolder(rootObject); assertNull(rootObject.getParent()); assertChildren(rootObject, rootChildren); // TODO: test rootObject.getName() and FileName methods assertEntity(rootObject); return rootObject; }
From source file:com.thinkberg.moxo.dav.lock.LockManager.java
/** * Discover locks for a given file object. This will find locks for the object * itself and parent path locks with a depth that reaches the file object. * * @param object the file object to find locks for * @return the locks that are found for this file object * @throws FileSystemException if the file object or its parents cannot be accessed *///from w w w. ja v a 2s.c o m public List<Lock> discoverLock(FileObject object) throws FileSystemException { FileObject parent = object; while (parent != null) { List<Lock> parentLocks = lockMap.get(parent); if (parentLocks != null && !parentLocks.isEmpty()) { return parentLocks; } parent = parent.getParent(); } return null; }
From source file:be.ibridge.kettle.trans.step.getfilenames.GetFileNames.java
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { if (data.filenr >= data.files.nrOfFiles()) { setOutputDone();//from w w w . j a v a2 s . c o m return false; } Row r = new Row(); FileObject file = data.files.getFile(data.filenr); Value filename = new Value("filename", KettleVFS.getFilename(file)); filename.setLength(500, -1); r.addValue(filename); Value short_filename = new Value("short_filename", file.getName().getBaseName()); short_filename.setLength(500, -1); r.addValue(short_filename); try { Value path = new Value("path", KettleVFS.getFilename(file.getParent())); path.setLength(500, -1); r.addValue(path); } catch (IOException e) { throw new KettleException(e); } data.filenr++; putRow(r); if ((linesInput > 0) && (linesInput % Const.ROWS_UPDATE) == 0) logBasic("linenr " + linesInput); return true; }