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.fizzed.stork.assembly.CopyFile.java
public void copyFile(File inputFile, File outputDir) throws IOException { if (inputFile.isDirectory()) { File[] files = inputFile.listFiles(); File newOutputDir = new File(outputDir, inputFile.getName()); for (File f : files) { copyFile(f, newOutputDir);/*from w w w.ja va 2 s .c o m*/ } } else { File outputFile = new File(outputDir, inputFile.getName()); outputDir.mkdirs(); logger.info(" copying " + inputFile + " to " + outputFile); FileUtils.copyFile(inputFile, outputFile); if (inputFile.canExecute()) { outputFile.setExecutable(true); } } }
From source file:com.abiquo.am.services.DiskFileServiceImpl.java
@Override public void copy(String source, final String destination) { source = customEncode(source); // source is automatic decoded ( :9000 -> %3A9000) LOGGER.info("Copying disk file from [{}] to [{}]", source, destination); final File sourceFile = getFile(source); final File destinationFile = new File(FilenameUtils.concat(repositoryPath, destination)); if (destinationFile.exists()) { throw new AMException(AMError.DISK_FILE_ALREADY_EXIST, destination); }/* ww w .j a va 2 s.c o m*/ if (!sourceFile.exists()) { throw new AMException(AMError.DISK_FILE_NOT_FOUND, source); } try { FileUtils.copyFile(sourceFile, destinationFile); } catch (IOException e) { throw new AMException(AMError.DISK_FILE_COPY_ERROR, e); } LOGGER.info("Copy process finished"); }
From source file:me.neatmonster.spacertk.actions.FileActions.java
/** * Copy's a file/*from w w w .j a va2 s. c o m*/ * @param oldFile File to copy * @param newFile File to copy to * @return */ @Action(aliases = { "copyFile" }) public boolean copyFile(final String oldFile, final String newFile) { try { FileUtils.copyFile(new File(oldFile), new File(newFile)); return true; } catch (final IOException e) { e.printStackTrace(); } return false; }
From source file:biz.gabrys.maven.plugins.directory.content.CopyMojo.java
private void copy(final File source, final File destination) throws MojoFailureException { if (!force && destination.exists() && source.lastModified() < destination.lastModified()) { if (verbose) { getLog().info("Skips copy file, because source is older than destination file: " + destination.getAbsolutePath()); }/* w w w . ja va 2 s . c o m*/ return; } if (verbose) { getLog().info( String.format("Copying %s to %s", source.getAbsolutePath(), destination.getAbsolutePath())); } try { FileUtils.copyFile(source, destination); } catch (final IOException e) { final String message = String.format("Cannot copy %s to %s", source.getAbsolutePath(), destination.getAbsolutePath()); throw new MojoFailureException(message, e); } }
From source file:com.santiagolizardo.madcommander.dialogs.progressive.CopyProgressDialog.java
@Override public void run() { if (srcPath.equals(dstPath)) { DialogFactory.showErrorMessage(sourceListing.getParent(), "You cannot copy a file to itself!"); dispose();/*from ww w . j a v a2s .c o m*/ return; } List<File> selectedFiles = sourceListing.getSelectedFiles(); int numFiles = selectedFiles.size(); myProcess.totalProgress = 0; for (int i = 0; i < selectedFiles.size(); i++) { myProcess.currentFile = selectedFiles.get(i).getName(); myProcess.currentProgress = 0; currentFileLabel.setText("Current file: " + myProcess.currentFile); String fullSrc = srcPath + File.separator + myProcess.currentFile; String fullDst = dstPath + File.separator + myProcess.currentFile; StringBuilder buffer = new StringBuilder(); buffer.append("Copying [ "); buffer.append(fullSrc); buffer.append(" => "); buffer.append(fullDst); buffer.append(" ]"); logger.info(buffer.toString()); try { File fileSrc = new File(fullSrc); File fileDst = new File(fullDst); if (fileSrc.isDirectory()) FileUtils.copyDirectory(fileSrc, fileDst); else FileUtils.copyFile(fileSrc, fileDst); myProcess.currentProgress = 100; myProcess.totalProgress = (i * 100) / numFiles; if (myProcess.cancel) { logger.info("Cancel copying."); return; } } catch (IOException e) { e.printStackTrace(); } } myProcess.totalProgress = 100; }
From source file:net.jsign.PESignerTest.java
public void testTimestampAuthenticode() throws Exception { File sourceFile = new File("target/test-classes/wineyes.exe"); File targetFile = new File("target/test-classes/wineyes-timestamped-authenticode.exe"); FileUtils.copyFile(sourceFile, targetFile); PEFile peFile = new PEFile(targetFile); PESigner signer = new PESigner(getKeyStore(), ALIAS, PRIVATE_KEY_PASSWORD); signer.withDigestAlgorithm(DigestAlgorithm.SHA1); signer.withTimestamping(true);/*from ww w .ja v a2 s .c o m*/ signer.withTimestampingMode(TimestampingMode.AUTHENTICODE); signer.sign(peFile); peFile = new PEFile(targetFile); List<CMSSignedData> signatures = peFile.getSignatures(); assertNotNull(signatures); assertEquals(1, signatures.size()); CMSSignedData signature = signatures.get(0); assertNotNull(signature); }
From source file:gov.redhawk.efs.sca.server.internal.FileSystemImpl.java
@Override public void copy(final String sourceFileName, final String destinationFileName) throws InvalidFileName, FileException { if (sourceFileName.equals(destinationFileName)) { throw new InvalidFileName(ErrorNumberType.CF_EINVAL, "Source file must be different from destination file."); }/*from ww w .j a v a 2 s. c om*/ final File sourceFile = new File(this.root, sourceFileName); try { FileUtils.copyFile(sourceFile, new File(this.root, destinationFileName)); } catch (final IOException e) { throw new FileException(ErrorNumberType.CF_EIO, e.getMessage()); } }
From source file:com.thoughtworks.go.helpers.Localhost.java
Localhost(int port, String overrideConfigFilePath, List<String> pipelineNames, List<String> baseStageNames, List<String> baseBuildNames) throws Exception { this.pipelineNames = pipelineNames; this.baseStageNames = baseStageNames; this.baseBuildNames = baseBuildNames; File configXml = DataUtils.getConfigXmlOfWebApp(); File srcFile;//w w w . j a v a2 s.co m if (overrideConfigFilePath == null) { srcFile = DataUtils.getConfigXmlAsFile(); } else { srcFile = new File(overrideConfigFilePath); } FileUtils.copyFile(srcFile, configXml); new SystemEnvironment().setProperty(SystemEnvironment.CONFIG_FILE_PROPERTY, configXml.getAbsolutePath()); new SystemEnvironment().setProperty("jdbc.port", "9003"); server = new Server(port); WebAppContext context = new WebAppContext("webapp", "/go"); context.setConfigurationClasses(new String[] { WebInfConfiguration.class.getCanonicalName(), WebXmlConfiguration.class.getCanonicalName(), JettyWebXmlConfiguration.class.getCanonicalName() }); context.setDefaultsDescriptor("webapp/WEB-INF/webdefault.xml"); server.setHandler(context); this.setCookieExpireIn6Months(context); }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SelectSTSMFListener.java
@Override public void handleEvent(Event event) { String path = this.selectSTSMFUI.getPath(); if (path == null) return;/* w ww . ja va2 s . c o m*/ if (path.contains("%")) { this.selectSTSMFUI.displayMessage("File name can not contain percent ('%') symbol."); return; } File file = new File(path); if (file.exists()) { if (file.isFile()) { if (!this.checkFormat(file)) return; String newPath; if (file.getName().endsWith(".subject_mapping")) { newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName(); } else { newPath = this.dataType.getPath().getAbsolutePath() + File.separator + file.getName() + ".subject_mapping"; } File copiedFile = new File(newPath); try { FileUtils.copyFile(file, copiedFile); ((GeneExpressionData) this.dataType).setSTSMF(copiedFile); this.selectSTSMFUI.displayMessage("File has been loaded"); WorkPart.updateSteps(); //to do: update files list UsedFilesPart.sendFilesChanged(this.dataType); } catch (IOException e) { // TODO Auto-generated catch block selectSTSMFUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } } else { this.selectSTSMFUI.displayMessage("This is a directory"); } } else { this.selectSTSMFUI.displayMessage("This path does no exist"); } }
From source file:io.apiman.manager.test.server.ApiManagerTestPluginRegistry.java
/** * @see io.apiman.manager.api.core.plugin.AbstractPluginRegistry#downloadPlugin(java.io.File, io.apiman.common.plugin.PluginCoordinates) *//*from w w w . j av a 2s .c om*/ @Override protected void downloadPlugin(File pluginFile, PluginCoordinates coordinates) { String testM2Path = System.getProperty("apiman.test.m2-path"); //$NON-NLS-1$ if (testM2Path == null) { return; } File testM2Dir = new File(testM2Path).getAbsoluteFile(); File pluginArtifactFile = new File(testM2Dir, PluginUtils.getMavenPath(coordinates)); if (!pluginArtifactFile.isFile()) { return; } try { FileUtils.copyFile(pluginArtifactFile, pluginFile); } catch (IOException e) { pluginArtifactFile.delete(); } }