List of usage examples for org.apache.commons.vfs FileUtil copyContent
public static void copyContent(final FileObject srcFile, final FileObject destFile) throws IOException
From source file:com.panet.imeta.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java
private boolean ProcessFile(FileObject sourcefile, String destinationFolder, LogWriter log, Result result, Job parentJob) {/*w ww. j a va 2 s . co m*/ boolean retval = false; boolean filexists = false; try { // return destination short filename String shortfilename = getDestinationFilename(sourcefile.getName().getBaseName()); // build full destination filename String destinationFilename = destinationFolder + Const.FILE_SEPARATOR + shortfilename; FileObject destinationfile = KettleVFS.getFileObject(destinationFilename); filexists = destinationfile.exists(); if (filexists) { if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.Log.FileExists", destinationFilename)); } if ((!filexists) || (filexists && isOverwriteFile())) { if (getAction().equals("copy")) { // Copy file FileUtil.copyContent(sourcefile, destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.log.CopiedFile", sourcefile.toString(), destinationFolder)); } else { // Move file sourcefile.moveTo(destinationfile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.log.MovedFile", sourcefile.toString(), destinationFolder)); } if (isRemovedSourceFilename()) { // Remove source file from result files list result.getResultFiles().remove(sourcefile.toString()); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString( "JobEntryCopyMoveResultFilenames.RemovedFileFromResult", sourcefile.toString())); } if (isAddDestinationFilename()) { // Add destination filename to Resultfilenames ... ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(destinationfile.toString()), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); if (log.isDetailed()) log.logDetailed(toString(), Messages.getString( "JobEntryCopyMoveResultFilenames.AddedFileToResult", destinationfile.toString())); } } retval = true; } catch (Exception e) { log.logError(toString(), Messages.getString("JobEntryCopyMoveResultFilenames.Log.ErrorProcessing", e.toString())); } return retval; }
From source file:com.akretion.kettle.steps.terminatooor.ScriptValuesAddedFunctions.java
public static void copyFile(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { try {/*from ww w . ja v a 2s .com*/ if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0]) && !isUndefined(ArgList[1])) { FileObject fileSource = null, fileDestination = null; try { // Source file to copy fileSource = KettleVFS.getFileObject((String) ArgList[0]); // Destination filename fileDestination = KettleVFS.getFileObject((String) ArgList[1]); if (fileSource.exists()) { // Source file exists... if (fileSource.getType() == FileType.FILE) { // Great..source is a file ... boolean overwrite = false; if (!ArgList[1].equals(null)) overwrite = (Boolean) ArgList[2]; boolean destinationExists = fileDestination.exists(); // Let's copy the file... if ((destinationExists && overwrite) || !destinationExists) FileUtil.copyContent(fileSource, fileDestination); } } else { new RuntimeException("file to copy [" + (String) ArgList[0] + "] can not be found!"); } } catch (IOException e) { throw new RuntimeException("The function call copyFile throw an error : " + e.toString()); } finally { if (fileSource != null) try { fileSource.close(); } catch (Exception e) { } if (fileDestination != null) try { fileDestination.close(); } catch (Exception e) { } } } else { throw new RuntimeException("The function call copyFileis not valid."); } } catch (Exception e) { throw new RuntimeException(e.toString()); } }
From source file:com.panet.imeta.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static void copyFile(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { try {//from www . j ava 2 s. c om if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0]) && !isUndefined(ArgList[1])) { FileObject fileSource = null, fileDestination = null; try { // Source file to copy fileSource = KettleVFS.getFileObject(Context.toString(ArgList[0])); // Destination filename fileDestination = KettleVFS.getFileObject(Context.toString(ArgList[1])); if (fileSource.exists()) { // Source file exists... if (fileSource.getType() == FileType.FILE) { // Great..source is a file ... boolean overwrite = false; if (!ArgList[1].equals(null)) overwrite = Context.toBoolean(ArgList[2]); boolean destinationExists = fileDestination.exists(); // Let's copy the file... if ((destinationExists && overwrite) || !destinationExists) FileUtil.copyContent(fileSource, fileDestination); } } else { Context.reportRuntimeError( "file to copy [" + Context.toString(ArgList[0]) + "] can not be found!"); } } catch (IOException e) { throw Context.reportRuntimeError("The function call copyFile throw an error : " + e.toString()); } finally { if (fileSource != null) try { fileSource.close(); } catch (Exception e) { } if (fileDestination != null) try { fileDestination.close(); } catch (Exception e) { } } } else { throw Context.reportRuntimeError("The function call copyFileis not valid."); } } catch (Exception e) { throw Context.reportRuntimeError(e.toString()); } }
From source file:org.josso.tooling.gshell.install.installer.VFSInstaller.java
protected boolean installFile(FileObject srcFile, FileObject destDir, String newName, boolean replace) throws IOException { try {/* w ww. j a va 2 s. com*/ String fname = srcFile.getName().getBaseName(); if (srcFile == null || !srcFile.exists()) { printInstallErrStatus(fname, "Source file not found " + fname); throw new IOException("Source file not found " + fname); } // Validates src and dest files if (destDir == null || !destDir.exists()) { printInstallErrStatus(fname, "Target directory not found " + destDir.getURL()); throw new IOException("Target directory not found " + destDir.getURL()); } FileObject destFile = destDir.resolveFile(newName); boolean exists = destFile.exists(); if (!replace && exists) { printInstallWarnStatus(fname, "Not replaced (see --replace option)"); if (fname.equals("josso-agent-config.xml")) { agentConfigFileInstalled = false; } return false; } FileUtil.copyContent(srcFile, destFile); printInstallOkStatus(fname, (exists ? "Replaced " : "Created ") + destFile.getName().getFriendlyURI()); return true; } finally { printer.flush(); } }
From source file:org.pentaho.di.job.entries.copymoveresultfilenames.JobEntryCopyMoveResultFilenames.java
private boolean processFile(FileObject sourcefile, String destinationFolder, Result result, Job parentJob, boolean deleteFile) { boolean retval = false; try {/*w w w .j ava 2s . c o m*/ if (deleteFile) { // delete file if (sourcefile.delete()) { if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.log.DeletedFile", sourcefile.toString())); } // Remove source file from result files list result.getResultFiles().remove(sourcefile.toString()); if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.RemovedFileFromResult", sourcefile.toString())); } } else { logError(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.CanNotDeletedFile", sourcefile.toString())); } } else { // return destination short filename String shortfilename = getDestinationFilename(sourcefile.getName().getBaseName()); // build full destination filename String destinationFilename = destinationFolder + Const.FILE_SEPARATOR + shortfilename; FileObject destinationfile = KettleVFS.getFileObject(destinationFilename, this); boolean filexists = destinationfile.exists(); if (filexists) { if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.Log.FileExists", destinationFilename)); } } if ((!filexists) || (filexists && isOverwriteFile())) { if (getAction().equals("copy")) { // Copy file FileUtil.copyContent(sourcefile, destinationfile); if (log.isDetailed()) { logDetailed( BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.log.CopiedFile", sourcefile.toString(), destinationFolder)); } } else { // Move file sourcefile.moveTo(destinationfile); if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.log.MovedFile", sourcefile.toString(), destinationFolder)); } } if (isRemovedSourceFilename()) { // Remove source file from result files list result.getResultFiles().remove(sourcefile.toString()); if (log.isDetailed()) { logDetailed(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.RemovedFileFromResult", sourcefile.toString())); } } if (isAddDestinationFilename()) { // Add destination filename to Resultfilenames ... ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, KettleVFS.getFileObject(destinationfile.toString(), this), parentJob.getJobname(), toString()); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); if (log.isDetailed()) { logDetailed( BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.AddedFileToResult", destinationfile.toString())); } } } } retval = true; } catch (Exception e) { logError(BaseMessages.getString(PKG, "JobEntryCopyMoveResultFilenames.Log.ErrorProcessing", e.toString())); } return retval; }
From source file:org.pentaho.di.trans.steps.script.ScriptAddedFunctions.java
public static void copyFile(ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext) { try {// w w w . j a va2 s. c o m if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0]) && !isUndefined(ArgList[1])) { FileObject fileSource = null, fileDestination = null; try { // Source file to copy fileSource = KettleVFS.getFileObject((String) ArgList[0]); // Destination filename fileDestination = KettleVFS.getFileObject((String) ArgList[1]); if (fileSource.exists()) { // Source file exists... if (fileSource.getType() == FileType.FILE) { // Great..source is a file ... boolean overwrite = false; if (!ArgList[1].equals(null)) { overwrite = (Boolean) ArgList[2]; } boolean destinationExists = fileDestination.exists(); // Let's copy the file... if ((destinationExists && overwrite) || !destinationExists) { FileUtil.copyContent(fileSource, fileDestination); } } } else { new RuntimeException("file to copy [" + (String) ArgList[0] + "] can not be found!"); } } catch (IOException e) { throw new RuntimeException("The function call copyFile throw an error : " + e.toString()); } finally { if (fileSource != null) { try { fileSource.close(); } catch (Exception e) { // Ignore errors } } if (fileDestination != null) { try { fileDestination.close(); } catch (Exception e) { // Ignore errors } } } } else { throw new RuntimeException("The function call copyFileis not valid."); } } catch (Exception e) { throw new RuntimeException(e.toString()); } }
From source file:org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.java
public static void copyFile(Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext) { try {//from w w w .ja v a 2 s . c om if (ArgList.length == 3 && !isNull(ArgList[0]) && !isNull(ArgList[1]) && !isUndefined(ArgList[0]) && !isUndefined(ArgList[1])) { FileObject fileSource = null, fileDestination = null; try { // Source file to copy fileSource = KettleVFS.getFileObject(Context.toString(ArgList[0])); // Destination filename fileDestination = KettleVFS.getFileObject(Context.toString(ArgList[1])); if (fileSource.exists()) { // Source file exists... if (fileSource.getType() == FileType.FILE) { // Great..source is a file ... boolean overwrite = false; if (!ArgList[1].equals(null)) { overwrite = Context.toBoolean(ArgList[2]); } boolean destinationExists = fileDestination.exists(); // Let's copy the file... if ((destinationExists && overwrite) || !destinationExists) { FileUtil.copyContent(fileSource, fileDestination); } } } else { Context.reportRuntimeError( "file to copy [" + Context.toString(ArgList[0]) + "] can not be found!"); } } catch (IOException e) { throw Context.reportRuntimeError("The function call copyFile throw an error : " + e.toString()); } finally { if (fileSource != null) { try { fileSource.close(); } catch (Exception e) { // Ignore errors } } if (fileDestination != null) { try { fileDestination.close(); } catch (Exception e) { // Ignore errors } } } } else { throw Context.reportRuntimeError("The function call copyFileis not valid."); } } catch (Exception e) { throw Context.reportRuntimeError(e.toString()); } }