Example usage for org.apache.commons.vfs2 FileObject getParent

List of usage examples for org.apache.commons.vfs2 FileObject getParent

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileObject getParent.

Prototype

FileObject getParent() throws FileSystemException;

Source Link

Document

Returns the folder that contains this file.

Usage

From source file:net.dempsy.distconfig.apahcevfs.Utils.java

public static FileObject nextFile(final FileObject lastFile, final FileObject parent)
        throws FileSystemException {
    if (lastFile == null)
        return parent.resolveFile(genVersionSuffix(0));
    final int lastVersion = getVersion(lastFile);
    return lastFile.getParent().resolveFile(genVersionSuffix(lastVersion + 1));
}

From source file:com.googlecode.vfsjfilechooser2.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  av a2 s  . com
public static boolean isRoot(FileObject fileObject) {
    try {
        return fileObject.getParent() == null;
    } catch (FileSystemException ex) {
        return false;
    }
}

From source file:com.googlecode.vfsjfilechooser2.utils.VFSUtils.java

/**
 * Returns whether a folder contains a given file
 * @param folder A folder/*w  w  w  .  j a  va2 s  . c o  m*/
 * @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.googlecode.vfsjfilechooser2.utils.VFSUtils.java

/**
 * Returns the parent directory of a file object
 * @param fileObject A file representation
 * @return the parent directory of a file object
 *//*from   ww  w.j  ava2 s . c om*/
public static FileObject getParentDirectory(FileObject fileObject) {
    if (fileObject == null)
        return fileObject;

    try {
        return fileObject.getParent();
    } catch (FileSystemException ex) {
        return fileObject;
    }
}

From source file:com.wipro.ats.bdre.filemon.FileMonitor.java

@Override
public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception {
    FileObject obj = fileChangeEvent.getFile();
    LOGGER.debug("File Created " + obj.getURL());
    String dirPath = obj.getParent().getName().getPath();
    LOGGER.debug("Full path " + obj.getName().getPath());

    //Don't process anything with _archive
    if (dirPath.startsWith(monDir + "/" + archiveDirName)) {
        return;/*  w w  w. java 2s  .c om*/
    }
    //Don't process directory
    if (obj.getType() == FileType.FOLDER) {
        return;
    }

    String fileName = obj.getName().getPath();

    //Checking if the file name matches with the given pattern
    if (fileName.matches(filePattern)) {
        FileContent fc = obj.getContent();
        LOGGER.debug("Matched File Pattern by " + fileName);
        putEligibleFileInfoInMap(fileName, fc);
    }
}

From source file:com.wipro.ats.bdre.tdimport.FileMonitor.java

@Override
public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception {
    FileObject obj = fileChangeEvent.getFile();
    LOGGER.debug("File Created " + obj.getURL());
    String dirPath = obj.getParent().getName().getPath();
    LOGGER.debug("Full path " + obj.getName().getPath());

    //Don't process anything with _archive
    if (dirPath.startsWith(monDir + "/" + archiveDirName)) {
        return;/* ww w.j  a v  a  2  s  .  com*/
    }
    //Don't process directory
    if (obj.getType() == FileType.FOLDER) {
        return;
    }

    String fileName = obj.getName().getPath();

    //Checking if the file name matches with the given pattern
    if (fileName.matches(filePattern)) {
        FileContent fc = obj.getContent();
        LOGGER.debug("Matched File Pattern by " + fileName);
        putEligibleFileInfoInMap(obj.getName().getBaseName(), fc);
    }
}

From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java

public void scanDirectory(FileSystemManager fsManager, FileSystemOptions opts, String ftpconn)
        throws IOException {
    try {// w ww . ja v a2  s.  c  om
        FileObject fileObject = fsManager.resolveFile(ftpconn, opts);
        FileObject[] files = fileObject.findFiles(new FileTypeSelector(FileType.FOLDER));
        HashMap<String, String> parentMap = new HashMap<String, String>();
        for (FileObject fo : files) {
            String objectName = fo.getName().toString();
            tree.addItem(objectName);
            tree.setItemIcon(objectName, FOLDER);
            if (fo.getParent() != null) {
                String parentName = fo.getParent().getName().toString();
                parentMap.put(objectName, parentName);
            } else
                tree.setItemCaption(objectName, "/");
        }

        // set parents
        logger.log(Level.INFO, "parentMap " + parentMap.size());
        if (parentMap.size() > 0) {
            Iterator<Map.Entry<String, String>> it = parentMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = it.next();
                tree.setParent(pairs.getKey(), pairs.getValue());
                String caption = pairs.getKey().toString().substring(pairs.getValue().toString().length());

                tree.setItemCaption(pairs.getKey(), removeSlash(caption));
                it.remove();
            }
        }
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}

From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java

protected static FileObject createConflictFile(FileObject targetFile) throws FileSystemException {
    String conflictFileName = targetFile.getName().getBaseName() + "_ovlconflict."
            + targetFile.getName().getExtension();
    targetFile = targetFile.getParent().resolveFile(conflictFileName);
    if (targetFile.exists()) {
        targetFile.delete();/*w  w  w . j  av a  2 s  .c o  m*/
    }
    return targetFile;
}

From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java

@Override
String archive(String fromPath) throws IOException {
    if (archiveURI == null) {
        throw new IOException("No archive directory defined - cannot archive");
    }//from  ww  w  .  j av  a  2 s .c  o  m

    String toPath = archiveURI.toString() + (fromPath.startsWith("/") ? fromPath.substring(1) : fromPath);

    FileObject toFile = VFS.getManager().resolveFile(toPath, archiveOptions);
    toFile.refresh();
    // Create the toPath's parent dir(s) if they don't exist
    toFile.getParent().createFolder();
    getChild(fromPath).moveTo(toFile);
    toFile.close();
    return toPath;
}

From source file:com.streamsets.pipeline.lib.remote.TestFTPRemoteFile.java

@Test
public void testCreateAndCommitOutputStream() throws Exception {
    String name = "file.txt";
    String filePath = "/some/path/";
    FileObject fileObject = Mockito.mock(FileObject.class);
    FileName fileName = Mockito.mock(FileName.class);
    Mockito.when(fileObject.getName()).thenReturn(fileName);
    Mockito.when(fileName.getBaseName()).thenReturn(name);
    FileObject parentFileObject = Mockito.mock(FileObject.class);
    FileObject tempFileObject = Mockito.mock(FileObject.class);
    Mockito.when(fileObject.getParent()).thenReturn(parentFileObject);
    Mockito.when(parentFileObject.resolveFile(Mockito.any())).thenReturn(tempFileObject);
    FileContent tempFileContent = Mockito.mock(FileContent.class);
    Mockito.when(tempFileObject.getContent()).thenReturn(tempFileContent);

    FTPRemoteFile file = new FTPRemoteFile(filePath + name, 0L, fileObject);

    try {//  w w  w. j av  a  2  s. co m
        file.commitOutputStream();
        Assert.fail("Expected IOException because called commitOutputStream before createOutputStream");
    } catch (IOException ioe) {
        Assert.assertEquals("Cannot commit " + filePath + name + " - it must be written first",
                ioe.getMessage());
    }

    file.createOutputStream();
    Mockito.verify(parentFileObject).resolveFile("_tmp_" + name);
    Mockito.verify(tempFileContent).getOutputStream();

    file.commitOutputStream();
    Mockito.verify(tempFileObject).moveTo(fileObject);
}