List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:de.tarent.maven.plugins.pkg.Utils.java
/** * Copies the Artifacts contained in the set to the folder denoted by * <code>dst</code> and returns the amount of bytes copied. * //www .ja v a2 s. c o m * <p> * If an artifact is a zip archive it is unzipped in this folder. * </p> * * @param l * @param artifacts * @param dst * @return * @throws MojoExecutionException */ public static long copyArtifacts(Log l, Set<Artifact> artifacts, File dst) throws MojoExecutionException { long byteAmount = 0; if (artifacts.size() == 0) { l.info("no artifact to copy."); return byteAmount; } l.info("copying " + artifacts.size() + " dependency artifacts."); l.info("destination: " + dst.toString()); try { Iterator<Artifact> ite = artifacts.iterator(); while (ite.hasNext()) { Artifact a = (Artifact) ite.next(); l.info("copying artifact: " + a); File f = a.getFile(); if (f != null) { l.debug("from file: " + f); if (a.getType().equals("zip")) { // Assume that this is a ZIP file with native libraries // inside. // TODO: Determine size of all entries and add this // to the byteAmount. unpack(a.getFile(), dst); } else { FileUtils.copyFileToDirectory(f, dst); byteAmount += (long) f.length(); } } else { throw new MojoExecutionException( "Unable to copy Artifact " + a + " because it is not locally available."); } } } catch (IOException ioe) { throw new MojoExecutionException("IOException while copying dependency artifacts.", ioe); } return byteAmount; }
From source file:com.virtualparadigm.packman.processor.JPackageManagerBU.java
private static void archivePackage(Package installPackage, File packageManagerDataDir) { // create "archive" dir if it doesnt exist // create package archive dir (<package name>_v_<package version>) // copy contents of package metadata, autorun and patch file to archive dir try {/* w w w. ja v a 2s . com*/ File archiveDir = new File(packageManagerDataDir.getAbsolutePath() + "/" + ARCHIVE_DIR_NAME); File archivePackageDir = new File(archiveDir.getAbsolutePath() + "/" + installPackage.getName() + "_v_" + installPackage.getVersion()); // if(!archivePackageDir.exists()) // { // archivePackageDir.mkdirs(); // } File archivePackageInstallDir = new File( archivePackageDir.getAbsolutePath() + "/" + JPackageManagerBU.INSTALL_DIR_NAME); if (!archivePackageInstallDir.exists()) { archivePackageInstallDir.mkdirs(); } File archivePackageUninstallDir = new File( archivePackageDir.getAbsolutePath() + "/" + JPackageManagerBU.UNINSTALL_DIR_NAME); if (!archivePackageUninstallDir.exists()) { archivePackageUninstallDir.mkdirs(); } // metadata archive dir FileUtils.copyDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerBU.METADATA_DIR_NAME), new File(archivePackageDir.getAbsolutePath() + "/" + JPackageManagerBU.METADATA_DIR_NAME)); // install archive dir FileUtils.copyDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerBU.AUTORUN_DIR_NAME + "/" + JPackageManagerBU.INSTALL_DIR_NAME), new File( archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerBU.AUTORUN_DIR_NAME)); FileUtils.copyFileToDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerBU.PATCH_DIR_NAME + "/" + JPackageManagerBU.PATCH_FILE_NAME), new File(archivePackageInstallDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_DIR_NAME)); // uninstall archive dir FileUtils.copyDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerBU.AUTORUN_DIR_NAME + "/" + JPackageManagerBU.UNINSTALL_DIR_NAME), new File(archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManagerBU.AUTORUN_DIR_NAME)); FileUtils.copyFileToDirectory( new File(packageManagerDataDir.getAbsolutePath() + "/" + TEMP_INSTALL_DIR_NAME + "/" + JPackageManagerBU.PATCH_DIR_NAME + "/" + JPackageManagerBU.PATCH_FILE_NAME), new File( archivePackageUninstallDir.getAbsolutePath() + "/" + JPackageManagerBU.PATCH_DIR_NAME)); } catch (Exception e) { logger.error("", e); // e.printStackTrace(); } }
From source file:es.bsc.servicess.ide.PackagingUtils.java
/** Copy a folder class of classes to the class folder of a element package * @param dir location of the folder which contains the classes * @param classesFolder Element package of the class folder *//*w w w . j av a 2 s. com*/ private static void copyClassDirectory(File dir, File classesFolder) { File[] files = dir.listFiles(); for (File f : files) { if (f.isDirectory()) { try { File destFile = new File(classesFolder.getAbsolutePath() + File.separator + f.getName()); if (!destFile.exists() || !destFile.isDirectory()) { destFile.mkdir(); } FileUtils.copyDirectory(f, destFile); log.debug("File " + f.getAbsolutePath() + "has been copied to " + classesFolder.getAbsolutePath()); } catch (IOException e) { log.error("File " + f.getAbsolutePath() + "could not be copied to " + classesFolder.getAbsolutePath(), e); e.printStackTrace(); } } else { try { FileUtils.copyFileToDirectory(f, classesFolder); log.debug("File " + f.getAbsolutePath() + "has been copied to " + classesFolder.getAbsolutePath()); } catch (IOException e) { log.error("File " + f.getAbsolutePath() + "could not be copied to " + classesFolder.getAbsolutePath(), e); e.printStackTrace(); } } } }
From source file:com.twinsoft.convertigo.engine.migration.Migration7_0_0.java
private static void copyXsdOfProject(String projectName, File destDir) throws IOException { File srcDir = new File(Engine.PROJECTS_PATH + "/" + projectName); if (srcDir.exists()) { Collection<File> xsdFiles = GenericUtils .cast(FileUtils.listFiles(srcDir, new String[] { "xsd" }, false)); for (File file : xsdFiles) { FileUtils.copyFileToDirectory(file, destDir); }/*from ww w . jav a2s .c om*/ } }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalSpriteAnimationsIntoProject(final ArrayList<File> files, ProgressHandler progressHandler) { if (files.size() == 0) { return;//from w ww . ja va 2 s .c om } handler = progressHandler; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { String newAnimName = null; String rawFileName = files.get(0).getName(); String fileExtension = FilenameUtils.getExtension(rawFileName); if (fileExtension.equals("png")) { Settings settings = new Settings(); settings.square = true; settings.flattenPaths = true; TexturePacker texturePacker = new TexturePacker(settings); FileHandle pngsDir = new FileHandle(files.get(0).getParentFile().getAbsolutePath()); for (FileHandle entry : pngsDir.list(new PngFilenameFilter())) { texturePacker.addImage(entry.file()); } String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName); String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", ""); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame; File targetDir = new File(targetPath); if (targetDir.exists()) { try { FileUtils.deleteDirectory(targetDir); } catch (IOException e) { e.printStackTrace(); } } texturePacker.pack(targetDir, fileNameWithoutFrame); newAnimName = fileNameWithoutFrame; } else { for (File file : files) { try { ArrayList<File> imgs = getAtlasPages(file); String fileNameWithoutExt = FilenameUtils.removeExtension(file.getName()); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt; File targetDir = new File(targetPath); if (targetDir.exists()) { FileUtils.deleteDirectory(targetDir); } for (File img : imgs) { FileUtils.copyFileToDirectory(img, targetDir); } FileUtils.copyFileToDirectory(file, targetDir); newAnimName = fileNameWithoutExt; } catch (IOException e) { e.printStackTrace(); } } } if (newAnimName != null) { resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, currentProjectInfoVO); } } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:de.uzk.hki.da.sb.Cli.java
/** * Copies the files listed in a SIP list to a single directory * // w w w . j a va2 s .c o m * @param fileListFile The SIP list file * @return The path to the directory containing the files */ private String copySipListContentToFolder(File sipListFile) { CliProgressManager progressManager = new CliProgressManager(); String tempFolderName = getTempFolderName(); XMLReader xmlReader = null; SAXParserFactory spf = SAXParserFactory.newInstance(); try { xmlReader = spf.newSAXParser().getXMLReader(); } catch (Exception e) { logger.log("ERROR: Failed to create SAX parser", e); System.out.println("Fehler beim Einlesen der SIP-Liste: SAX-Parser konnte nicht erstellt werden."); return ""; } xmlReader.setErrorHandler(new ErrorHandler() { @Override public void error(SAXParseException e) throws SAXException { throw new SAXException("Beim Einlesen der SIP-Liste ist ein Fehler aufgetreten.", e); } @Override public void fatalError(SAXParseException e) throws SAXException { throw new SAXException("Beim Einlesen der SIP-Liste ist ein schwerer Fehler aufgetreten.", e); } @Override public void warning(SAXParseException e) throws SAXException { logger.log("WARNING: Warning while parsing siplist", e); System.out.println("\nWarnung:\n" + e.getMessage()); } }); InputStream inputStream; try { inputStream = new FileInputStream(sipListFile); Reader reader = new InputStreamReader(inputStream, "UTF-8"); Builder parser = new Builder(xmlReader); Document doc = parser.build(reader); reader.close(); Element root = doc.getRootElement(); Elements sipElements = root.getChildElements("sip"); long files = 0; for (int i = 0; i < sipElements.size(); i++) { Elements fileElements = sipElements.get(i).getChildElements("file"); if (fileElements != null) files += fileElements.size(); } progressManager.setTotalSize(files); for (int i = 0; i < sipElements.size(); i++) { Element sipElement = sipElements.get(i); String sipName = sipElement.getAttributeValue("name"); File tempDirectory = new File(tempFolderName + File.separator + sipName); if (tempDirectory.exists()) { FileUtils.deleteQuietly(new File(tempFolderName)); System.out.println("\nDie SIP-Liste enthlt mehrere SIPs mit dem Namen " + sipName + ". " + "Bitte vergeben Sie fr jedes SIP einen eigenen Namen."); return ""; } tempDirectory.mkdirs(); Elements fileElements = sipElement.getChildElements("file"); for (int j = 0; j < fileElements.size(); j++) { Element fileElement = fileElements.get(j); String filepath = fileElement.getValue(); File file = new File(filepath); if (!file.exists()) { logger.log("ERROR: File " + file.getAbsolutePath() + " is referenced in siplist, " + "but does not exist"); System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath() + " existiert nicht."); FileUtils.deleteQuietly(new File(tempFolderName)); return ""; } try { if (file.isDirectory()) FileUtils.copyDirectoryToDirectory(file, tempDirectory); else FileUtils.copyFileToDirectory(file, tempDirectory); progressManager.copyFilesFromListProgress(); } catch (IOException e) { logger.log("ERROR: Failed to copy file " + file.getAbsolutePath() + " to folder " + tempDirectory.getAbsolutePath(), e); System.out.println("\nDie in der SIP-Liste angegebene Datei " + file.getAbsolutePath() + " konnte nicht kopiert werden."); FileUtils.deleteQuietly(new File(tempFolderName)); return ""; } } } } catch (Exception e) { logger.log("ERROR: Failed to read siplist " + sipListFile.getAbsolutePath(), e); System.out.println("\nBeim Lesen der SIP-Liste ist ein Fehler aufgetreten. "); return ""; } return (new File(tempFolderName).getAbsolutePath()); }
From source file:com.daphne.es.maintain.editor.web.controller.OnlineEditorController.java
@RequestMapping("copy") public String copy(@RequestParam(value = "descPath") String descPath, @RequestParam(value = "paths") String[] paths, @RequestParam(value = "conflict") String conflict, RedirectAttributes redirectAttributes) throws IOException { String rootPath = sc.getRealPath(ROOT_DIR); descPath = URLDecoder.decode(descPath, Constants.ENCODING); for (int i = 0, l = paths.length; i < l; i++) { String path = paths[i];//from ww w.ja v a 2s .com path = URLDecoder.decode(path, Constants.ENCODING); paths[i] = (rootPath + File.separator + path).replace("\\", "/"); } try { File descPathFile = new File(rootPath + File.separator + descPath); for (String path : paths) { File sourceFile = new File(path); File descFile = new File(descPathFile, sourceFile.getName()); if (descFile.exists() && "ignore".equals(conflict)) { continue; } FileUtils.deleteQuietly(descFile); if (sourceFile.isDirectory()) { FileUtils.copyDirectoryToDirectory(sourceFile, descPathFile); } else { FileUtils.copyFileToDirectory(sourceFile, descPathFile); } } redirectAttributes.addFlashAttribute(Constants.MESSAGE, "???"); } catch (Exception e) { redirectAttributes.addFlashAttribute(Constants.ERROR, e.getMessage()); } redirectAttributes.addAttribute("path", URLEncoder.encode(descPath, Constants.ENCODING)); return redirectToUrl(viewName("list")); }
From source file:de.uzk.hki.da.cli.Cli.java
/** * Copies the files listed in a file list to a single directory * /*from w w w. j a v a 2s. c om*/ * @param fileListFile The file list file * @return The path to the directory containing the files */ private String copySipContentToFolder(File fileListFile) { CliProgressManager progressManager = new CliProgressManager(); String tempFolderName = getTempFolderName(); String fileList = ""; try { fileList = StringUtilities.readFile(fileListFile); } catch (Exception e) { logger.error("Failed to read file " + fileListFile.getAbsolutePath(), e); System.out.println("Die Datei " + fileListFile.getAbsolutePath() + " konnte nicht gelesen werden."); return ""; } fileList = fileList.replace("\r", ""); if (!fileList.endsWith("\n")) fileList += "\n"; long files = 0; for (int i = 0; i < fileList.length(); i++) { if (fileList.charAt(i) == '\n') files++; } progressManager.setTotalSize(files); File tempDirectory = new File(tempFolderName + File.separator + sipFactory.getName()); tempDirectory.mkdirs(); while (true) { int index = fileList.indexOf('\n'); if (index >= 0) { String filepath = fileList.substring(0, index); fileList = fileList.substring(index + 1); File file = new File(filepath); if (!file.exists()) { logger.error("File " + file.getAbsolutePath() + " is referenced in filelist, " + "but does not exist"); System.out.println("\nDie in der Dateiliste angegebene Datei " + file.getAbsolutePath() + " existiert nicht."); FolderUtils.deleteQuietlySafe(tempDirectory); return ""; } try { if (file.isDirectory()) FileUtils.copyDirectoryToDirectory(file, tempDirectory); else FileUtils.copyFileToDirectory(file, tempDirectory); progressManager.copyFilesFromListProgress(); } catch (IOException e) { logger.error("Failed to copy file " + file.getAbsolutePath() + " to folder " + tempDirectory.getAbsolutePath(), e); System.out.println("\nDie in der Dateiliste angegebene Datei " + file.getAbsolutePath() + " konnte nicht kopiert werden."); FolderUtils.deleteQuietlySafe(tempDirectory); return ""; } } else break; } return (tempDirectory.getAbsolutePath()); }
From source file:it.geosolutions.geobatch.unredd.script.publish.PublishingAction.java
/************ * copy the tiff of source mosaic to the target mosaic directory * dissemination path/*w w w . ja v a 2 s . co m*/ * @throws IOException */ private void copyRaster(String srcPath, String dstPath, String layer, String year, String month, String day) throws IOException { String filename = NameUtils.buildTifFileName(layer, year, month, day); File srcFile = new File(srcPath, filename); File dstDir = new File(dstPath); FileUtils.copyFileToDirectory(srcFile, dstDir); // todo: copy also ancillary files if any (external OV, ...) }
From source file:com.taobao.android.tools.TPatchTool.java
/** * resource changes in main bundle/*from w w w.j av a 2s . c om*/ * * @param newApkUnzipFolder * @param baseApkUnzipFolder * @param patchTmpDir * @param retainFiles * @throws IOException */ public void copyMainBundleResources(final File newApkUnzipFolder, final File baseApkUnzipFolder, File patchTmpDir, Collection<File> retainFiles) throws IOException { boolean resoureModified = false; for (File retainFile : retainFiles) { String relativePath = PathUtils.toRelative(newApkUnzipFolder, retainFile.getAbsolutePath()); File baseFile = new File(baseApkUnzipFolder, relativePath); if (isBundleFile(retainFile)) { } else if (isFileModify(retainFile, baseFile)) { resoureModified = true; File destFile = new File(patchTmpDir, relativePath); FileUtils.copyFile(retainFile, destFile); } } if (resoureModified) { File AndroidMenifestFile = new File(newApkUnzipFolder, ANDROID_MANIFEST); FileUtils.copyFileToDirectory(AndroidMenifestFile, patchTmpDir); } }