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

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

Introduction

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

Prototype

void refresh() throws FileSystemException;

Source Link

Document

This will prepare the fileObject to get resynchronized with the underlying file system if required.

Usage

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  w w w . j  a  va2 s.co 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.stage.origin.remote.RemoteDownloadSource.java

private void queueFiles(FileObject remoteDir) throws FileSystemException {
    remoteDir.refresh();
    for (FileObject remoteFile : remoteDir.getChildren()) {
        if (remoteFile.getType().toString().equals("folder")) {
            queueFiles(remoteFile);/*from   w  w  w.j av a2s .co  m*/
            continue;
        }
        long lastModified = remoteFile.getContent().getLastModifiedTime();
        RemoteFile tempFile = new RemoteFile(remoteFile.getName().getBaseName(), lastModified, remoteFile);

        if (shouldQueue(tempFile)) {
            // If we are done with all files, the files with the final mtime might get re-ingested over and over.
            // So if it is the one of those, don't pull it in.
            fileQueue.add(tempFile);
        }
    }
}

From source file:com.googlecode.vfsjfilechooser2.plaf.basic.BasicVFSDirectoryModel.java

/**
 *
 *//*from   w  w w.  ja v  a  2s  . c o m*/
public void validateFileCache() {
    FileObject currentDirectory = filechooser.getCurrentDirectoryObject();

    if (currentDirectory == null) {
        return;
    }

    try {
        currentDirectory.refresh();
    } catch (FileSystemException ex) {
    }

    if (loadThread != null) {
        loadThread.cancel(true);
    }

    setBusy(true, ++fetchID);

    loadThread = executor.submit(new LoadFilesThread(currentDirectory, fetchID));
}

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

private void refreshIfUpdatable(FileObject tmlFolder) throws FileSystemException {
    if (getFsResources().isUpdateableFileSystem()) {
        tmlFolder.refresh();
    }/*from ww w  .j  a  va  2 s . c o  m*/
}

From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java

/**
 * Refresh ftp cache./*w w  w .ja  va2  s. c  o m*/
 * 
 * @param fileObject the file object
 * @throws FileSystemException
 */
public void refreshFtpCache(FileObject fileObject) throws FileSystemException {

    if (fileObject == null) {
        return;
    }

    if (!(fileObject.getFileSystem() instanceof FtpFileSystem)) {
        return;
    }
    if (fileObject.exists()) {
        return;
    }
    FileObject fileObjectParent = fileObject.getParent();
    if (fileObjectParent == null) {
        return;
    }

    fileObjectParent.getType(); // force to attach : needed for force refresh
    fileObjectParent.refresh();

}

From source file:org.aludratest.service.file.impl.AbstractFileAction.java

/** Lists all child elements of the given folder which match the filter.
 * @param filePath the path of the directory to read
 * @param filter a filter for choosing files
 * @return a List of all children that match the filter */
public List<String> getChildren(String filePath, FileFilter filter) {
    File.verifyFilePath(filePath);
    try {//from   w  w  w . ja  va  2s .  com
        FileObject parent = configuration.getFileObject(filePath);
        parent.refresh();
        FileObject[] candidates = parent.getChildren();
        List<String> filePaths = new ArrayList<String>();
        if (candidates != null) {
            for (FileObject candidate : candidates) {
                String path = configuration.pathFromRoot(candidate);
                FileInfo info = new FileInfoImpl(candidate, path);
                if (filter == null || filter.accept(info)) {
                    filePaths.add(pathFromRoot(candidate));
                }
            }
        }
        if (!filePaths.isEmpty()) {
            logger.debug("Found children: {}", filePaths);
        } else {
            logger.debug("No children found for filter {}", filter);
        }
        return filePaths;
    } catch (IOException e) {
        throw new TechnicalException("Error retrivieving child objects", e);
    }
}

From source file:org.aludratest.service.file.impl.AbstractFileAction.java

/** Tells if a file or folder with the given path exists.
 * @param filePath filePath the path of the file to check
 * @return true if it exosts, otherwise false */
public boolean exists(String filePath) {
    File.verifyFilePath(filePath);
    try {//from w ww  . j a v a  2  s .com
        FileObject file = getFileObject(filePath);
        file.refresh();
        boolean result = file.exists();
        logger.debug("File '{}' {}", filePath, (result ? "exists" : "does not exist"));
        return result;
    } catch (IOException e) {
        throw new TechnicalException("Error checking file presence", e);
    }
}

From source file:org.aludratest.service.file.impl.AbstractFileAction.java

/** Lists FileInfos for all child elements of the given folder which match the filter.
 * @param dirPath the file path of the directory
 * @param filter the file filter to apply
 * @return a list of the directory's child items that match the filter */
protected List<FileInfo> getChildInfos(String dirPath, FileFilter filter) {
    File.verifyFilePath(dirPath);
    try {//  ww  w . ja  v a 2  s  . c o  m
        FileObject parent = configuration.getFileObject(dirPath);
        parent.refresh();
        FileObject[] candidates = parent.getChildren();
        List<FileInfo> infos = new ArrayList<FileInfo>();
        if (candidates != null) {
            for (FileObject candidate : candidates) {
                FileInfo fileInfo = new FileInfoImpl(candidate, configuration.pathFromRoot(candidate));
                if (filter == null || filter.accept(fileInfo)) {
                    infos.add(fileInfo);
                }
            }
        }
        return infos;
    } catch (IOException e) {
        throw new TechnicalException("Error retrivieving child objects", e);
    }
}

From source file:org.aludratest.service.file.impl.FileActionImpl.java

/** Lists all child elements of the given folder which match the filter. */
@Override/*from w  ww  .j  a v a  2  s  . c om*/
public List<String> getChildren(String filePath, FileFilter filter) {
    FileUtil.verifyFilePath(filePath);
    try {
        FileObject parent = configuration.getFileObject(filePath);
        parent.refresh();
        FileObject[] candidates = parent.getChildren();
        List<String> filePaths = new ArrayList<String>();
        if (candidates != null) {
            for (FileObject candidate : candidates) {
                if (filter == null || filter.accept(new FileInfo(candidate))) {
                    filePaths.add(pathFromRoot(candidate));
                }
            }
        }
        if (filePaths.size() > 0) {
            LOGGER.info("Found children: {}", filePaths);
        } else {
            LOGGER.info("No children found for filter {}", filter);
        }
        return filePaths;
    } catch (FileSystemException e) {
        throw new TechnicalException("Error retrivieving child objects", e);
    }
}

From source file:org.aludratest.service.file.impl.FileActionImpl.java

/** Tells if a file or folder with the given path exists. */
@Override//  w w w  . j  a v a 2 s . c  o m
public boolean exists(String filePath) {
    FileUtil.verifyFilePath(filePath);
    try {
        FileObject file = getFileObject(filePath);
        file.refresh();
        boolean result = file.exists();
        LOGGER.debug("File '{}' {}", filePath, (result ? "exists" : "does not exist"));
        return result;
    } catch (FileSystemException e) {
        throw new TechnicalException("Error checking file presence", e);
    }
}