List of usage examples for org.apache.commons.vfs FileSelectInfo getFile
FileObject getFile();
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 av a2 s .c o m // 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.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]);//from 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.github.lucapino.sheetmaker.parsers.mediainfo.MediaInfoRetriever.java
@Override public MovieInfo getMovieInfo(String filePath) { MediaInfo mediaInfo = new MediaInfo(); String fileToParse = filePath; // test if we have iso if (filePath.toLowerCase().endsWith("iso")) { // open iso and parse the ifo files Map<Integer, String> ifoFiles = new TreeMap<>(); try {/*ww w. ja va2 s . co m*/ FileSystemManager fsManager = VFS.getManager(); FileObject fo = fsManager.resolveFile("iso:" + filePath + "!/"); // create an ifo file selector FileSelector ifoFs = new FileFilterSelector(new FileFilter() { @Override public boolean accept(FileSelectInfo fsi) { return fsi.getFile().getName().getBaseName().toLowerCase().endsWith("ifo"); } }); FileObject[] files = fo.getChild("VIDEO_TS").findFiles(ifoFs); for (FileObject file : files) { File tmpFile = new File( System.getProperty("java.io.tmpdir") + File.separator + file.getName().getBaseName()); System.out.println(file.getName().getBaseName()); IOUtils.copy(file.getContent().getInputStream(), new FileOutputStream(tmpFile)); mediaInfo.Open(tmpFile.getAbsolutePath()); String format = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "Format_Profile", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); System.out.println("Format profile: " + format); // if format is "Program" -> it's a video file if (format.equalsIgnoreCase("program")) { String duration = mediaInfo.Get(MediaInfo.StreamKind.General, 0, "Duration", MediaInfo.InfoKind.Text, MediaInfo.InfoKind.Name); System.out.println("Duration: " + duration); ifoFiles.put(Integer.valueOf(duration), tmpFile.getName()); } mediaInfo.Close(); } if (!ifoFiles.isEmpty()) { if (ifoFiles.size() == 1) { fileToParse = ifoFiles.values().iterator().next(); } else { // get the last entry -> the bigger one Set<Integer> keys = ifoFiles.keySet(); Iterator<Integer> iterator = keys.iterator(); for (int i = 0; i < keys.size(); i++) { String fileName = ifoFiles.get(iterator.next()); if (i == keys.size() - 1) { fileToParse = fileName; } else { new File(fileName).delete(); } } } } } catch (IOException | NumberFormatException ex) { } } // here fileToParse is correct mediaInfo.Open(fileToParse); System.out.println(mediaInfo.Inform()); return new MovieInfoImpl(mediaInfo, filePath); }
From source file:com.thinkberg.moxo.dav.lock.LockManager.java
/** * Check whether a lock conflicts with already existing locks up and down the path. * First we go up the path to check for parent locks that may include the file object * and the go down the directory tree (if depth requires it) to check locks that * will conflict.//ww w . ja va2 s .c o m * * @param requestedLock the lock requested * @throws LockConflictException if a conflicting lock was found * @throws FileSystemException if the file object or path cannot be accessed */ private void checkConflicts(final Lock requestedLock) throws LockConflictException, FileSystemException { // find locks in the parent path FileObject parent = requestedLock.getObject(); while (parent != null) { List<Lock> parentLocks = lockMap.get(parent); if (parentLocks != null && !parentLocks.isEmpty()) { for (Lock parentLock : parentLocks) { if (Lock.EXCLUSIVE.equals(requestedLock.getScope()) || Lock.EXCLUSIVE.equals(parentLock.getScope())) { throw new LockConflictException(parentLocks); } } } parent = parent.getParent(); } // look for locks down the path (if depth requests it) if (requestedLock.getDepth() != 0 && requestedLock.getObject().getChildren().length > 0) { requestedLock.getObject().findFiles(new DepthFileSelector(1, requestedLock.getDepth()) { public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { List<Lock> childLocks = lockMap.get(fileSelectInfo.getFile()); for (Lock childLock : childLocks) { if (Lock.EXCLUSIVE.equals(requestedLock.getScope()) || Lock.EXCLUSIVE.equals(childLock.getScope())) { throw new LockConflictException(childLocks); } } return false; } }, false, new ArrayList()); } }
From source file:com.sonatype.nexus.plugin.groovyconsole.DefaultScriptStorage.java
public void initialize() throws InitializationException { scripts = new LinkedHashMap<String, String>(); FileObject listendir;/*from w w w .j av a 2 s.c o m*/ try { FileSystemManager fsManager = VFS.getManager(); scriptDir = applicationConfiguration.getWorkingDirectory("scripts"); if (!scriptDir.exists()) { scriptDir.mkdirs(); try { new File(scriptDir, "place your .groovy files here.txt").createNewFile(); } catch (IOException e) { throw new InitializationException(e.getMessage(), e); } } listendir = fsManager.resolveFile(scriptDir.getAbsolutePath()); } catch (FileSystemException e) { throw new InitializationException(e.getMessage(), e); } FileSelector selector = new FileSelector() { public boolean traverseDescendents(FileSelectInfo arg0) throws Exception { return true; } public boolean includeFile(FileSelectInfo arg0) throws Exception { return isScriptFile(arg0.getFile()); } }; try { FileObject[] availableScripts = listendir.findFiles(selector); for (FileObject fileObject : availableScripts) { updateScript(fileObject); } } catch (FileSystemException e) { getLogger().warn("Unable to perform initial directory scan.", e); } DefaultFileMonitor fm = new DefaultFileMonitor(this); fm.setRecursive(true); fm.addFile(listendir); fm.start(); this.fileMonitor = fm; }
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(),/*ww w. ja v a 2s .c om*/ 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 {// ww w . j av a 2 s. c o m 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 {// www . j a va 2 s. c o 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.codehaus.mojo.unix.util.vfs.IncludeExcludeFileSelector.java
public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { FileObject fileObject = fileSelectInfo.getFile(); FileName name = fileObject.getName(); if (fileType != null && fileObject.getType() != fileType) { return false; }// www .j av a 2s. c o m String relativePath = root.getRelativeName(name); return matches(relativePath); }
From source file:org.efaps.webdav4vfs.lock.LockManager.java
/** * Check whether a lock conflicts with already existing locks up and down the path. * First we go up the path to check for parent locks that may include the file object * and the go down the directory tree (if depth requires it) to check locks that * will conflict.//from w w w . ja v a2 s . co m * * @param requestedLock the lock requested * @throws LockConflictException if a conflicting lock was found * @throws FileSystemException if the file object or path cannot be accessed */ private void checkConflicts(final Lock requestedLock) throws LockConflictException, FileSystemException { // find locks in the parent path FileObject parent = requestedLock.getObject(); while (parent != null) { List<Lock> parentLocks = lockMap.get(parent); if (parentLocks != null && !parentLocks.isEmpty()) { for (Lock parentLock : parentLocks) { if (Lock.EXCLUSIVE.equals(requestedLock.getScope()) || Lock.EXCLUSIVE.equals(parentLock.getScope())) { throw new LockConflictException(parentLocks); } } } parent = parent.getParent(); } // look for locks down the path (if depth requests it) if (requestedLock.getDepth() != 0 && requestedLock.getObject().getChildren().length > 0) { requestedLock.getObject().findFiles(new DepthFileSelector(1, requestedLock.getDepth()) { @Override() public boolean includeFile(FileSelectInfo fileSelectInfo) throws Exception { List<Lock> childLocks = lockMap.get(fileSelectInfo.getFile()); for (Lock childLock : childLocks) { if (Lock.EXCLUSIVE.equals(requestedLock.getScope()) || Lock.EXCLUSIVE.equals(childLock.getScope())) { throw new LockConflictException(childLocks); } } return false; } }, false, new ArrayList<Object>()); } }