List of usage examples for org.apache.commons.io FileUtils moveFile
public static void moveFile(File srcFile, File destFile) throws IOException
From source file:au.org.ala.layers.grid.GridCacheBuilder.java
public static void all(String divaGridDir, String outputDir, LayerIntersectDAO layerIntersectDAO) { //load up all diva grids in a directory ArrayList<Grid> grids = loadGridHeaders(divaGridDir); //identify groups ArrayList<ArrayList<Grid>> groups = identifyGroups(grids); File tmpDir = new File(outputDir + "/tmp/"); try {//from ww w . jav a 2s.c o m FileUtils.forceMkdir(tmpDir); //delete existing files, if any for (File f : tmpDir.listFiles()) { if (f.isFile()) { FileUtils.deleteQuietly(f); } } } catch (IOException e) { logger.error("failed to create or empty tmp dir in: " + outputDir, e); } //write large enough groups for (int i = 0; i < groups.size(); i++) { try { writeGroup(tmpDir.getPath(), groups.get(i)); } catch (IOException e) { logger.error(e.getMessage(), e); } } //delete existing files for (File f : new File(outputDir).listFiles()) { if (f.isFile()) { FileUtils.deleteQuietly(f); } } //move new files for (File f : tmpDir.listFiles()) { try { FileUtils.moveFile(f, new File(f.getPath().replace("/tmp/", ""))); } catch (IOException e) { logger.error("failed to move new grid cache file: " + f.getPath()); } } //reload grid cache layerIntersectDAO.reload(); }
From source file:com.yifanlu.PSXperiaTool.StringReplacement.java
public void replaceStringsIn(File file) throws IOException { String name = file.getPath(); BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedWriter writer = new BufferedWriter(new FileWriter(name + ".tmp")); Logger.debug("Writing to temporary file: %s", name + ".tmp"); String line;/*ww w.j a v a 2 s .c o m*/ while ((line = reader.readLine()) != null) { Logger.verbose("Data line before replacement: %s", line); Iterator<String> keys = mMap.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); String value = mMap.get(key); line = line.replaceAll(key, value); } Logger.verbose("Data line after replacement: %s", line); writer.write(line); writer.newLine(); } reader.close(); writer.close(); file.delete(); FileUtils.moveFile(new File(name + ".tmp"), file); Logger.debug("Successfully cleaned up and done with string replacement."); }
From source file:com.dexels.navajo.tipi.dev.server.appmanager.impl.UnsignJarTask.java
private static void cleanSigningData(File tmpDir, List<String> extraHeaders) throws IOException { File metainf = new File(tmpDir, "META-INF"); if (!metainf.exists()) { logger.warn("No META-INF. Odd."); return;//from w w w . jav a 2s. co m } File[] list = metainf.listFiles(); File manifest = null; for (File file : list) { if (file.getName().toUpperCase().endsWith(".SF")) { file.delete(); } if (file.getName().toUpperCase().endsWith(".RSA")) { file.delete(); } if (file.getName().equals("MANIFEST.MF")) { manifest = file; } } File tmpManifest = new File(metainf, "TMPMANIFEST.MF"); FileUtils.moveFile(manifest, tmpManifest); if (manifest != null) { logger.info( "Moving file from: " + manifest.getAbsolutePath() + " to: " + tmpManifest.getAbsolutePath()); cleanManifest(tmpManifest, manifest, extraHeaders); } tmpManifest.delete(); }
From source file:edu.cornell.med.icb.goby.alignments.perms.ConcatenatePermutations.java
public void concatenate(String destinationBasename) { if (!outputNeedsPermutation) { new File(outputFilename).delete(); } else {/*from www . j a va 2 s . c o m*/ close(); final String destinationFilename = destinationBasename + ".perm"; try { FileUtils.moveFile(new File(outputFilename), new File(destinationFilename)); } catch (IOException e) { LOG.error(String.format("Unable to move temporary permutation file %s to destination %s ", outputFilename, destinationFilename)); } } }
From source file:edu.unc.lib.dl.cdr.sword.server.deposit.DSPACEMETSDepositHandler.java
@Override public DepositReceipt doDeposit(PID destination, Deposit deposit, PackagingType type, SwordConfiguration config, String depositor, String owner) throws SwordError { if (log.isDebugEnabled()) { log.debug("Preparing to perform a DSPACE METS deposit to " + destination.getPid()); log.debug("Working with temporary file: " + deposit.getFile().getAbsolutePath()); }/*from w w w.ja v a 2 s . c o m*/ // extract info from METS header MetsHeaderScanner scanner = new MetsHeaderScanner(); try { scanner.scan(deposit.getFile(), deposit.getFilename()); } catch (Exception e1) { throw new SwordError(ErrorURIRegistry.INGEST_EXCEPTION, 400, "Unable to parse your METS file: " + deposit.getFilename(), e1); } UUID depositUUID = UUID.randomUUID(); PID depositPID = new PID("uuid:" + depositUUID.toString()); File dir = makeNewDepositDirectory(depositPID.getUUID()); // drop upload in data directory try { File data = new File(dir, "data"); data.mkdir(); FileUtils.moveFile(deposit.getFile(), new File(data, deposit.getFilename())); } catch (IOException e) { throw new SwordError(ErrorURIRegistry.INGEST_EXCEPTION, 500, "Unable to create your deposit bag: " + depositPID.getPid(), e); } // METS specific fields Map<String, String> status = new HashMap<String, String>(); status.put(DepositField.metsProfile.name(), scanner.getProfile()); status.put(DepositField.metsType.name(), scanner.getType()); status.put(DepositField.createTime.name(), scanner.getCreateDate()); status.put(DepositField.intSenderDescription.name(), StringUtils.join(scanner.getNames(), ',')); registerDeposit(depositPID, destination, deposit, type, depositor, owner, status); return buildReceipt(depositPID, config); }
From source file:it.drwolf.ridire.utility.RIDIREPlainTextCleaner.java
public void cleanTextFile(File f) throws IOException { File tmpFile = new File(f.getCanonicalPath() + ".tmp"); FileUtils.writeStringToFile(tmpFile, this.getCleanText(f)); FileUtils.deleteQuietly(f);//from www .j a v a2 s. c o m FileUtils.moveFile(tmpFile, f); }
From source file:de.uzk.hki.da.service.CSVQueryHandler.java
@SuppressWarnings({ "serial", "unchecked" }) public void generateRetrievalRequests(File csvFile, File outCsvFile) { try {/*from w w w . ja v a2s .c om*/ csvFileHandler.parseFile(csvFile); Object o = null; for (Map<String, java.lang.Object> csvEntry : csvFileHandler.getCsvEntries()) { logger.debug("Evaluating " + csvEntry.get("origName")); String origName = String.valueOf(csvEntry.get("origName")); o = fetchObject(origName); if (o != null) { createRetrievalJob(o); } } FolderUtils.deleteQuietlySafe(outCsvFile); FileUtils.moveFile(csvFile, outCsvFile); } catch (IOException e) { logger.error("catched " + e.toString() + " while working with " + csvFile.getAbsolutePath()); throw new RuntimeException("CSV File operations not possible " + csvFile.getAbsolutePath(), e) { }; } }
From source file:edu.unc.lib.dl.cdr.sword.server.deposit.CDRMETSDepositHandler.java
@Override public DepositReceipt doDeposit(PID destination, Deposit deposit, PackagingType type, SwordConfiguration config, String depositor, String owner) throws SwordError { if (log.isDebugEnabled()) { log.debug("Preparing to perform a CDR METS deposit to " + destination.getPid()); log.debug("Working with temporary file: " + deposit.getFile().getAbsolutePath()); }//from w w w .j av a 2 s . c om // extract info from METS header MetsHeaderScanner scanner = new MetsHeaderScanner(); try { scanner.scan(deposit.getFile(), deposit.getFilename()); } catch (Exception e1) { throw new SwordError(ErrorURIRegistry.INGEST_EXCEPTION, 400, "Unable to parse your METS file: " + deposit.getFilename(), e1); } PID depositPID = scanner.getObjID(); if (depositPID == null) { UUID depositUUID = UUID.randomUUID(); depositPID = new PID("uuid:" + depositUUID.toString()); } File dir = makeNewDepositDirectory(depositPID.getUUID()); // drop upload in data directory try { File data = new File(dir, "data"); data.mkdir(); FileUtils.moveFile(deposit.getFile(), new File(data, deposit.getFilename())); } catch (IOException e) { throw new SwordError(ErrorURIRegistry.INGEST_EXCEPTION, 500, "Unable to create your deposit bag: " + depositPID.getPid(), e); } // METS specific fields Map<String, String> status = new HashMap<String, String>(); status.put(DepositField.metsProfile.name(), scanner.getProfile()); status.put(DepositField.metsType.name(), scanner.getType()); status.put(DepositField.createTime.name(), scanner.getCreateDate()); status.put(DepositField.intSenderDescription.name(), StringUtils.join(scanner.getNames(), ',')); registerDeposit(depositPID, destination, deposit, type, depositor, owner, status); return buildReceipt(depositPID, config); }
From source file:com.mirth.connect.util.messagewriter.MessageWriterArchive.java
/** * Ends message writing and moves the written folders/files into the archive file. *//*from ww w. j a v a2 s .c o m*/ @Override public void finishWrite() throws MessageWriterException { fileWriter.close(); if (messagesWritten) { try { File tempFile = new File( archiveFile.getParent() + IOUtils.DIR_SEPARATOR + "." + archiveFile.getName()); try { FileUtils.forceDelete(tempFile); } catch (FileNotFoundException e) { } ArchiveUtils.createArchive(rootFolder, tempFile, archiver, compressor); try { FileUtils.forceDelete(archiveFile); } catch (FileNotFoundException e) { } FileUtils.moveFile(tempFile, archiveFile); } catch (Exception e) { throw new MessageWriterException(e); } finally { FileUtils.deleteQuietly(rootFolder); } } }
From source file:com.blogspot.skam94.main.datatypes.FileItem.java
/** * newName must not contain extension/*w w w .j a va 2 s .c o m*/ * @param newName * @return */ public boolean rename(String newName) { if (newName.equals(fileName)) { return true; } File newFile = new File(filePath.concat(newName).concat(getExtWithDot())); try { FileUtils.moveFile(getFile(), newFile); fileName = newName; } catch (IOException e) { // e.printStackTrace(); return false; } return true; }