List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:ie.programmer.catcher.browser.AsyncTasks.AsyncCopyTask.java
@Override protected Boolean doInBackground(String... params) { if (mCopyInterface != null) mCopyInterface.preCopyStartAsync(); if (mSourceFile == null || mDestDirFile == null) { if (mCopyInterface != null) mCopyInterface.onCopyCompleteAsync(false); return false; }/*from w ww. j av a 2 s. co m*/ if (mSourceFile.isDirectory()) { try { FileUtils.copyDirectory(mSourceFile, mDestDirFile); } catch (Exception e) { if (mCopyInterface != null) mCopyInterface.onCopyCompleteAsync(false); return false; } } else { try { FileUtils.copyFile(mSourceFile, mDestDirFile); } catch (Exception e) { if (mCopyInterface != null) mCopyInterface.onCopyCompleteAsync(false); return false; } } if (mCopyInterface != null) mCopyInterface.onCopyCompleteAsync(true); return true; }
From source file:com.sonarsource.cobol.ebcdic.FileConverterTest.java
@Test public void shouldConvertEbcdicFile() throws Exception { converter = new FileConverter(FileConverter.CP1047, Charset.forName("UTF-8")); converter.setFixedLength(80);// ww w . j a v a2 s. c o m File ebcdicFile = new File(FileConverterTest.class.getResource("/EBCDIC.txt").toURI()); File expectedOutputFile = new File(FileConverterTest.class.getResource("/ASCII.txt").toURI()); File workingFile = new File("target/converter/cobol.txt"); FileUtils.copyFile(ebcdicFile, workingFile); converter.convert(workingFile, workingFile); assertThat(FileUtils.contentEquals(workingFile, expectedOutputFile)).isTrue(); }
From source file:com.cloud.ops.resource.ResourcePackageController.java
@RequestMapping(value = "/{id}/download", method = RequestMethod.GET) public void download(HttpServletResponse response, @PathVariable("id") String id) { ResourcePackage resourcePackage = service.get(id); try {/*w w w. j a v a 2s . c o m*/ response.reset(); response.setContentType("licenseInfo/octet-stream;charset=UTF-8"); File file = new File(resourcePackage.getWarPath()); response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(file.getName(), "UTF-8")); FileUtils.copyFile(file, response.getOutputStream()); } catch (IOException e) { LOGGER.error("file download error: ", e); } }
From source file:com.ecop.CriminalAdd.java
@Override public String execute() throws Exception { String path = request.getSession().getServletContext().getRealPath("/images"); Session s = HibernateUtil.getSessionFactory().openSession(); File f = new File(path, photoFileName); PoliceStation ps = (PoliceStation) s.get(PoliceStation.class, pstation_id); FileUtils.copyFile(photo, f); FileInputStream fis = new FileInputStream(f); byte[] bs = new byte[(int) f.length()]; fis.read(bs);//from w ww . j a va 2 s .co m fis.close(); // Session s=NewHibernateUtil.getSessionFactory().openSession(); Criminal c = new Criminal(); c.setCriminalId(criminal_id); c.setName(name); c.setGender(gender); c.setHeight(height); c.setWeight(weight); c.setPoliceStation(ps); c.setCrimelevel(crimelevel); c.setStatus(status); c.setPhoto(bs); s.save(c); s.beginTransaction().commit(); s.close(); return SUCCESS; }
From source file:com.nms.mediastore.servlet.VideoServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w ww .j a v a 2s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String uuid = request.getParameter("id"); if (Validator.isNotNull(uuid)) { VideoLink link; FileEntry videoFile = null; try { if (uuid.equals(DEFAULT_ID)) { Video video = videoService.getDefault(); videoFile = video.getVideoFile(); } else { link = linkService.findByUUID(uuid); videoFile = link.getVideo().getVideoFile(); } } catch (Exception e) { LOG.log(Level.WARNING, "Video link not found or expirated uuid = {0} and ERROR: {1}", new Object[] { uuid, e.toString() }); } if (videoFile != null && Validator.isNotNull(videoFile.getUri())) { File in = new File(AppConfig.getFileStorePath() + videoFile.getUri()); if (in.exists()) { response.setContentType(videoFile.getContentType()); response.setContentLengthLong(videoFile.getSize()); response.setHeader("Content-Disposition", "attachment;filename=\"" + videoFile.getName() + "\""); try (OutputStream out = response.getOutputStream()) { FileUtils.copyFile(in, out); } } else { LOG.log(Level.WARNING, "Video file not found = {0}", new Object[] { AppConfig.getFileStorePath() + videoFile.getUri() }); } } else { LOG.log(Level.WARNING, "Video file not found = {0}", new Object[] { uuid }); } } }
From source file:net.erdfelt.android.sdkfido.project.ant.AntOutputProject.java
@Override public void init() throws FetchException { baseDir.ensureExists();// w w w. j a va2 s . co m sourceDir.ensureExists(); try { this.copier = new SourceCopier(baseDir); } catch (IOException e) { throw new FetchException(e.getMessage(), e); } if (androidStub != null) { try { FileUtils.copyFile(androidStub, baseDir.getFile("android-stub.jar")); copier.setNarrowSearchTo(new JarListing(androidStub)); } catch (IOException e) { throw new FetchException( "Unable to narrow search tree by using listing of java files withou android stub jar file: " + androidStub, e); } } }
From source file:net.chris54721.infinitycubed.data.Asset.java
public boolean copyFromVanilla() { try {/* ww w . ja v a2 s . c o m*/ if (this.isLocalValid()) return true; else { File mcAssetsDir = new File(Utils.getAppdataPath() + File.separator + ".minecraft", "assets"); if (!mcAssetsDir.isDirectory()) return false; File mcAssetsFile = new File(mcAssetsDir + File.separator + "objects" + File.separator + getTarget().getParentFile().getName(), getTarget().getName()); if (!mcAssetsFile.isFile() || mcAssetsFile.length() != getFileSize()) return false; FileUtils.copyFile(mcAssetsFile, getTarget()); return this.copyToLegacy(); } } catch (IOException e) { LogHelper.error("Failed copying asset " + name + " from vanilla", e); return false; } }
From source file:com.blackducksoftware.integration.hub.detect.workflow.diagnostic.RelevantFileTracker.java
private boolean registerRelevantFile(final File file, final String directoryName) { try {// w w w. ja v a 2 s .com if (file == null) { return false; } if (isChildOfTrackedFolder(file)) { logger.debug("Asked to track file '" + file.getPath() + "' but it is already being tracked."); return false; } if (file.isFile()) { final File dest = findNextAvailableRelevant(directoryName, file.getName()); FileUtils.copyFile(file, dest); } else if (file.isDirectory()) { final File dest = findNextAvailableRelevant(directoryName, file.getName()); FileUtils.copyDirectory(file, dest); } return true; } catch (final Exception e) { logger.trace("Failed to copy file to relevant directory:" + file.toString()); return false; } }
From source file:com.ecop.CriminalUpdate.java
@Override public String execute() throws Exception { String path = request.getSession().getServletContext().getRealPath("/images"); Session s = HibernateUtil.getSessionFactory().openSession(); File f = new File(path, photoFileName); PoliceStation ps = (PoliceStation) s.get(PoliceStation.class, pstation_id); FileUtils.copyFile(photo, f); FileInputStream fis = new FileInputStream(f); byte[] bs = new byte[(int) f.length()]; fis.read(bs);//from ww w .j av a2 s. co m fis.close(); // Session s=NewHibernateUtil.getSessionFactory().openSession(); Criminal c = (Criminal) s.get(Criminal.class, criminal_id); c.setCriminalId(criminal_id); c.setName(name); c.setGender(gender); c.setHeight(height); c.setWeight(weight); c.setPoliceStation(ps); c.setCrimelevel(crimelevel); c.setStatus(status); c.setPhoto(bs); s.update(c); s.save(c); s.beginTransaction().commit(); s.close(); return SUCCESS; }
From source file:action.ProductAction.java
public String create() throws Exception { String filePath = request.getSession().getServletContext().getRealPath("/") .concat("public\\upload\\product"); Random rand = new Random(); int n = rand.nextInt(99999) + 1; File fileToCreate = new File(filePath, n + "_" + this.getUploadFileName()); FileUtils.copyFile(this.getUpload(), fileToCreate); product.setImage(n + "_" + this.getUploadFileName()); boolean insert = controller.insert(this.getProduct()); if (insert == true) { this.addActionMessage("Create product success!"); list = controller.getAll();/*from w w w .j a v a2 s . co m*/ ServletActionContext.getRequest().getSession().setAttribute("list", list); return SUCCESS; } else { cList = cController.getAll(); dList = dController.getAll(); this.addActionError("Have some error, please try again!"); return INPUT; } }