List of usage examples for org.apache.commons.io FileUtils moveFile
public static void moveFile(File srcFile, File destFile) throws IOException
From source file:com.esofthead.mycollab.module.file.service.impl.FileRawContentServiceImpl.java
@Override public void movePath(String oldPath, String destinationPath) { try {//from w w w . j a v a2 s . c o m File src = new File(baseFolder + "/" + oldPath); File dest = new File(baseFolder + "/" + destinationPath); if (!src.exists()) { LOG.debug("Source: {} is not existed", src.getPath()); return; } if (dest.exists()) { FileUtils.deleteQuietly(dest); } if (src.isFile()) { FileUtils.moveFile(src, dest); } else { FileUtils.moveDirectory(src, dest); } } catch (IOException e) { throw new MyCollabException(e); } }
From source file:com.dianping.phoenix.dev.core.tools.wms.AgentWorkspaceServiceImpl.java
@Override protected void generateContainer(WorkspaceContext context, OutputStream out) throws Exception { checkoutSource(context, out);/* w ww . jav a 2 s. co m*/ File warBase = new File(context.getBaseDir(), WorkspaceConstants.PHOENIX_CONTAINER_FOLDER); File webInfFolder = new File(warBase, "WEB-INF"); File phoenixServerFolder = new File(webInfFolder, "classes/com/dianping/phoenix/container/"); FileUtils.forceMkdir(webInfFolder); FileUtils.forceMkdir(phoenixServerFolder); String libZipName = "lib.zip"; copyFile(libZipName, webInfFolder); ZipUtil.unpack(new File(webInfFolder, libZipName), webInfFolder); FileUtils.deleteQuietly(new File(webInfFolder, libZipName)); ContainerWebXMLGenerator containerWebXMLGenerator = new ContainerWebXMLGenerator(); containerWebXMLGenerator.generate(new File(webInfFolder, "web.xml"), null); String serverClassFileName = "AgentPhoenixServer.classfile"; copyFile(serverClassFileName, phoenixServerFolder); FileUtils.moveFile(new File(phoenixServerFolder, serverClassFileName), new File(phoenixServerFolder, "PhoenixServer.class")); }
From source file:br.com.elotech.sits.service.AbstractService.java
public void moveToSent(File fileSent) throws IOException { FileUtils.moveFile(fileSent, getFileToWriteSent(fileSent)); }
From source file:com.hs.mail.deliver.Deliver.java
private void deliver(String from, String[] rcpts, File file) { SmtpMessage message = null;/*from w w w . j a v a2s . c om*/ try { MailAddress sender = new MailAddress(from, false); message = new SmtpMessage(sender, SmtpMessage.LOCAL); for (int i = 0; i < rcpts.length; i++) { Recipient rcpt = new Recipient(rcpts[i], false); message.addRecipient(rcpt); } FileUtils.moveFile(file, message.getDataFile()); message.store(); message.createTrigger(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); // If exception caught, remove temporary files if (message != null) { message.dispose(); } System.exit(EX_TEMPFAIL); } }
From source file:com.manydesigns.elements.util.ElementsFileUtils.java
public static void moveFileSafely(File tempFile, String fileName) throws IOException { File destination = new File(fileName); if (!destination.exists()) { FileUtils.moveFile(tempFile, destination); } else {// w w w . ja v a 2s .c om File backup = File.createTempFile(destination.getName(), ".backup", destination.getParentFile()); if (!backup.delete()) { logger.warn("Cannot delete: {}", backup); } FileUtils.moveFile(destination, backup); FileUtils.moveFile(tempFile, destination); if (!backup.delete()) { logger.warn("Cannot delete: {}", backup); } } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.SetSubjectsIdListener.java
@Override public void handleEvent(Event event) { // TODO Auto-generated method stub Vector<String> values = this.setSubjectsIdUI.getValues(); Vector<String> samples = this.setSubjectsIdUI.getSamples(); for (String v : values) { if (v.compareTo("") == 0) { this.setSubjectsIdUI.displayMessage("All identifiers have to be set"); return; }/*from w w w.j a va 2 s .co m*/ } File file = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".subject_mapping.tmp"); try { FileWriter fw = new FileWriter(file); BufferedWriter out = new BufferedWriter(fw); out.write( "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n"); File stsmf = ((GeneExpressionData) this.dataType).getStsmf(); if (stsmf == null) { for (int i = 0; i < samples.size(); i++) { out.write(this.dataType.getStudy().toString() + "\t" + "\t" + values.elementAt(i) + "\t" + samples.elementAt(i) + "\t" + "\t" + "\t" + "\t" + "\t" + "\n"); } } else { try { BufferedReader br = new BufferedReader(new FileReader(stsmf)); String line = br.readLine(); while ((line = br.readLine()) != null) { String[] fields = line.split("\t", -1); String sample = fields[3]; String subject; if (samples.contains(sample)) { subject = values.get(samples.indexOf(sample)); } else { br.close(); return; } out.write(fields[0] + "\t" + fields[1] + "\t" + subject + "\t" + sample + "\t" + fields[4] + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n"); } br.close(); } catch (Exception e) { this.setSubjectsIdUI.displayMessage("File error: " + e.getLocalizedMessage()); out.close(); e.printStackTrace(); } } out.close(); try { File fileDest; if (stsmf != null) { String fileName = stsmf.getName(); stsmf.delete(); fileDest = new File(this.dataType.getPath() + File.separator + fileName); } else { fileDest = new File(this.dataType.getPath() + File.separator + this.dataType.getStudy().toString() + ".subject_mapping"); } FileUtils.moveFile(file, fileDest); ((GeneExpressionData) this.dataType).setSTSMF(fileDest); } catch (IOException ioe) { this.setSubjectsIdUI.displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.setSubjectsIdUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } this.setSubjectsIdUI.displayMessage("Subject to sample mapping file updated"); WorkPart.updateSteps(); WorkPart.updateFiles(); UsedFilesPart.sendFilesChanged(dataType); }
From source file:com.thoughtworks.go.server.service.ConsoleService.java
public void moveConsoleArtifacts(LocatableEntity locatableEntity) { try {/*from w w w .ja v a 2s . co m*/ File from = chooser.temporaryConsoleFile(locatableEntity); // Job cancellation skips temporary file creation. Force create one if it does not exist. FileUtils.touch(from); File to = consoleLogArtifact(locatableEntity); FileUtils.moveFile(from, to); } catch (IOException | IllegalArtifactLocationException e) { throw new RuntimeException(e); } }
From source file:c3.ops.priam.backup.MetaData.java
public File createTmpMetaFile() throws IOException { File metafile = File.createTempFile("meta", ".json"); File destFile = new File(metafile.getParent(), "meta.json"); if (destFile.exists()) destFile.delete();/*from www . jav a 2 s . com*/ FileUtils.moveFile(metafile, destFile); return destFile; }
From source file:com.qualinsight.mojo.cobertura.core.OverallCoverageReportMojo.java
private void cleanupFileSystem(final File baseDataFile, final File destinationDataFile) throws MojoExecutionException { getLog().debug("Cleaning up directories after Cobertura report generation"); try {/* w w w .j a v a2 s . c om*/ FileUtils.moveFile(baseDataFile, destinationDataFile); } catch (final IOException e) { final String message = "An error occurred during directories cleanup: "; getLog().error(message, e); throw new MojoExecutionException(message, e); } }
From source file:com.bittorrent.mpetazzoni.client.storage.FileStorage.java
/** Move the partial file to its final location. *//*from w w w .j a va 2 s .c o m*/ @Override public synchronized void finish() throws IOException { logger.debug("Closing file channel to " + this.current.getName() + " (download complete)."); if (this.channel.isOpen()) { this.channel.force(true); } // Nothing more to do if we're already on the target file. if (this.isFinished()) { return; } this.raf.close(); FileUtils.deleteQuietly(this.target); FileUtils.moveFile(this.current, this.target); logger.debug("Re-opening torrent byte storage at {}.", this.target.getAbsolutePath()); this.raf = new RandomAccessFile(this.target, "rw"); this.raf.setLength(this.size); this.channel = this.raf.getChannel(); this.current = this.target; FileUtils.deleteQuietly(this.partial); logger.info("Moved torrent data from {} to {}.", this.partial.getName(), this.target.getName()); }