Example usage for org.apache.commons.vfs AllFileSelector AllFileSelector

List of usage examples for org.apache.commons.vfs AllFileSelector AllFileSelector

Introduction

In this page you can find the example usage for org.apache.commons.vfs AllFileSelector AllFileSelector.

Prototype

AllFileSelector

Source Link

Usage

From source file:com.pongasoft.kiwidoc.builder.AbstractContentHandler.java

/**
 * Deletes the content pointed to by this resource.
 *
 * @param resource the resource to delete
 * @return <code>true</code> if the resource was deleted, <code>false</code> if it did not exist in
 *         the first place/* w  ww  .ja  v  a  2  s .  co m*/
 * @throws StoreException if there is a problem
 */
public boolean deleteContent(R resource) throws StoreException {
    if (resource == null)
        return false;

    try {
        FileObject resourceFile = getResourceFile(resource);
        return resourceFile.delete(new AllFileSelector()) > 0;
    } catch (IOException e) {
        throw new StoreException(e);
    }
}

From source file:com.rapleaf.ramhdfs.RamFileSystem.java

@Override
public boolean delete(Path f, boolean arg1) throws IOException {
    FileObject fo = pathToFileObject(f);
    return fo.delete(new AllFileSelector()) > 0;
}

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  a  va2 s .co  m

        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.rapleaf.ramhdfs.RamFileSystem.java

@Override
public boolean rename(Path source, Path target) throws IOException {
    FileObject sourceFo = pathToFileObject(source);
    pathToFileObject(target).copyFrom(sourceFo, new AllFileSelector());
    delete(source);// ww w  . j  a v a 2  s  .  c o m
    return true;
}

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 {// ww w  . j a  v  a2  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:com.panet.imeta.core.plugins.PluginLoader.java

/**
 * "Deploys" the plugin jar file./*from   ww  w.  j ava2 s. c  o  m*/
 * 
 * @param parent
 * @return
 * @throws FileSystemException
 */
private FileObject explodeJar(FileObject parent) throws FileSystemException {
    // By Alex, 7/13/07
    // Since the JVM does not support nested jars and
    // URLClassLoaders, we have to hack it
    // see
    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4735639
    // 
    // We do so by exploding the jar, sort of like deploying it
    FileObject dest = VFS.getManager().resolveFile(Const.getKettleDirectory() + File.separator + WORK_DIR);
    dest.createFolder();

    FileObject destFile = dest.resolveFile(parent.getName().getBaseName());

    if (!destFile.exists())
        destFile.createFolder();
    else
        // delete children
        for (FileObject child : destFile.getChildren())
            child.delete(new AllFileSelector());

    // force VFS to treat it as a jar file explicitly with children,
    // etc. and copy
    destFile.copyFrom(!(parent instanceof JarFileObject)
            ? VFS.getManager().resolveFile(JAR + ":" + parent.getName().getURI())
            : parent, new AllFileSelector());

    return destFile;
}

From source file:com.panet.imeta.job.entries.xmlwellformed.JobEntryXMLWellFormed.java

private boolean ProcessFileFolder(String sourcefilefoldername, String wildcard, Job parentJob, Result result) {
    LogWriter log = LogWriter.getInstance();
    boolean entrystatus = false;
    FileObject sourcefilefolder = null;
    FileObject CurrentFile = null;

    // Get real source file and wilcard
    String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername);
    if (Const.isEmpty(realSourceFilefoldername)) {
        log.logError(toString(),/* w w w  .  j av  a2  s . c o m*/
                Messages.getString("JobXMLWellFormed.log.FileFolderEmpty", sourcefilefoldername));
        // Update Errors
        updateErrors();

        return entrystatus;
    }
    String realWildcard = environmentSubstitute(wildcard);

    try {
        sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername);

        if (sourcefilefolder.exists()) {
            if (log.isDetailed())
                log.logDetailed(toString(),
                        Messages.getString("JobXMLWellFormed.Log.FileExists", sourcefilefolder.toString()));
            if (sourcefilefolder.getType() == FileType.FILE) {
                entrystatus = checkOneFile(sourcefilefolder, log, result, parentJob);

            } else if (sourcefilefolder.getType() == FileType.FOLDER) {
                FileObject[] fileObjects = sourcefilefolder.findFiles(new AllFileSelector() {
                    public boolean traverseDescendents(FileSelectInfo info) {
                        return true;
                    }

                    public boolean includeFile(FileSelectInfo info) {

                        FileObject fileObject = info.getFile();
                        try {
                            if (fileObject == null)
                                return false;
                            if (fileObject.getType() != FileType.FILE)
                                return false;
                        } catch (Exception ex) {
                            // Upon error don't process the file.
                            return false;
                        }

                        finally {
                            if (fileObject != null) {
                                try {
                                    fileObject.close();
                                } catch (IOException ex) {
                                }
                                ;
                            }

                        }
                        return true;
                    }
                });

                if (fileObjects != null) {
                    for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) {
                        if (successConditionBroken) {
                            if (!successConditionBrokenExit) {
                                log.logError(toString(), Messages.getString(
                                        "JobXMLWellFormed.Error.SuccessConditionbroken", "" + NrAllErrors));
                                successConditionBrokenExit = true;
                            }
                            return false;
                        }
                        // Fetch files in list one after one ...
                        CurrentFile = fileObjects[j];

                        if (!CurrentFile.getParent().toString().equals(sourcefilefolder.toString())) {
                            // Not in the Base Folder..Only if include sub folders  
                            if (include_subfolders) {
                                if (GetFileWildcard(CurrentFile.toString(), realWildcard)) {
                                    checkOneFile(CurrentFile, log, result, parentJob);
                                }
                            }

                        } else {
                            // In the base folder
                            if (GetFileWildcard(CurrentFile.toString(), realWildcard)) {
                                checkOneFile(CurrentFile, log, result, parentJob);
                            }
                        }
                    }
                }
            } else {
                log.logError(toString(), Messages.getString("JobXMLWellFormed.Error.UnknowFileFormat",
                        sourcefilefolder.toString()));
                // Update Errors
                updateErrors();
            }
        } else {
            log.logError(toString(),
                    Messages.getString("JobXMLWellFormed.Error.SourceFileNotExists", realSourceFilefoldername));
            // Update Errors
            updateErrors();
        }
    } // end try

    catch (IOException e) {
        log.logError(toString(), Messages.getString("JobXMLWellFormed.Error.Exception.Processing",
                realSourceFilefoldername.toString(), e.getMessage()));
        // Update Errors
        updateErrors();
    } finally {
        if (sourcefilefolder != null) {
            try {
                sourcefilefolder.close();
            } catch (IOException ex) {
            }
            ;

        }
        if (CurrentFile != null) {
            try {
                CurrentFile.close();
            } catch (IOException ex) {
            }
            ;
        }
    }
    return entrystatus;
}

