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.cologneintelligence.fitgoodies.maven.FitIntegrationTestMojo.java
private void copyNonTestFiles(File sourceDir, File targetDir) throws MojoExecutionException { File[] files = sourceDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { File newTarget = new File(targetDir, file.getName()); //noinspection ResultOfMethodCallIgnored newTarget.mkdirs();//w ww.j a v a2 s. c o m copyNonTestFiles(file, newTarget); } else if (isNonTestFile(file.getName())) { try { FileUtils.copyFile(file, new File(targetDir, file.getName())); } catch (IOException e) { throw new MojoExecutionException("Could not copy file: " + file.getAbsolutePath(), e); } } } } }
From source file:net.sf.firemox.ui.MdbListener.java
/** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) *///from w w w . ja v a2 s . c o m public void actionPerformed(ActionEvent e) { if ("menu_options_tbs_more".equals(e.getActionCommand())) { // goto "more TBS" page try { WebBrowser.launchBrowser("http://sourceforge.net/project/showfiles.php?group_id=" + IdConst.PROJECT_ID + "&package_id=107882"); } catch (Exception e1) { JOptionPane.showOptionDialog(MagicUIComponents.magicForm, LanguageManager.getString("error") + " : " + e1.getMessage(), LanguageManager.getString("web-pb"), JOptionPane.OK_OPTION, JOptionPane.INFORMATION_MESSAGE, UIHelper.getIcon("wiz_update_error.gif"), null, null); } return; } if ("menu_options_tbs_update".equals(e.getActionCommand())) { // update the current TBS XmlConfiguration.main(new String[] { "-g", MToolKit.tbsName }); return; } if ("menu_options_tbs_rebuild".equals(e.getActionCommand())) { /* * rebuild completely the current TBS */ XmlConfiguration.main(new String[] { "-f", "-g", MToolKit.tbsName }); return; } // We change the TBS // Wait for confirmation if (JOptionPane.YES_OPTION == JOptionPane.showOptionDialog(MagicUIComponents.magicForm, LanguageManager.getString("warn-disconnect"), LanguageManager.getString("disconnect"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, UIHelper.getIcon("wiz_update.gif"), null, null)) { // Save the current settings before changing TBS Magic.saveSettings(); // Copy this settings file to the profile directory of this TBS final File propertyFile = MToolKit.getFile(IdConst.FILE_SETTINGS); try { FileUtils.copyFile(propertyFile, MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false)); // Delete the current settings file of old TBS propertyFile.delete(); // Load the one of the new TBS abstractMainForm.setMdb(e.getActionCommand()); Configuration.loadTemplateFile( MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false).getAbsolutePath()); // Copy the saved configuration of new TBS FileUtils.copyFile(MToolKit.getTbsFile(IdConst.FILE_SETTINGS_SAVED, false), propertyFile); Log.info("Successful TBS swith to " + MToolKit.tbsName); // Restart the game System.exit(IdConst.EXIT_CODE_RESTART); } catch (IOException e1) { e1.printStackTrace(); } } }
From source file:annis.administration.BinaryImportHelper.java
@Override public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { ps.setString(1, fileDestination.getName()); ps.setLong(2, this.corpusRef); ps.setString(3, this.mimeType); ps.setString(4, fileSource.getName()); ps.executeUpdate();/*www .j a va 2 s .c om*/ try { FileUtils.copyFile(fileSource, fileDestination); } catch (IOException ex) { log.error("Could not copy file " + fileSource.getPath(), ex); return false; } return true; }
From source file:com.sios.stc.coseng.test.Base.java
public void saveScreenshot(final WebDriver webDriver, final String name) throws IOException { final File scrFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE); // Now you can do whatever you need to do with it, for example copy // somewhere//from ww w.jav a 2s . co m FileUtils.copyFile(scrFile, new File(testReportDirectoryPath + File.separator + "screenshot-" + name + ".png")); }
From source file:com.alta189.chavabot.plugin.CommonPluginManager.java
public synchronized Plugin loadPlugin(File paramFile, boolean ignoresoftdepends) throws InvalidPluginException, InvalidDescriptionFileException, UnknownDependencyException { File update = null;/* w ww .j a v a2 s.c om*/ if (updateDir != null && updateDir.isDirectory()) { update = new File(updateDir, paramFile.getName()); if (update.exists() && update.isFile()) { try { FileUtils.copyFile(update, paramFile); } catch (IOException e) { chavamanager.getLogger().log(Level.SEVERE, new StringBuilder().append("Error copying file '").append(update.getPath()) .append("' to its new destination at '").append(paramFile.getPath()) .append("': ").append(e.getMessage()).toString(), e); } update.delete(); } } Set<Pattern> patterns = loaders.keySet(); Plugin result = null; for (Pattern pattern : patterns) { String name = paramFile.getName(); Matcher m = pattern.matcher(name); if (m.find()) { PluginLoader loader = loaders.get(pattern); result = loader.loadPlugin(paramFile, ignoresoftdepends); if (result != null) break; } } if (result != null) { plugins.add(result); names.put(result.getDescription().getName(), result); } return result; }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java
@Test public void testZipTwoFile() throws Exception { FileUtils.forceMkdir(new File("target/Z-testfiles/source")); FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/Z-testfiles/source/CP0-input.csv")); FileUtils.copyFile(new File("src/test/resources/testFiles/input.csv"), new File("target/Z-testfiles/source/CP1-input.csv")); String aTargetFilename = "target/Z1-input.zip"; ZipFilesTasklet aTasklet = new ZipFilesTasklet(); aTasklet.setSourceBaseDirectory(new FileSystemResource("target/Z-testfiles/source/")); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:target/Z-testfiles/source/*input*.csv"); aTasklet.setSourceFactory(aSourceFactory); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setExpression(aTargetFilename); aTasklet.setDestinationFactory(aDestinationFactory); assertFalse(new File(aTargetFilename).exists()); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(2)).incrementReadCount(); verify(aStepContribution, times(2)).incrementWriteCount(1); assertTrue(new File(aTargetFilename).exists()); ZipFile aZipFile = new ZipFile(new File(aTargetFilename)); Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries(); assertTrue(aEntries.hasMoreElements()); assertEquals("CP0-input.csv", aEntries.nextElement().getName()); assertTrue(aEntries.hasMoreElements()); assertEquals("CP1-input.csv", aEntries.nextElement().getName()); assertFalse(aEntries.hasMoreElements()); aZipFile.close();/*w w w . j ava2 s. co m*/ }
From source file:de.uzk.hki.da.cb.ScanActionTests.java
@Test public void testMigrationToConfirm() throws IOException { premisFile.delete();//from ww w.j a v a2 s. com FileUtils.copyFile(Path.makeFile(workAreaRootPath, "premis.xml_MIGRATION_CONFIRM"), premisFile); action.implementation(); assertEquals(C.QUESTION_MIGRATION_ALLOWED, j.getQuestion()); assertEquals(C.WORKFLOW_STATUS_WAIT___PROCESS_FOR_USER_DECISION_ACTION, action.getEndStatus()); }
From source file:com.us.action.file.KindUpLoad.java
@Override public String execute() throws Exception { if (gloabelError != null) { return text(getError(gloabelError.toString())); }/*w w w . ja v a 2 s . c o m*/ if (imgFile == null) { return text(getError(getI118("${upload.nofile}", getRequest()))); } String dirName = getRequest().getParameter("dir"); if (dirName == null) { dirName = "image"; } final String allowed = AppHelper.KIND_CONFIG.get(dirName).toString(); String fileExt = FilenameUtils.getExtension(imgFileFileName); if (!Arrays.<String>asList(allowed.split(",")).contains(fileExt)) { return text(getError(getI118("${upload.invaildFile}", getRequest(), imgFileFileName, allowed))); } Object savePath = AppHelper.KIND_CONFIG.get("savePath"); if (savePath == null) { return text(getError(getI118("${upload.noConfig}", getRequest(), "savePath"))); } // File uploadDir = FileHelper.getFile(AppHelper.APPSET.getFilePath(), savePath.toString()); if (!uploadDir.exists()) uploadDir.mkdirs(); if (uploadDir == null || !uploadDir.isDirectory()) { return text(getError(getI118("${upload.dirNotExist}", getRequest()))); } // ?? if (!uploadDir.canWrite()) { return text(getError(getI118("${upload.dirCantWrite}", getRequest()))); } Object type = AppHelper.KIND_CONFIG.get(dirName); if (type == null) { return text(getError(getI118("${upload.typeNoConfig}", getRequest(), "dirName"))); } // ?URL String saveUrl = AppHelper.APPSET.getWebPath() + savePath.toString(); if (!uploadDir.exists()) uploadDir.mkdirs(); String child = DateUtil.format(DateUtil.now(), "yyyyMM/dd/"); uploadDir = FileHelper.getFile(uploadDir, child); saveUrl += child; if (!uploadDir.exists()) { uploadDir.mkdirs(); } final long initSize = Long.parseLong(AppHelper.KIND_CONFIG.get("maxSize").toString()); if (imgFile.length() > initSize * 1024000) { return text(getError( getI118("${upload.tooMax}", getRequest(), imgFileFileName, imgFile.length(), initSize))); } String newFileName = RandomHelper.uu_id() + "." + fileExt; File uploadedFile = new File(uploadDir, newFileName); final long startTime = System.currentTimeMillis(); FileUtils.copyFile(imgFile, uploadedFile); log.info(String.format("?%s(ms)", (System.currentTimeMillis() - startTime))); return text(JSONHelper.obj2Json(KindResult .success(getI118("${upload.hasUpload}", getRequest(), imgFileFileName), saveUrl + newFileName))); }
From source file:com.mmj.app.biz.service.impl.FileServiceImpl.java
@Override public Result saveFileByPath(String filePath, IFileHandle... ihandle) { if (StringUtils.isEmpty(filePath)) { return Result.failed(); }/*from w w w.j a va2s .c o m*/ filePath = StringUtils.replace(filePath, STATIC_TMP_IMG, StringUtils.EMPTY); File file = new File(UPLOAD_TMP_PATH + filePath); if (file == null || file.isFile()) { try { String path = ihandle[0].parse(UPLOAD_BASE_PATH, filePath); FileUtils.copyFile(file, new File(path)); return Result.success(null, STATIC_BASE_IMG + path.replaceAll(UPLOAD_BASE_PATH, "")); } catch (Exception e) { logger.error(e.getMessage()); return Result.failed(); } } return Result.failed(); }
From source file:com.exalttech.trex.util.files.FileManager.java
/** * Export file//from w ww .jav a2 s . c o m * * @param windowTitle * @param fileName * @param fileContent * @param window * @param type * @throws IOException */ public static void exportFile(String windowTitle, String fileName, Object fileContent, Window window, FileType type) throws IOException { File savedFile = getSelectedFile(windowTitle, fileName, window, type, PreferencesManager.getInstance().getSaveLocation(), true); if (savedFile != null) { String filePath = savedFile.getAbsolutePath(); String pathToSave = !filePath.contains(type.getExtension()) ? filePath + type.getExtension() : filePath; File fileToSave = new File(pathToSave); if (!fileToSave.exists()) { fileToSave.createNewFile(); } if (fileContent instanceof String) { FileUtils.writeStringToFile(fileToSave, String.valueOf(fileContent)); } else { FileUtils.copyFile((File) fileContent, savedFile); } } }