List of usage examples for org.apache.commons.io FileUtils copyDirectory
public static void copyDirectory(File srcDir, File destDir) throws IOException
From source file:io.siddhi.extension.io.file.FileSinkTestCase.java
@BeforeMethod public void doBeforeMethod() { count.set(0);//from w w w . j a v a 2 s .c om try { FileUtils.copyDirectory(sourceRoot, fileToAppend); } catch (IOException e) { throw new TestException("Failed to copy files from " + sourceRoot.getAbsolutePath() + " to " + fileToAppend.getAbsolutePath() + " which are required for tests. Hence aborting tests.", e); } }
From source file:io.siddhi.extension.io.file.FileSourceBinaryModeTestCase.java
@BeforeMethod public void doBeforeMethod() { count.set(0);// www .jav a 2 s. c o m try { FileUtils.copyDirectory(sourceRoot, newRoot); movedFiles = new File(moveAfterProcessDir); FileUtils.forceMkdir(movedFiles); } catch (IOException e) { throw new TestException("Failed to copy files from " + sourceRoot.getAbsolutePath() + " to " + newRoot.getAbsolutePath() + " which are required for tests. Hence aborting tests.", e); } }
From source file:com.github.mojos.distribute.PackageMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (version != null) { packageVersion = version;/*from w ww . java2 s . c o m*/ } //Copy sourceDirectory final File sourceDirectoryFile = new File(sourceDirectory); final File buildDirectory = Paths.get(project.getBuild().getDirectory(), "py").toFile(); try { FileUtils.copyDirectory(sourceDirectoryFile, buildDirectory); } catch (IOException e) { throw new MojoExecutionException("Failed to copy source", e); } final File setup = Paths.get(buildDirectory.getPath(), "setup.py").toFile(); final boolean setupProvided = setup.exists(); final File setupTemplate = setupProvided ? setup : Paths.get(buildDirectory.getPath(), "setup-template.py").toFile(); try { if (!setupProvided) { //update VERSION to latest version List<String> lines = new ArrayList<String>(); final InputStream inputStream = new BufferedInputStream(new FileInputStream(setupTemplate)); try { lines.addAll(IOUtils.readLines(inputStream)); } finally { inputStream.close(); } int index = 0; for (String line : lines) { line = line.replace(VERSION, packageVersion); line = line.replace(PROJECT_NAME, packageName); lines.set(index, line); index++; } final OutputStream outputStream = new FileOutputStream(setup); try { IOUtils.writeLines(lines, "\n", outputStream); } finally { outputStream.flush(); outputStream.close(); } } //execute setup script ProcessBuilder processBuilder = new ProcessBuilder(pythonExecutable, setup.getCanonicalPath(), "bdist_egg"); processBuilder.directory(buildDirectory); processBuilder.redirectErrorStream(true); Process pr = processBuilder.start(); int exitCode = pr.waitFor(); BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream())); String line = ""; while ((line = buf.readLine()) != null) { getLog().info(line); } if (exitCode != 0) { throw new MojoExecutionException("python setup.py returned error code " + exitCode); } } catch (FileNotFoundException e) { throw new MojoExecutionException("Unable to find " + setup.getPath(), e); } catch (IOException e) { throw new MojoExecutionException("Unable to read " + setup.getPath(), e); } catch (InterruptedException e) { throw new MojoExecutionException("Unable to execute python " + setup.getPath(), e); } }
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; }// w w w .j ava 2 s .c om 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.orange.ocara.model.export.AuditExportService.java
private void exportToDocx(Audit audit) { final AssetManager assetManager = getAssets(); String locale = Locale.getDefault().getLanguage(); String folder;/* www .ja v a2 s . c o m*/ if (locale.equals("en")) { folder = "export/"; } else { folder = "export-" + locale + "/"; } Timber.v("locale " + locale + " folder " + folder); final File exportDir = new File(getCacheDir(), folder); final File templateDir = new File(exportDir, "docx/template"); final File workingDir = new File(exportDir, "docx/working"); final File exportFile = new File(exportDir, String.format("docx/audit_%d.docx", audit.getId())); try { // Create and cleanup Working and Template directories createAndCleanup(workingDir); createAndCleanup(templateDir); FileUtils.deleteQuietly(exportFile); exportFile.createNewFile(); AssetsHelper.copyAsset(assetManager, folder + "docx", templateDir); FileUtils.copyDirectory(templateDir, workingDir); DocxExporter auditExporter = new AuditDocxExporter(audit, templateDir); DocxWriter writer = DocxWriter.builder().workingDirectory(workingDir).exportFile(exportFile) .exporter(auditExporter).build(); writer.export(); Intent i = new Intent(EXPORT_SUCCESS); i.putExtra("path", exportFile.getPath()); LocalBroadcastManager.getInstance(this).sendBroadcast(i); } catch (Exception e) { Timber.e(e, "Failed to copy assets"); Intent i = new Intent(EXPORT_FAILED); LocalBroadcastManager.getInstance(this).sendBroadcast(i); } finally { FileUtils.deleteQuietly(templateDir); FileUtils.deleteQuietly(workingDir); } }
From source file:au.org.ala.delta.confor.ToIntTest.java
@Test public void zztestPoneriniToInt() throws Exception { File tointDirectory = urlToFile("/dataset/"); File dest = new File(System.getProperty("java.io.tmpdir")); FileUtils.copyDirectory(tointDirectory, dest); String tointFilePath = FilenameUtils.concat(dest.getAbsolutePath(), "ponerini/toint"); CONFOR.main(new String[] { tointFilePath }); File ichars = new File(FilenameUtils.concat(dest.getAbsolutePath(), "ponerini/ichars")); File iitems = new File(FilenameUtils.concat(dest.getAbsolutePath(), "ponerini/iitems")); IntkeyDataset dataSet = IntkeyDatasetFileReader.readDataSet(ichars, iitems); File expectedIChars = new File( FilenameUtils.concat(dest.getAbsolutePath(), "ponerini/expected_results/ichars")); File expectedIItems = new File( FilenameUtils.concat(dest.getAbsolutePath(), "ponerini/expected_results/iitems")); IntkeyDataset expectedDataSet = IntkeyDatasetFileReader.readDataSet(expectedIChars, expectedIItems); compare(dataSet, expectedDataSet);//from w w w .j av a2 s .c om }
From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.db.HibernateSearchDAOTest.java
private static void restoreSearchIndex() { File targetPath = new File(LUCENE_INDEX_PATH); FileUtilities.deleteRecursively(targetPath); targetPath.mkdirs();/* w w w . ja va 2 s . c o m*/ File srcPath = new File(LUCENE_INDEX_TEMPLATE_PATH); try { FileUtils.copyDirectory(srcPath, targetPath); new File(srcPath, FullTextIndexerRunnable.FULL_TEXT_INDEX_MARKER_FILENAME).createNewFile(); } catch (IOException ex) { throw new IOExceptionUnchecked(ex); } }
From source file:net.mindengine.blogix.BlogixMain.java
@SuppressWarnings("unused") private static void cmd_export(String[] args) throws IOException, URISyntaxException { String dest = "export"; if (args.length > 0) { dest = args[0];//from w w w.java 2 s . c o m } File destinationDir = new File(dest); if (!destinationDir.exists()) { destinationDir.mkdirs(); } BlogixExporter exporter = new BlogixExporter(destinationDir); info("Exporting all routes to \"" + dest + "\""); File publicDir = new File("public"); if (publicDir.exists()) { File publicExportDir = new File(destinationDir.getAbsolutePath() + File.separator + "public"); publicExportDir.mkdir(); FileUtils.copyDirectory(publicDir, publicExportDir); } exporter.exportAll(); }
From source file:com.psaravan.filebrowserview.lib.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 . ja v a2s . c om*/ 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:io.github.thefishlive.updater.Updater.java
public void run() { System.out.println("-------------------------"); System.out.println(gitDir.getAbsolutePath()); File updateFile = new File(basedir, "UPDATE"); Git git = null;/*www . j a va 2s.c o m*/ try { if (!gitDir.exists()) { git = Git.cloneRepository().setDirectory(basedir).setURI(GitUpdater.remote) .setProgressMonitor(buildProgressMonitor()).call(); System.out.println("Repository cloned"); } else { updateFile.createNewFile(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.setGitDir(gitDir).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); git = new Git(repo); PullResult result = git.pull().setProgressMonitor(buildProgressMonitor()).call(); if (!result.isSuccessful() || result.getMergeResult().getMergeStatus().equals(MergeStatus.MERGED)) { System.out.println("Update Failed"); FileUtils.deleteDirectory(basedir); basedir.mkdir(); System.out.println("Re-cloning repository"); git = Git.cloneRepository().setDirectory(basedir).setURI(GitUpdater.remote) .setProgressMonitor(buildProgressMonitor()).call(); System.out.println("Repository cloned"); } System.out.println("State: " + result.getMergeResult().getMergeStatus()); } File configdir = new File("config"); if (configdir.exists()) { FileUtils.copyDirectory(configdir, new File(basedir, "config")); } } catch (Exception e) { e.printStackTrace(); } finally { git.getRepository().close(); } updateFile.delete(); System.out.println("-------------------------"); }