From source file:com.panet.imeta.job.entries.unzip.JobEntryUnZip.java

private boolean unzipFile(LogWriter log, FileObject sourceFileObject, String realTargetdirectory,
        String realWildcard, String realWildcardExclude, Result result, Job parentJob, FileObject fileObject,
        FileObject movetodir, String realMovetodirectory) {
    boolean retval = false;

    try {// w w w.j  a  v  a  2 s  . com

        if (log.isDetailed())
            log.logDetailed(toString(),
                    Messages.getString("JobUnZip.Log.ProcessingFile", sourceFileObject.toString()));

        // Do you create a root folder?
        //
        if (rootzip) {
            String shortSourceFilename = sourceFileObject.getName().getBaseName();
            int lenstring = shortSourceFilename.length();
            int lastindexOfDot = shortSourceFilename.lastIndexOf('.');
            if (lastindexOfDot == -1)
                lastindexOfDot = lenstring;

            String foldername = realTargetdirectory + "/" + shortSourceFilename.substring(0, lastindexOfDot);
            FileObject rootfolder = KettleVFS.getFileObject(foldername);
            if (!rootfolder.exists()) {
                try {
                    rootfolder.createFolder();
                    if (log.isDetailed())
                        log.logDetailed(toString(),
                                Messages.getString("JobUnZip.Log.RootFolderCreated", foldername));
                } catch (Exception e) {
                    throw new Exception(Messages.getString("JobUnZip.Error.CanNotCreateRootFolder", foldername),
                            e);
                }
            }
        }

        // Try to read the entries from the VFS object...
        //
        String zipFilename = "zip:" + sourceFileObject.getName().getFriendlyURI();
        FileObject zipFile = KettleVFS.getFileObject(zipFilename);
        FileObject[] items = zipFile.findFiles(new AllFileSelector() {
            public boolean traverseDescendents(FileSelectInfo info) {
                return true;
            }

            public boolean includeFile(FileSelectInfo info) {
                // Never return the parent directory of a file list.
                if (info.getDepth() == 0) {
                    return false;
                }

                FileObject fileObject = info.getFile();
                return fileObject != null;
            }
        });

        Pattern pattern = null;
        if (!Const.isEmpty(realWildcard)) {
            pattern = Pattern.compile(realWildcard);

        }
        Pattern patternexclude = null;
        if (!Const.isEmpty(realWildcardExclude)) {
            patternexclude = Pattern.compile(realWildcardExclude);

        }

        for (FileObject item : items) {

            if (successConditionBroken) {
                if (!successConditionBrokenExit) {
                    log.logError(toString(),
                            Messages.getString("JobUnZip.Error.SuccessConditionbroken", "" + NrErrors));
                    successConditionBrokenExit = true;
                }
                return false;
            }

            try {
                if (log.isDetailed())
                    log.logDetailed(toString(), Messages.getString("JobUnZip.Log.ProcessingZipEntry",
                            item.getName().getURI(), sourceFileObject.toString()));

                // get real destination filename
                //
                String newFileName = realTargetdirectory + Const.FILE_SEPARATOR
                        + getTargetFilename(item.getName().getPath());
                FileObject newFileObject = KettleVFS.getFileObject(newFileName);

                if (item.getType().equals(FileType.FOLDER)) {
                    // Directory
                    //
                    if (log.isDetailed())
                        log.logDetailed(toString(),
                                Messages.getString("JobUnZip.CreatingDirectory.Label", newFileName));

                    // Create Directory if necessary ...
                    //
                    if (!newFileObject.exists())
                        newFileObject.createFolder();
                } else {
                    // File
                    //
                    boolean getIt = true;
                    boolean getItexclude = false;

                    // First see if the file matches the regular expression!
                    //
                    if (pattern != null) {
                        Matcher matcher = pattern.matcher(item.getName().getURI());
                        getIt = matcher.matches();
                    }

                    if (patternexclude != null) {
                        Matcher matcherexclude = patternexclude.matcher(item.getName().getURI());
                        getItexclude = matcherexclude.matches();
                    }

                    boolean take = takeThisFile(log, item, newFileName);

                    if (getIt && !getItexclude && take) {
                        if (log.isDetailed())
                            log.logDetailed(toString(), Messages.getString("JobUnZip.ExtractingEntry.Label",
                                    item.getName().getURI(), newFileName));

                        if (iffileexist == IF_FILE_EXISTS_UNIQ) {
                            // Create file with unique name

                            int lenstring = newFileName.length();
                            int lastindexOfDot = newFileName.lastIndexOf('.');
                            if (lastindexOfDot == -1)
                                lastindexOfDot = lenstring;

                            newFileName = newFileName.substring(0, lastindexOfDot)
                                    + StringUtil.getFormattedDateTimeNow(true)
                                    + newFileName.substring(lastindexOfDot, lenstring);

                            if (log.isDebug())
                                log.logDebug(toString(),
                                        Messages.getString("JobUnZip.Log.CreatingUniqFile", newFileName));
                        }

                        // See if the folder to the target file exists...
                        //
                        if (!newFileObject.getParent().exists()) {
                            newFileObject.getParent().createFolder(); // creates
                            // the
                            // whole
                            // path.
                        }
                        InputStream is = null;
                        OutputStream os = null;

                        try {
                            is = KettleVFS.getInputStream(item);
                            os = KettleVFS.getOutputStream(newFileObject, false);

                            if (is != null) {
                                byte[] buff = new byte[2048];
                                int len;

                                while ((len = is.read(buff)) > 0) {
                                    os.write(buff, 0, len);
                                }

                                // Add filename to result filenames
                                addFilenameToResultFilenames(result, parentJob, newFileName);
                            }
                        } finally {
                            if (is != null)
                                is.close();
                            if (os != null)
                                os.close();
                        }
                    } // end if take
                }
            } catch (Exception e) {
                updateErrors();
                log.logError(toString(), Messages.getString("JobUnZip.Error.CanNotProcessZipEntry",
                        item.getName().getURI(), sourceFileObject.toString()), e);
            }
        } // End while

        // Here gc() is explicitly called if e.g. createfile is used in the
        // same
        // job for the same file. The problem is that after creating the
        // file the
        // file object is not properly garbaged collected and thus the file
        // cannot
        // be deleted anymore. This is a known problem in the JVM.

        // System.gc();

        // Unzip done...
        if (afterunzip == 1) {
            // delete zip file
            boolean deleted = fileObject.delete();
            if (!deleted) {
                updateErrors();
                log.logError(toString(),
                        Messages.getString("JobUnZip.Cant_Delete_File.Label", sourceFileObject.toString()));
            }
            // File deleted
            if (log.isDebug())
                log.logDebug(toString(),
                        Messages.getString("JobUnZip.File_Deleted.Label", sourceFileObject.toString()));
        } else if (afterunzip == 2) {
            FileObject destFile = null;
            // Move File
            try {
                String destinationFilename = movetodir + Const.FILE_SEPARATOR
                        + fileObject.getName().getBaseName();
                destFile = KettleVFS.getFileObject(destinationFilename);

                fileObject.moveTo(destFile);

                // File moved
                if (log.isDetailed())
                    log.logDetailed(toString(), Messages.getString("JobUnZip.Log.FileMovedTo",
                            sourceFileObject.toString(), realMovetodirectory));
            } catch (Exception e) {
                updateErrors();
                log.logError(toString(), Messages.getString("JobUnZip.Cant_Move_File.Label",
                        sourceFileObject.toString(), realMovetodirectory, e.getMessage()));
            } finally {
                if (destFile != null) {
                    try {
                        destFile.close();
                    } catch (IOException ex) {
                    }
                    ;
                }
            }
        }

        retval = true;
    } catch (Exception e) {
        updateErrors();
        log.logError(Messages.getString("JobUnZip.Error.Label"),
                Messages.getString("JobUnZip.ErrorUnzip.Label", sourceFileObject.toString(), e.getMessage()),
                e);
    }

    return retval;
}

