List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:com.bluexml.side.Util.ecore.autofix.Fixer.java
protected Object fix(Exception e) { for (AbstractFixer fixer : fixers.values()) { boolean ok = fixer.fixe(modelFile, e); if (ok) { // try to run again try { File fixedFile = fixer.getFixedFile(); Object rt = action.execute(fixedFile); // job done, so persist changes FileUtils.copyFile(fixedFile, modelFile); System.out.println("model " + modelFile + " have been fixed by " + fixer); return rt; } catch (Exception e1) { e1.printStackTrace();/*from w w w.j av a 2s . c o m*/ } } else { System.out.println("fixer " + fixer + " is unable to perform correction for this error"); } } System.out.println("no fixer found for +" + modelFile + " and error " + e); return null; }
From source file:de.uni_siegen.wineme.come_in.thumbnailer.util.TemporaryFilesManager.java
private void createNewCopy(File file, File destFile) throws IOException { FileUtils.copyFile(file, destFile); files.put(file, destFile); }
From source file:com.digitalgeneralists.assurance.model.merge.TargetMergeEngine.java
@Override public void mergeResult(ComparisonResult result, IProgressMonitor monitor) throws AssuranceNullFileReferenceException { File sourceFile = result.getSource().getFile(); File targetFile = result.getTarget().getFile(); if ((sourceFile == null) || (targetFile == null)) { throw new AssuranceNullFileReferenceException("The source or target file is null."); }//from ww w . j a v a2 s. c o m if (monitor != null) { StringBuilder message = new StringBuilder(512); monitor.publish(message.append("Merging ").append(targetFile.toString()).append(" to ") .append(sourceFile.toString()).toString()); message.setLength(0); message = null; } if (targetFile.exists()) { try { if (targetFile.isDirectory()) { FileUtils.copyDirectory(targetFile, sourceFile); } else { FileUtils.copyFile(targetFile, sourceFile); } result.setResolution(AssuranceResultResolution.REPLACE_SOURCE); } catch (IOException e) { logger.error("An error occurred when replacing the source with the target."); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } } else { if (sourceFile.exists()) { File scanDeletedItemsLocation = result .getSourceDeletedItemLocation(getApplicationDeletedItemsLocation()); if (scanDeletedItemsLocation == null) { StringBuilder deletedFilePath = new StringBuilder(512); scanDeletedItemsLocation = new File( deletedFilePath.append(this.getDefaultDeletedItemsLocation()).append(File.separator) .append(sourceFile.getName()).toString()); deletedFilePath.setLength(0); } try { if (sourceFile.isDirectory()) { FileUtils.moveDirectory(sourceFile, scanDeletedItemsLocation); } else { FileUtils.moveFile(sourceFile, scanDeletedItemsLocation); } result.setResolution(AssuranceResultResolution.DELETE_SOURCE); } catch (IOException e) { StringBuffer message = new StringBuffer(512); logger.error(message.append("Could not move item to deleted items location ") .append(sourceFile.getPath())); message.setLength(0); message = null; result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } scanDeletedItemsLocation = null; } } sourceFile = null; targetFile = null; }
From source file:com.digitalgeneralists.assurance.model.merge.SourceMergeEngine.java
@Override public void mergeResult(ComparisonResult result, IProgressMonitor monitor) throws AssuranceNullFileReferenceException { File sourceFile = result.getSource().getFile(); File targetFile = result.getTarget().getFile(); if ((sourceFile == null) || (targetFile == null)) { throw new AssuranceNullFileReferenceException("The source or target file is null."); }/* w w w . j ava 2 s . c o m*/ if (monitor != null) { StringBuilder message = new StringBuilder(512); monitor.publish(message.append("Merging ").append(sourceFile.toString()).append(" to ") .append(targetFile.toString()).toString()); message.setLength(0); message = null; } if (sourceFile.exists()) { try { if (sourceFile.isDirectory()) { FileUtils.copyDirectory(sourceFile, targetFile); } else { FileUtils.copyFile(sourceFile, targetFile); } result.setResolution(AssuranceResultResolution.REPLACE_TARGET); } catch (IOException e) { logger.error("An error occurred when replacing the target with the source."); result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } } else { if (targetFile.exists()) { File scanDeletedItemsLocation = result .getTargetDeletedItemLocation(getApplicationDeletedItemsLocation()); if (scanDeletedItemsLocation == null) { StringBuilder deletedItemPath = new StringBuilder(512); scanDeletedItemsLocation = new File( deletedItemPath.append(this.getDefaultDeletedItemsLocation()).append(File.separator) .append(targetFile.getName()).toString()); deletedItemPath.setLength(0); deletedItemPath = null; } try { if (targetFile.isDirectory()) { FileUtils.moveDirectory(targetFile, scanDeletedItemsLocation); } else { FileUtils.moveFile(targetFile, scanDeletedItemsLocation); } result.setResolution(AssuranceResultResolution.DELETE_TARGET); } catch (IOException e) { StringBuffer message = new StringBuffer(512); logger.warn(message.append("Could not move item to deleted items location ") .append(sourceFile.getPath())); message.setLength(0); message = null; result.setResolution(AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED); result.setResolutionError(e.getMessage()); } scanDeletedItemsLocation = null; } } sourceFile = null; targetFile = null; }
From source file:Helpers.FileHelper.java
public void copyFile(File source, File dest) throws IOException { FileUtils.copyFile(source, dest); }
From source file:com.liveramp.hank.storage.LocalPartitionRemoteFileOps.java
@Override public void copyToLocalRoot(String remoteSourceRelativePath, String localDestinationRoot) throws IOException { File source = new File(getRemoteAbsolutePath(remoteSourceRelativePath)); File destination = new File(localDestinationRoot + "/" + source.getName()); FileUtils.copyFile(source, destination); }
From source file:net.chris54721.infinitycubed.data.Asset.java
public boolean copyToLegacy() { try {/*from www .jav a2 s .c o m*/ legacyFile.getParentFile().mkdirs(); FileUtils.copyFile(getTarget(), legacyFile); return isLocalValid(); } catch (IOException e) { LogHelper.error("Failed copying asset " + name + " to legacy file", e); return false; } }
From source file:es.uvigo.ei.sing.adops.operations.CopyExperiment.java
@Port(order = 3, direction = Direction.OUTPUT) public Experiment copyExperiment() throws IOException, IllegalArgumentException { final File newFolder = new File(this.experiment.getFolder().getParentFile(), this.name); if (newFolder.exists()) throw new FileExistsException("New experiment folder already exists (" + newFolder + ")"); if (!(new File(newFolder, this.experiment.getFilesFolder().getName()).mkdirs())) throw new IOException("Error writing in new folder (" + newFolder + ")"); FileUtils.copyFile(this.experiment.getPropertiesFile(), new File(newFolder, this.experiment.getPropertiesFile().getName())); FileUtils.copyFile(this.experiment.getNotesFile(), new File(newFolder, this.experiment.getNotesFile().getName())); return new ProjectExperiment(this.experiment.getProject(), newFolder); }
From source file:ch.unibas.fittingwizard.application.tools.GaussianLogModifier.java
public void createBackup(File file) { File bak = getBackupFileName(file); try {//w w w .j a v a2 s .c o m FileUtils.copyFile(file, bak); } catch (IOException e) { throw new RuntimeException("Could not create backup file " + bak.getAbsolutePath()); } }
From source file:azkaban.storage.LocalStorage.java
@Override public String put(StorageMetadata metadata, File localFile) { final File projectDir = new File(rootDirectory, String.valueOf(metadata.getProjectId())); if (projectDir.mkdir()) { log.info("Created project dir: " + projectDir.getAbsolutePath()); }//ww w . j a va2 s . c o m final File targetFile = new File(projectDir, String.format("%s-%s.%s", String.valueOf(metadata.getProjectId()), new String(metadata.getHash()), Files.getFileExtension(localFile.getName()))); if (targetFile.exists()) { throw new StorageException( String.format("Error in LocalStorage. Target file already exists. targetFile: %s, Metadata: %s", targetFile, metadata)); } try { FileUtils.copyFile(localFile, targetFile); } catch (IOException e) { log.error("LocalStorage error in put(): Metadata: " + metadata); throw new StorageException(e); } return createRelativePath(targetFile); }