List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:de.cismet.cids.custom.utils.vermessungsunterlagen.tasks.VermUntTaskRisse.java
@Override public void performTask() throws VermessungsunterlagenTaskException { final String prefix = (ServerAlkisConf.getInstance().getVermessungHostBilder().equalsIgnoreCase(host) ? "Vermessungsrisse-Bericht" : "Ergnzende-Dokumente-Bericht"); final String suffix = getJobKey().substring(getJobKey().indexOf("_") + 1, getJobKey().length()); final String filename = getPath() + "/" + prefix + "_" + suffix.replace("/", "--") + ".pdf"; final File src = new File(VermessungsunterlagenHelper.getInstance().getProperties().getAbsPathPdfRisse()); final File dst = new File(getPath() + "/" + src.getName()); if (!dst.exists()) { try {/* w w w . j a v a 2 s .c o m*/ FileUtils.copyFile(src, dst); } catch (final Exception ex) { final String message = "Beim Kopieren des Risse-Informations-PDFs kam es zu einem unerwarteten Fehler."; throw new VermessungsunterlagenTaskException(getType(), message, ex); } } final Object[] tmp = VermessungsRissReportHelper.getInstance().generateReportData(auftragsnummer, projektnummer, risseBeans, host, MultiPagePictureReader.class); final Collection<CidsBean> reportBeans = (Collection) tmp[0]; final Map parameters = (Map) tmp[1]; final Collection<URL> additionalFilesToDownload = (Collection) tmp[2]; final JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(reportBeans); { OutputStream out = null; try { out = new FileOutputStream(filename); jasperReportDownload( ServerResourcesLoader.getInstance() .loadJasperReport(WundaBlauServerResources.VERMESSUNGSRISSE_JASPER.getValue()), parameters, dataSource, out); } catch (final Exception ex) { final String message = "Beim Erzeugen des Vermessungsrisse-Berichtes kam es zu einem unerwarteten Fehler."; throw new VermessungsunterlagenTaskException(getType(), message, ex); } finally { closeStream(out); } } final ExtendedAccessHandler extendedAccessHandler = new SimpleHttpAccessHandler(); for (final URL additionalFileToDownload : additionalFilesToDownload) { final String additionalFilename = getPath() + "/" + additionalFileToDownload.getFile() .substring(additionalFileToDownload.getFile().lastIndexOf('/') + 1); final String pureAdditionalFilename = additionalFilename.substring(0, additionalFilename.lastIndexOf('.')); InputStream in = null; OutputStream out = null; try { in = extendedAccessHandler.doRequest(additionalFileToDownload); out = new FileOutputStream(additionalFilename); downloadStream(in, out); } catch (Exception ex) { LOG.warn("could not download additional File", ex); VermessungsunterlagenHelper.writeExceptionJson(ex, VermessungsunterlagenHelper.getInstance().getPath(getJobKey().replace("/", "--")) + "/fehlerprotokoll_" + pureAdditionalFilename + ".json"); } finally { closeStream(in); closeStream(out); } } }
From source file:com.ccoe.build.service.track.QueueService.java
@POST @Path("/queue/{appname}") @Consumes(MediaType.MULTIPART_FORM_DATA) public String post(final FormDataMultiPart multiPart, @PathParam("appname") String appName) { File appQueueFolder = new File(queueRoot, appName); if (!appQueueFolder.exists()) { System.out.println("Making application queue root: " + appQueueFolder); appQueueFolder.mkdirs();/*from www . j a va 2 s . com*/ } List<String> files = new ArrayList<String>(); List<BodyPart> parts = multiPart.getBodyParts(); for (BodyPart bodyPart : parts) { if (bodyPart instanceof FormDataBodyPart) { FormDataBodyPart part = (FormDataBodyPart) bodyPart; String fileName = part.getFormDataContentDisposition().getFileName(); File resultFile = new File(appQueueFolder, fileName); if (resultFile.exists()) { System.err.println( fileName + " already upLoaded? Same file found in queue root: " + appQueueFolder); } else { File uploadedTemp = part.getEntityAs(File.class); try { FileUtils.copyFile(uploadedTemp, resultFile); FileUtils.deleteQuietly(uploadedTemp); files.add(fileName); } catch (IOException ex) { Logger.getLogger(QueueService.class.getName()).log(Level.SEVERE, "Cannot move: " + uploadedTemp + " to: " + appQueueFolder, ex); System.err.println("Failed to process upload file: " + fileName); } } } } return "Files: " + files + " queued @ " + getHostName() + " in folder: " + appQueueFolder; }
From source file:com.ettrema.http.fs.FsFileResource.java
/** * @{@inheritDoc}//from www .jav a2 s .c om */ @Override protected void doCopy(File dest) { try { FileUtils.copyFile(file, dest); } catch (IOException ex) { throw new RuntimeException("Failed doing copy to: " + dest.getAbsolutePath(), ex); } }
From source file:be.vds.jtbdive.core.utils.FileUtilities.java
public static void renameFile(File srcFile, File destFile) throws IOException { FileUtils.copyFile(srcFile, destFile); srcFile.delete(); }
From source file:atg.tools.dynunit.test.util.FileUtil.java
public static void forceComponentScope(final File file, final String scope) throws IOException { final long oldLastModified = getConfigFileLastModified(file); if (oldLastModified < file.lastModified()) { final File tempFile = newTempFile(); BufferedWriter out = null; BufferedReader in = null; try {//from ww w. ja va2 s . c o m out = new BufferedWriter(new FileWriter(tempFile)); in = new BufferedReader(new FileReader(file)); for (String line = in.readLine(); line != null; line = in.readLine()) { if (line.contains("$scope")) { out.write("$scope="); out.write(scope); } else { out.write(line); } out.newLine(); } FileUtils.copyFile(tempFile, file); setConfigFileLastModified(file); dirty = true; } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } } }
From source file:de.unisb.cs.st.javalanche.mutation.results.MutationCoverageFile.java
public static void copyCoverageData(long srcId, long destId) { File src = new File(COVERAGE_DIR, "" + srcId); File dest = new File(COVERAGE_DIR, "" + destId); try {//from w ww . j ava 2s . co m FileUtils.copyFile(src, dest); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:de.uzk.hki.da.grid.IrodsGridFacadeBase.java
/** * Prepare replication./* w w w . j a v a 2 s . c o m*/ * * @param file the file * @param relative_address_dest the relative_address_dest * @return true, if successful * @throws IOException Signals that an I/O exception has occurred. */ protected boolean PrepareReplication(File file, String relative_address_dest, StoragePolicy sp) throws IOException { if (sp.getGridCacheAreaRootPath() == null) throw new IOException("gridCacheAreaRootPath is not set"); if (irodsSystemConnector.getDefaultStorage() == null) logger.error("Default Storage for node named " + sp.getNodeName() + " must be set!"); if (irodsSystemConnector.getZone() == null) throw new IOException("MyZone is not set"); if (!file.exists()) throw new IOException("Not an existing File to put: " + file); String address_dest = relative_address_dest; if (!relative_address_dest.startsWith("/")) address_dest = "/" + relative_address_dest; String targetPhysically = sp.getGridCacheAreaRootPath() + "/" + WorkArea.AIP + address_dest; String targetAbsoluteLogicalPath = "/" + irodsSystemConnector.getZone() + "/" + WorkArea.AIP + address_dest; File gridfile = new File(targetPhysically); if (gridfile.exists()) { if (!replicatedOnlyToCache(targetAbsoluteLogicalPath)) throw new java.io.IOException("Grid File " + gridfile + " " + targetAbsoluteLogicalPath + " not exclusively or not only available on cache group devices!"); if (MD5Checksum.getMD5checksumForLocalFile(file) .equals(MD5Checksum.getMD5checksumForLocalFile(gridfile))) { logger.info("GridFile is valid and only available on cache devices"); return true; } else { logger.error("Leftovers or invalid file on the grid!"); irodsSystemConnector.removeFile(targetAbsoluteLogicalPath); if (gridfile.exists()) gridfile.delete(); } } try { new File(FilenameUtils.getFullPath(targetPhysically)).mkdir(); FileUtils.copyFile(file, gridfile); } catch (IOException e) { logger.error( "Error while creating File or directory physically on the GridCachePath, target file may already exist " + e.getMessage()); return false; } if (!MD5Checksum.getMD5checksumForLocalFile(file) .equals(MD5Checksum.getMD5checksumForLocalFile(gridfile))) { logger.error(" put of " + file + " failed"); return false; } return true; }
From source file:com.turn.ttorrent.client.TorrentByteStorage.java
/** Move the partial file to its final location. * * <p>// ww w . j av a 2 s . c om * This method needs to make sure reads can still happen seemlessly during * the operation. The partial is first flushed to the storage device before * being copied to its target location. The {@link FileChannel} is then * switched to this new file before the partial is removed. * </p> */ public synchronized void complete() throws IOException { this.channel.force(true); // Nothing more to do if we're already on the target file. if (this.current.equals(this.target)) { return; } FileUtils.deleteQuietly(this.target); FileUtils.copyFile(this.current, this.target); logger.debug("Re-opening torrent byte storage at " + this.target.getAbsolutePath() + "."); RandomAccessFile raf = new RandomAccessFile(this.target, "rw"); raf.setLength(this.size); this.channel = raf.getChannel(); this.raf.close(); this.raf = raf; this.current = this.target; FileUtils.deleteQuietly(this.partial); }
From source file:at.medevit.elexis.inbox.model.impl.InboxElementService.java
@Override public void createInboxElement(Patient patient, Kontakt mandant, String file, boolean copyFile) { String path = file;/*from www. j a va 2 s . c o m*/ if (path != null) { File src = new File(path); if (src.exists()) { if (copyFile) { try { StringBuilder pathBuilder = new StringBuilder(); pathBuilder.append("inbox"); pathBuilder.append(File.separator); pathBuilder.append(patient.getPatCode()); pathBuilder.append("_"); pathBuilder.append(System.currentTimeMillis()); pathBuilder.append("_"); pathBuilder.append(src.getName()); File dest = new File(CoreHub.getWritableUserDir(), pathBuilder.toString()); FileUtils.copyFile(src, dest); path = dest.getAbsolutePath(); } catch (IOException e) { LoggerFactory.getLogger(InboxElementService.class).error("file copy error", e); return; } } InboxElement element = new InboxElement(patient, mandant, InboxElementType.FILE.getPrefix() + path); fireUpdate(element); } } }
From source file:com.github.blindpirate.gogradle.util.IOUtils.java
public static void copyFile(File src, File dest) { try {/* w w w .ja v a 2s. c om*/ FileUtils.copyFile(src, dest); } catch (IOException e) { throw new UncheckedIOException(e); } }