From source file:com.panet.imeta.job.entries.movefiles.JobEntryMoveFiles.java

private boolean ProcessFileFolder(String sourcefilefoldername, String destinationfilefoldername,
        String wildcard, Job parentJob, Result result, String MoveToFolder, LogWriter log) {
    boolean entrystatus = false;
    FileObject sourcefilefolder = null;
    FileObject destinationfilefolder = null;
    FileObject movetofolderfolder = null;
    FileObject Currentfile = null;

    // Get real source, destination file and wildcard
    String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername);
    String realDestinationFilefoldername = environmentSubstitute(destinationfilefoldername);
    String realWildcard = environmentSubstitute(wildcard);

    try {/*w w  w . j a  v  a 2  s  .  co m*/

        // Here gc() is explicitly called if e.g. createfile is used in the
        // same
        // job for the same file. The problem is that after creating the
        // file the
        // file object is not properly garbaged collected and thus the file
        // cannot
        // be deleted anymore. This is a known problem in the JVM.

        System.gc();

        sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername);
        destinationfilefolder = KettleVFS.getFileObject(realDestinationFilefoldername);
        if (!Const.isEmpty(MoveToFolder))
            movetofolderfolder = KettleVFS.getFileObject(MoveToFolder);

        if (sourcefilefolder.exists()) {

            // Check if destination folder/parent folder exists !
            // If user wanted and if destination folder does not exist
            // PDI will create it
            if (CreateDestinationFolder(destinationfilefolder)) {

                // Basic Tests
                if (sourcefilefolder.getType().equals(FileType.FOLDER) && destination_is_a_file) {
                    // Source is a folder, destination is a file
                    // WARNING !!! CAN NOT MOVE FOLDER TO FILE !!!

                    log.logError(Messages.getString("JobMoveFiles.Log.Forbidden"),
                            Messages.getString("JobMoveFiles.Log.CanNotMoveFolderToFile",
                                    realSourceFilefoldername, realDestinationFilefoldername));

                    // Update Errors
                    updateErrors();
                } else {
                    if (destinationfilefolder.getType().equals(FileType.FOLDER)
                            && sourcefilefolder.getType().equals(FileType.FILE)) {
                        // Source is a file, destination is a folder
                        // return destination short filename
                        String shortfilename = sourcefilefolder.getName().getBaseName();

                        try {
                            shortfilename = getDestinationFilename(sourcefilefolder.getName().getBaseName());
                        } catch (Exception e) {
                            log.logError(toString(),
                                    Messages.getString(Messages.getString("JobMoveFiles.Error.GettingFilename",
                                            sourcefilefolder.getName().getBaseName(), e.toString())));
                            return entrystatus;
                        }
                        // Move the file to the destination folder

                        String destinationfilenamefull = destinationfilefolder.toString() + Const.FILE_SEPARATOR
                                + shortfilename;
                        FileObject destinationfile = KettleVFS.getFileObject(destinationfilenamefull);

                        entrystatus = MoveFile(shortfilename, sourcefilefolder, destinationfile,
                                movetofolderfolder, log, parentJob, result);

                    } else if (sourcefilefolder.getType().equals(FileType.FILE) && destination_is_a_file) {
                        // Source is a file, destination is a file

                        FileObject destinationfile = KettleVFS.getFileObject(realDestinationFilefoldername);

                        // return destination short filename
                        String shortfilename = destinationfile.getName().getBaseName();
                        try {
                            shortfilename = getDestinationFilename(destinationfile.getName().getBaseName());
                        } catch (Exception e) {
                            log.logError(toString(),
                                    Messages.getString(Messages.getString("JobMoveFiles.Error.GettingFilename",
                                            sourcefilefolder.getName().getBaseName(), e.toString())));
                            return entrystatus;
                        }

                        String destinationfilenamefull = destinationfilefolder.getParent().toString()
                                + Const.FILE_SEPARATOR + shortfilename;
                        destinationfile = KettleVFS.getFileObject(destinationfilenamefull);

                        entrystatus = MoveFile(shortfilename, sourcefilefolder, destinationfile,
                                movetofolderfolder, log, parentJob, result);

                    } else {
                        // Both source and destination are folders
                        if (log.isDetailed()) {
                            log.logDetailed(toString(), "  ");
                            log.logDetailed(toString(), Messages.getString("JobMoveFiles.Log.FetchFolder",
                                    sourcefilefolder.toString()));
                        }

                        FileObject[] fileObjects = sourcefilefolder.findFiles(new AllFileSelector() {
                            public boolean traverseDescendents(FileSelectInfo info) {
                                return true;
                            }

                            public boolean includeFile(FileSelectInfo info) {
                                FileObject fileObject = info.getFile();
                                try {
                                    if (fileObject == null)
                                        return false;
                                } catch (Exception ex) {
                                    // Upon error don't process the
                                    // file.
                                    return false;
                                }

                                finally {
                                    if (fileObject != null) {
                                        try {
                                            fileObject.close();
                                        } catch (IOException ex) {
                                        }
                                        ;
                                    }

                                }
                                return true;
                            }
                        });

                        if (fileObjects != null) {
                            for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) {
                                // Success condition broken?
                                if (successConditionBroken) {
                                    if (!successConditionBrokenExit) {
                                        log.logError(toString(), Messages.getString(
                                                "JobMoveFiles.Error.SuccessConditionbroken", "" + NrErrors));
                                        successConditionBrokenExit = true;
                                    }
                                    return false;
                                }
                                // Fetch files in list one after one ...
                                Currentfile = fileObjects[j];

                                if (!MoveOneFile(Currentfile, sourcefilefolder, realDestinationFilefoldername,
                                        realWildcard, log, parentJob, result, movetofolderfolder)) {
                                    // Update Errors
                                    updateErrors();
                                }

                            }
                        }
                    }

                }
                entrystatus = true;
            } // end if
            else {
                // Destination Folder or Parent folder is missing
                log.logError(toString(), Messages.getString("JobMoveFiles.Error.DestinationFolderNotFound",
                        realDestinationFilefoldername));
            }
        } // end if
        else {
            log.logError(toString(),
                    Messages.getString("JobMoveFiles.Error.SourceFileNotExists", realSourceFilefoldername));
        }
    } // end try
    catch (Exception e) {
        log.logError(toString(), Messages.getString("JobMoveFiles.Error.Exception.MoveProcess",
                realSourceFilefoldername.toString(), destinationfilefolder.toString(), e.getMessage()));
        // Update Errors
        updateErrors();
    } finally {
        if (sourcefilefolder != null) {
            try {
                sourcefilefolder.close();
            } catch (IOException ex) {
            }
            ;
        }
        if (destinationfilefolder != null) {
            try {
                destinationfilefolder.close();
            } catch (IOException ex) {
            }
            ;
        }
        if (Currentfile != null) {
            try {
                Currentfile.close();
            } catch (IOException ex) {
            }
            ;
        }
        if (movetofolderfolder != null) {
            try {
                movetofolderfolder.close();
            } catch (IOException ex) {
            }
            ;
        }
    }
    return entrystatus;
}

From source file:org.bibalex.gallery.storage.BAGStorage.java

public static void copyFile(String sourceUrlStr, String targetUrlsStr) throws BAGException {
    try {//from w w  w .  ja  v a  2  s. c om
        FileObject targetFO = VFS.getManager().resolveFile(targetUrlsStr);
        FileObject sourceFO = VFS.getManager().resolveFile(sourceUrlStr);

        targetFO.copyFrom(sourceFO, new AllFileSelector());
    } catch (FileSystemException e) {
        throw new BAGException(e);
    }
}