use of org.apache.commons.vfs2.AllFileSelector in project artisynth_core by artisynth.
the class ZipUtility method unzip.
public static void unzip(URIx src, final File dest) throws IOException {
dest.mkdirs();
final FileSystemManager fileSystemManager = VFS.getManager();
final FileObject zipFileObject = fileSystemManager.resolveFile(src.toString());
try {
final FileObject fileSystem = fileSystemManager.createFileSystem(zipFileObject);
try {
fileSystemManager.toFileObject(dest).copyFrom(fileSystem, new AllFileSelector());
} finally {
fileSystem.close();
}
} finally {
zipFileObject.close();
}
}
use of org.apache.commons.vfs2.AllFileSelector in project artisynth_core by artisynth.
the class FileCacher method copy.
public boolean copy(URIx from, URIx to, FileTransferMonitor monitor) throws FileSystemException {
FileObject fromFile = null;
FileObject toFile = null;
// clear authenticators
setAuthenticator(fsOpts, null);
setIdentityFactory(fsOpts, null);
// loop through authenticators until we either succeed or cancel
boolean cancel = false;
while (toFile == null && cancel == false) {
toFile = resolveRemote(to);
}
cancel = false;
while (fromFile == null && cancel == false) {
fromFile = resolveRemote(from);
}
if (fromFile == null || !fromFile.exists()) {
throw new FileSystemException("Cannot find source file <" + from.toString() + ">", new FileNotFoundException("<" + from.toString() + ">"));
}
if (toFile == null) {
throw new FileSystemException("Cannot find destination <" + to.toString() + ">", new FileNotFoundException("<" + to.toString() + ">"));
}
// monitor the file transfer progress
if (monitor != null) {
monitor.monitor(fromFile, toFile, -1, fromFile.getName().getBaseName());
monitor.start();
monitor.fireStartEvent(toFile);
}
// transfer content
try {
if (fromFile.isFile()) {
toFile.copyFrom(fromFile, Selectors.SELECT_SELF);
} else if (fromFile.isFolder()) {
// final FileObject fileSystem = manager.createFileSystem(remoteFile);
toFile.copyFrom(fromFile, new AllFileSelector());
// fileSystem.close();
}
if (monitor != null) {
monitor.fireCompleteEvent(toFile);
}
} catch (Exception e) {
throw new FileTransferException("Failed to complete transfer of " + fromFile.getURL() + " to " + toFile.getURL(), e);
} finally {
// close files if we need to
fromFile.close();
toFile.close();
if (monitor != null) {
monitor.release(toFile);
monitor.stop();
}
}
return true;
}
use of org.apache.commons.vfs2.AllFileSelector in project pentaho-kettle by pentaho.
the class JobEntryMoveFiles method ProcessFileFolder.
private boolean ProcessFileFolder(String sourcefilefoldername, String destinationfilefoldername, String wildcard, Job parentJob, Result result, String MoveToFolder) {
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 {
sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername, this);
destinationfilefolder = KettleVFS.getFileObject(realDestinationFilefoldername, this);
if (!Utils.isEmpty(MoveToFolder)) {
movetofolderfolder = KettleVFS.getFileObject(MoveToFolder, this);
}
if (sourcefilefolder.exists()) {
// 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(BaseMessages.getString(PKG, "JobMoveFiles.Log.Forbidden"), BaseMessages.getString(PKG, "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(shortfilename);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, BaseMessages.getString(PKG, "JobMoveFiles.Error.GettingFilename", sourcefilefolder.getName().getBaseName(), e.toString())));
return entrystatus;
}
// Move the file to the destination folder
String destinationfilenamefull = KettleVFS.getFilename(destinationfilefolder) + Const.FILE_SEPARATOR + shortfilename;
FileObject destinationfile = KettleVFS.getFileObject(destinationfilenamefull, this);
entrystatus = MoveFile(shortfilename, sourcefilefolder, destinationfile, movetofolderfolder, parentJob, result);
return entrystatus;
} else if (sourcefilefolder.getType().equals(FileType.FILE) && destination_is_a_file) {
// Source is a file, destination is a file
FileObject destinationfile = KettleVFS.getFileObject(realDestinationFilefoldername, this);
// return destination short filename
String shortfilename = destinationfile.getName().getBaseName();
try {
shortfilename = getDestinationFilename(shortfilename);
} catch (Exception e) {
logError(BaseMessages.getString(PKG, BaseMessages.getString(PKG, "JobMoveFiles.Error.GettingFilename", sourcefilefolder.getName().getBaseName(), e.toString())));
return entrystatus;
}
String destinationfilenamefull = KettleVFS.getFilename(destinationfile.getParent()) + Const.FILE_SEPARATOR + shortfilename;
destinationfile = KettleVFS.getFileObject(destinationfilenamefull, this);
entrystatus = MoveFile(shortfilename, sourcefilefolder, destinationfile, movetofolderfolder, parentJob, result);
return entrystatus;
} else {
// Both source and destination are folders
if (log.isDetailed()) {
logDetailed(" ");
logDetailed(BaseMessages.getString(PKG, "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) {
/* Ignore */
}
}
}
return true;
}
});
if (fileObjects != null) {
for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) {
// Success condition broken?
if (successConditionBroken) {
if (!successConditionBrokenExit) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Error.SuccessConditionbroken", "" + NrErrors));
successConditionBrokenExit = true;
}
return false;
}
// Fetch files in list one after one ...
Currentfile = fileObjects[j];
if (!MoveOneFile(Currentfile, sourcefilefolder, realDestinationFilefoldername, realWildcard, parentJob, result, movetofolderfolder)) {
// Update Errors
updateErrors();
}
}
}
}
}
entrystatus = true;
} else {
// Destination Folder or Parent folder is missing
logError(BaseMessages.getString(PKG, "JobMoveFiles.Error.DestinationFolderNotFound", realDestinationFilefoldername));
}
} else {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Error.SourceFileNotExists", realSourceFilefoldername));
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobMoveFiles.Error.Exception.MoveProcess", realSourceFilefoldername.toString(), destinationfilefolder.toString(), e.getMessage()));
} finally {
if (sourcefilefolder != null) {
try {
sourcefilefolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (destinationfilefolder != null) {
try {
destinationfilefolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (Currentfile != null) {
try {
Currentfile.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (movetofolderfolder != null) {
try {
movetofolderfolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
}
return entrystatus;
}
use of org.apache.commons.vfs2.AllFileSelector in project pentaho-kettle by pentaho.
the class JobEntryPGPDecryptFiles method ProcessFileFolder.
private boolean ProcessFileFolder(String sourcefilefoldername, String passPhrase, String destinationfilefoldername, String wildcard, Job parentJob, Result result, String MoveToFolder) {
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 {
sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername);
destinationfilefolder = KettleVFS.getFileObject(realDestinationFilefoldername);
if (!Utils.isEmpty(MoveToFolder)) {
movetofolderfolder = KettleVFS.getFileObject(MoveToFolder);
}
if (sourcefilefolder.exists()) {
// 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 !!!
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Log.Forbidden"), BaseMessages.getString(PKG, "JobPGPDecryptFiles.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) {
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.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 = DecryptFile(shortfilename, sourcefilefolder, passPhrase, destinationfile, movetofolderfolder, 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) {
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Error.GettingFilename", sourcefilefolder.getName().getBaseName(), e.toString()));
return entrystatus;
}
String destinationfilenamefull = destinationfilefolder.getParent().toString() + Const.FILE_SEPARATOR + shortfilename;
destinationfile = KettleVFS.getFileObject(destinationfilenamefull);
entrystatus = DecryptFile(shortfilename, sourcefilefolder, passPhrase, destinationfile, movetofolderfolder, parentJob, result);
} else {
// Both source and destination are folders
if (isDetailed()) {
logDetailed(" ");
logDetailed(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Log.FetchFolder", sourcefilefolder.toString()));
}
FileObject[] fileObjects = sourcefilefolder.findFiles(new AllFileSelector() {
public boolean traverseDescendents(FileSelectInfo info) {
return info.getDepth() == 0 || include_subfolders;
}
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();
fileObject = null;
} catch (IOException ex) {
/* Ignore */
}
}
}
return true;
}
});
if (fileObjects != null) {
for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) {
// Success condition broken?
if (successConditionBroken) {
if (!successConditionBrokenExit) {
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Error.SuccessConditionbroken", "" + NrErrors));
successConditionBrokenExit = true;
}
return false;
}
// Fetch files in list one after one ...
Currentfile = fileObjects[j];
if (!DecryptOneFile(Currentfile, sourcefilefolder, passPhrase, realDestinationFilefoldername, realWildcard, parentJob, result, movetofolderfolder)) {
// Update Errors
updateErrors();
}
}
}
}
}
entrystatus = true;
} else {
// Destination Folder or Parent folder is missing
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Error.DestinationFolderNotFound", realDestinationFilefoldername));
}
} else {
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Error.SourceFileNotExists", realSourceFilefoldername));
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobPGPDecryptFiles.Error.Exception.MoveProcess", realSourceFilefoldername.toString(), destinationfilefolder.toString(), e.getMessage()));
// Update Errors
updateErrors();
} finally {
if (sourcefilefolder != null) {
try {
sourcefilefolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (destinationfilefolder != null) {
try {
destinationfilefolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (Currentfile != null) {
try {
Currentfile.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (movetofolderfolder != null) {
try {
movetofolderfolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
}
return entrystatus;
}
use of org.apache.commons.vfs2.AllFileSelector in project pentaho-kettle by pentaho.
the class JobEntryXMLWellFormed method processFileFolder.
private boolean processFileFolder(String sourcefilefoldername, String wildcard, Job parentJob, Result result) {
boolean entrystatus = false;
FileObject sourcefilefolder = null;
FileObject CurrentFile = null;
// Get real source file and wilcard
String realSourceFilefoldername = environmentSubstitute(sourcefilefoldername);
if (Utils.isEmpty(realSourceFilefoldername)) {
logError(BaseMessages.getString(PKG, "JobXMLWellFormed.log.FileFolderEmpty", sourcefilefoldername));
// Update Errors
updateErrors();
return entrystatus;
}
String realWildcard = environmentSubstitute(wildcard);
try {
sourcefilefolder = KettleVFS.getFileObject(realSourceFilefoldername, this);
if (sourcefilefolder.exists()) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobXMLWellFormed.Log.FileExists", sourcefilefolder.toString()));
}
if (sourcefilefolder.getType() == FileType.FILE) {
entrystatus = checkOneFile(sourcefilefolder, 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) {
/* Ignore */
}
}
}
return true;
}
});
if (fileObjects != null) {
for (int j = 0; j < fileObjects.length && !parentJob.isStopped(); j++) {
if (successConditionBroken) {
if (!successConditionBrokenExit) {
logError(BaseMessages.getString(PKG, "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, result, parentJob);
}
}
} else {
// In the base folder
if (GetFileWildcard(CurrentFile.toString(), realWildcard)) {
checkOneFile(CurrentFile, result, parentJob);
}
}
}
}
} else {
logError(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.UnknowFileFormat", sourcefilefolder.toString()));
// Update Errors
updateErrors();
}
} else {
logError(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.SourceFileNotExists", realSourceFilefoldername));
// Update Errors
updateErrors();
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "JobXMLWellFormed.Error.Exception.Processing", realSourceFilefoldername.toString(), e));
// Update Errors
updateErrors();
} finally {
if (sourcefilefolder != null) {
try {
sourcefilefolder.close();
} catch (IOException ex) {
/* Ignore */
}
}
if (CurrentFile != null) {
try {
CurrentFile.close();
} catch (IOException ex) {
/* Ignore */
}
}
}
return entrystatus;
}
Aggregations