Java Code Examples for org.apache.commons.io.FileUtils.copyDirectory()

The following are Jave code examples for showing how to use copyDirectory() of the org.apache.commons.io.FileUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Lernkartei_2017   File: MoveFile.java   View Source Code Vote up 6 votes
public MoveFile() {
		//checks the name from User
		String userName = System.getProperty("user.name");
		//Finds out where its saved
		URL location = MoveFile.class.getProtectionDomain().getCodeSource().getLocation();
		
		File source = new File(location.getPath() + "/pushing/jars");
		File dest = new File("C:/Users/" + userName +"/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup");
		
		try {
			//Copies source datas to destination.
		    FileUtils.copyDirectory(source, dest);
		}
		catch (IOException e) {
		    e.printStackTrace();
		}
}
 
Example 2
Project: atlas   File: FileCacheCenter.java   View Source Code Vote up 6 votes
public static void fetchFile(String type, String key, boolean folder, boolean remote, File dest) throws FileCacheException {

        if (!BUILD_CACHE_ENABLED){
            return;
        }

        File cacheFile = queryFile(type,key,folder,remote);

        if (null != cacheFile && cacheFile.exists()){

            try {
                if (cacheFile.isFile()) {
                    FileUtils.copyFile(cacheFile, dest);
                } else {
                    FileUtils.copyDirectory(cacheFile, dest);
                }
                logger.log(type + "." + key + " fech  file success  " + dest.getAbsolutePath());
            }catch (Throwable e){
                throw new FileCacheException(e.getMessage(),e);
            }

        }


    }
 
Example 3
Project: butterfly   File: CopyDirectory.java   View Source Code Vote up 6 votes
@Override
protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) {
    // TODO Validation must be done here!!! In case none has been set!
    File filesFrom = getAbsoluteFile(transformedAppFolder, transformationContext);
    File fileTo = getFileTo(transformedAppFolder, transformationContext);
    TOExecutionResult result = null;

    try {
        FileUtils.copyDirectory(filesFrom, fileTo);
        String details = String.format("Files from '%s' have been copied to '%s'", getRelativePath(transformedAppFolder, filesFrom), getRelativePath(transformedAppFolder, fileTo));
        result = TOExecutionResult.success(this, details);
    } catch (IOException e) {
        result = TOExecutionResult.error(this, e);
    }

    return result;
}
 
Example 4
Project: carnotzet   File: ResourcesManagerTest.java   View Source Code Vote up 6 votes
@Test
public void config_variant() throws IOException {
	// Given
	URL url = Thread.currentThread().getContextClassLoader().getResource("example_config_variant");
	File example = new File(url.getPath());
	Path resources = temp.newFolder().toPath();
	FileUtils.copyDirectory(example, resources.toFile());
	ResourcesManager manager = new ResourcesManager(resources, null);
	List<CarnotzetModule> modules = Arrays.asList(
			CarnotzetModule.builder().name("service2").serviceId("service2").build(),
			CarnotzetModule.builder().name("service1-variant").serviceId("service1").build()
	);

	// When
	manager.resolveResources(modules);

	// Then
	assertTrue(resources.resolve("resolved/service2/files/config.properties").toFile().exists());
	assertTrue(resources.resolve("resolved/service2/files/config2.properties").toFile().exists());
	assertTrue(resources.resolve("resolved/service1/files/config3.properties").toFile().exists());
	assertTrue(resources.resolve("resolved/service2/files/config4.properties").toFile().exists());

}
 
Example 5
Project: sc-generator   File: AbstractGeneratorMybatis.java   View Source Code Vote up 6 votes
protected void copyMybatisXml(String src, String dest) throws IOException {
    final List<File> oldXmlFile = new ArrayList<File>();
    FileUtils.copyDirectory(new File(src + packagePath.replace(".", "/") + "/dao"),
            new File(dest + "/" + packagePath.replace(".", "/") + "/dao"), new FileFilter() {
                public boolean accept(File pathname) {
                    int lastIndexOf = pathname.getName().lastIndexOf(".xml");
                    if (lastIndexOf != -1) {
                        oldXmlFile.add(pathname);
                    }
                    return lastIndexOf != -1;
                }
            });
    for (File file : oldXmlFile) {
        file.delete();
    }
}
 
Example 6
Project: convertigo-engine   File: MobilePlatform.java   View Source Code Vote up 6 votes
private void checkFolder() {
	File folder = getResourceFolder();
	File templateFolder = new File(Engine.TEMPLATES_PATH, "base/DisplayObjects/platforms/" + getClass().getSimpleName());

	try {
		if (!folder.exists()) {
			FileUtils.copyDirectory(templateFolder, folder);
		} else {
			File config = new File(folder, "config.xml");
			if (!config.exists()) {
				FileUtils.copyFile(new File(templateFolder, "config.xml"), config);
			}
			File res = new File(folder, "res");
			if (!res.exists()) {
				FileUtils.copyDirectory(new File(templateFolder, "res"), res);
			}
		}
	} catch (IOException e) {
		Engine.logBeans.warn("(MobilePlatform) The folder '" + folder.getAbsolutePath() + "' doesn't exist and cannot be created", e);
	}
}
 
Example 7
Project: OneClient   File: CurseZipInstaller.java   View Source Code Vote up 6 votes
private void installOverrides(File pack, File instance) {
	File overrideDir = new File(pack, manifest.overrides);
	File[] files = overrideDir.listFiles();
	if (files != null) {
		for (File file : files) {
			File output = new File(instance, file.toString().replace(overrideDir.toString(), ""));
			try {
				if (file.isDirectory())
					FileUtils.copyDirectory(file, output);
				else if (file.isFile())
					FileUtils.copyFile(file, output);
			} catch (IOException e) {
				OneClientLogging.error(e);
			}
		}
	}
}
 
Example 8
Project: Reer   File: GFileUtils.java   View Source Code Vote up 5 votes
public static void copyDirectory(File source, File destination) {
    try {
        FileUtils.copyDirectory(source, destination);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 9
Project: Install_Builder_Universal   File: ManageDirs.java   View Source Code Vote up 5 votes
@SuppressWarnings("rawtypes")
public void copyDir(final DefaultListModel dirModel, final JTextField txt, JProgressBar bar, Logger log) {
	bar.setValue(0);
	bar.setMinimum(0);
	bar.setMaximum(dirModel.size() - 1);
	if(dirModel.size() != 0) {
		for(int i = 0;i<dirModel.size(); i++) {
			log.Info("COPYING: <DIR> " + dirModel.getElementAt(i));
			File f = new File(dirModel.getElementAt(i).toString());
			try {
				if(!System.getProperty("os.name").equals("Linux"))
					InstallBuilderWindow.content +=  "Files\\" + Utils.indexOf(dirModel.getElementAt(i).toString(), '\\') + "\n";
				else
					InstallBuilderWindow.content +=  "Files/" + Utils.indexOf(dirModel.getElementAt(i).toString(), '/') + "\n";
				
				if(!System.getProperty("os.name").equals("Linux"))
					FileUtils.copyDirectory(f, new File(System.getProperty("user.dir") + "/" + txt.getText() + "/" + "/Files/" + 
							Utils.indexOf(dirModel.getElementAt(i).toString(), '\\')));
				else
					FileUtils.copyDirectory(f, new File(System.getProperty("user.dir") + "/" + txt.getText() + "/Files/" + 
							Utils.indexOf(dirModel.getElementAt(i).toString(), '/')));
			} catch (IOException e) {
				e.printStackTrace();
				log.Error("Could not copy directory\n" + e);
			}
			bar.setValue(i);
		}
		InstallBuilderWindow.content += "## DIRS END ##\n";
	}else {
		InstallBuilderWindow.content += "\n## DIRS END ##\n";
	}
}
 
Example 10
Project: karate   File: MockSpringMvcServletTest.java   View Source Code Vote up 5 votes
@Test
public void testSpringBootDemo() throws Exception {        
    File srcDir = new File("../karate-demo/src/test/java");
    File destDir = new File("target/test-classes");
    FileUtils.copyDirectory(srcDir, destDir, 
            f -> !f.getName().equals("karate-config.js") // don't over-write karate-config.js
                    && !f.getName().equals("redirect.feature") // too much work to support redirects in mock servlet
                    && !f.getName().equals("request.feature") // TODO support (karate.request) in mock servlet
                    && !f.getName().equals("sign-in.feature"), false); // TODO support servlet filters
    System.setProperty("karate.env", "dev-mock-springmvc");
    KarateStats stats = CucumberRunner.parallel(getClass(), 5);
    assertTrue("there are scenario failures", stats.getFailCount() == 0);
}
 
Example 11
Project: atlas   File: NativeSoUtils.java   View Source Code Vote up 5 votes
/**
 * @param localNativeLibrariesDirectory
 * @param destinationDirectory
 * @param supportAbis                   Type of architecture supported
 * @param removeSoFiles
 */
public static void copyLocalNativeLibraries(final File localNativeLibrariesDirectory,
                                            final File destinationDirectory, Set<String> supportAbis,
                                            Set<String> removeSoFiles) {
    sLogger.info("Copying existing native libraries from " + localNativeLibrariesDirectory + " to "
                     + destinationDirectory);
    try {
        IOFileFilter filter = new NativeSoFilter(supportAbis, removeSoFiles);
        // First, determine whether there is a file of the same name, if there is a discrepancy
        Collection<File> files = FileUtils.listFiles(localNativeLibrariesDirectory, filter, TrueFileFilter.TRUE);
        List<String> dumpFiles = new ArrayList<String>();
        for (File file : files) {
            String relativePath = getRelativePath(localNativeLibrariesDirectory, file);
            File destFile = new File(destinationDirectory, relativePath);
            if (destFile.exists()) {
                String orgFileMd5 = MD5Util.getFileMD5(file);
                String destFileMd5 = MD5Util.getFileMD5(destFile);
                if (!orgFileMd5.equals(destFileMd5)) {
                    dumpFiles.add(file.getAbsolutePath() + " to " + destFile.getAbsolutePath());
                }
            }
        }
        if (dumpFiles.size() > 0) {
            throw new RuntimeException("Copy native so error,duplicate file exist!:\n"
                                           + StringUtils.join(dumpFiles, "\n"));
        }
        FileUtils.copyDirectory(localNativeLibrariesDirectory, destinationDirectory, filter);
    } catch (IOException e) {
        throw new RuntimeException("Could not copy native dependency.", e);
    }
}
 
Example 12
Project: TitanCompanion   File: TCPreferenceActivity.java   View Source Code Vote up 5 votes
public static boolean runSavegameImport(Context context) {
    try {
            File oldDir = new File(Environment.getExternalStorageDirectory()
                    .getPath(), "ffgbutil");
        if (oldDir.exists()) {
            FileUtils.copyDirectory(oldDir, new File(context.getFilesDir(), "ffgbutil"));
            return true;
        } else {
            return false;
        }
    } catch (IOException e) {
        throw new IllegalStateException("Error importing old savegames", e);
    }
}
 
Example 13
Project: OneClient   File: MMCInstaller.java   View Source Code Vote up 5 votes
@Override
public void install(Instance instance) {
	try {
		FileUtils.copyDirectory(new File(dir, "minecraft"), instance.getDirectory());
	} catch (IOException e) {
		OneClientLogging.error(e);
	}
}
 
Example 14
Project: convertigo-engine   File: MobileResourceHelper.java   View Source Code Vote up 5 votes
private static boolean handleJQMcssFolder(File inFile, File outFile) throws IOException {
	if (inFile.getName().matches("jquery\\.mobile\\.(?:min\\.)?css")) {
		File inImages = new File(inFile.getParentFile(), "images");
		File outImages = new File(outFile.getParentFile(), "images");
		FileUtils.copyDirectory(inImages, outImages, defaultFilter, true);
		return true;
	}
	return false;
}
 
Example 15
Project: email-newsletter-generator   File: EmailTemplateMakerProgram.java   View Source Code Vote up 5 votes
private void _copyAssetsDirectory() {
    String dest = this._getOutputPath() + File.separator + "assets";
    
    if (!dest.equals("")) {
        String src = "contents" + File.separator + "assets";
        
        try {
            FileUtils.copyDirectory(new File(src), new File(dest));
        }
        catch (IOException exception) {
            exception.printStackTrace();
        }
    }
}
 
Example 16
Project: dhus-core   File: RestoreDatabase.java   View Source Code Vote up 5 votes
/**
 * @param args
 * @throws IllegalAccessException 
 * @throws IOException 
 */
public static void main (String[] args) throws IllegalAccessException,
      IOException
{
   if (args.length != 2)
   {
      throw new IllegalArgumentException (
         RestoreDatabase.class.getCanonicalName () + 
         ": Wrong arguments <source path> <destination path>.");
   }
   
   File dump = new File (args[0]);
   File db = new File (args[1]);
   
   LOGGER.info("Restoring " + dump.getPath () + " into " + db.getPath () +
         ".");
   
   if (!db.exists ())
      throw new IllegalArgumentException (
         RestoreDatabase.class.getCanonicalName () + 
         ": Input database path not found (\"" + db.getPath () + "\").");

   if (!dump.exists ())
      throw new IllegalArgumentException (
         RestoreDatabase.class.getCanonicalName () + 
         ": Input database dump path not found (\"" + db.getPath () +
               "\").");


   FileUtils.deleteDirectory (db);
   FileUtils.copyDirectory (dump, db);
   
   LOGGER.info("Dump properly restored, please restart system now.");
}
 
Example 17
Project: atlas   File: TPatchDiffApkBuildTask.java   View Source Code Vote up 4 votes
@TaskAction
public void doApkBuild() throws Exception {

    //TODO Merge 2 zip packages
    apkFile = getApkFile();
    diffAPkFile = getDiffAPkFile();

    Profiler.start("build tpatch apk");

    Profiler.enter("prepare dir");
    File tmpWorkDir = new File(diffAPkFile.getParentFile(), "tmp-apk");
    if (tmpWorkDir.exists()) {
        FileUtils.deleteDirectory(tmpWorkDir);
    }
    if (!tmpWorkDir.exists()) {
        tmpWorkDir.mkdirs();
    }

    BetterZip.unzipDirectory(apkFile,tmpWorkDir);

    //Map zipEntityMap = new HashMap();
    //ZipUtils.unzip(apkFile, tmpWorkDir.getAbsolutePath(), "UTF-8", zipEntityMap, true);

    FileUtils.deleteDirectory(new File(tmpWorkDir, "assets"));
    FileUtils.deleteDirectory(new File(tmpWorkDir, "res"));
    FileUtils.forceDelete(new File(tmpWorkDir, "resources.arsc"));
    FileUtils.forceDelete(new File(tmpWorkDir, "AndroidManifest.xml"));

    File resdir = new File(diffAPkFile.getParentFile(), "tmp-diffResAp");
    resdir.mkdirs();
    ZipUtils.unzip(getResourceFile(), resdir.getAbsolutePath(), "UTF-8", new HashMap<String, ZipEntry>(), true);

    FileUtils.copyDirectory(resdir, tmpWorkDir);

    Profiler.release();

    Profiler.enter("rezip");

    if (getProject().hasProperty("atlas.createDiffApk")) {
        BetterZip.zipDirectory(tmpWorkDir, diffAPkFile);
    }else {
        FileUtils.moveDirectory(tmpWorkDir,diffAPkFile);
    }

    //ZipUtils.rezip(diffAPkFile, tmpWorkDir, zipEntityMap);
    Profiler.release();

    FileUtils.deleteDirectory(tmpWorkDir);
    FileUtils.deleteDirectory(resdir);

    getLogger().warn(Profiler.dump());

}
 
Example 18
Project: wrdocletbase   File: Util.java   View Source Code Vote up 4 votes
public static void copyResourceFolder(String resourceFolder, String destDir)
		throws IOException {
	final File jarFile = new File(Util.class.getProtectionDomain()
			.getCodeSource().getLocation().getPath());
	if (jarFile.isFile()) { // Run with JAR file
		resourceFolder = StringUtils.strip(resourceFolder, "/");
		final JarFile jar = new JarFile(jarFile);
		// gives ALL entries in jar
		final Enumeration<JarEntry> entries = jar.entries();
		while (entries.hasMoreElements()) {
			JarEntry element = entries.nextElement();
			final String name = element.getName();
			// filter according to the path
			if (name.startsWith(resourceFolder + "/")) {
				String resDestDir = Util.combineFilePath(destDir,
						name.replaceFirst(resourceFolder + "/", ""));
				if (element.isDirectory()) {
					File newDir = new File(resDestDir);
					if (!newDir.exists()) {
						boolean mkdirRes = newDir.mkdirs();
						if (!mkdirRes) {
							logger.error("Failed to create directory "
									+ resDestDir);
						}
					}
				} else {
					InputStream inputStream = null;
					try {
						inputStream = Util.class.getResourceAsStream("/"
								+ name);
						if (inputStream == null) {
							logger.error("No resource is found:" + name);
						} else {
							Util.outputFile(inputStream, resDestDir);
						}

						/* compress js files */
						inputStream = Util.class.getResourceAsStream("/"
								+ name);
						compressor.compress(inputStream, name, destDir);
					} finally {
						if (inputStream != null) {
							inputStream.close();
						}
					}
				}
			}
		}
		jar.close();
	} else { // Run with IDE
		final URL url = Util.class.getResource(resourceFolder);
		if (url != null) {
			try {
				final File src = new File(url.toURI());
				File dest = new File(destDir);
				FileUtils.copyDirectory(src, dest);
				Util.compressFilesInDir(src, destDir);
			} catch (URISyntaxException ex) {
				logger.error(ex);
			}
		}
	}
}
 
Example 19
Project: marathonv5   File: MPFConfigurationInfo.java   View Source Code Vote up 4 votes
private void createMarathonDirectories(Properties props) {
    String projectDir = props.getProperty(Constants.PROP_PROJECT_DIR);
    if (props.getProperty(Constants.PROP_TEST_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_TESTCASES);
    }
    if (props.getProperty(Constants.PROP_SUITE_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_TESTSUITES);
    }
    if (props.getProperty(Constants.PROP_FEATURE_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_FEATURES);
    }
    if (props.getProperty(Constants.PROP_ISSUE_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_ISSUES);
    }
    if (props.getProperty(Constants.PROP_STORY_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_STORIES);
    }
    if (props.getProperty(Constants.PROP_CHECKLIST_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_CHECKLIST);
        File srcDir = new File(System.getProperty(Constants.PROP_HOME), "Checklists");
        File destDir = new File(projectDir, Constants.DIR_CHECKLIST);
        try {
            FileUtils.copyDirectory(srcDir, destDir);
        } catch (IOException e1) {
            LOGGER.warning("Unable to copy Checklists folder from " + srcDir + " to " + destDir);
            e1.printStackTrace();
        }
    }
    File destFile = new File(projectDir, "logging.properties");
    try {
        FileUtils.copyInputStreamToFile(MPFConfigurationStage.class.getResourceAsStream("/logging.properties"), destFile);
    } catch (IOException e) {
        LOGGER.warning("Copy file failed: " + destFile);
        e.printStackTrace();
    }
    if (props.getProperty(Constants.PROP_MODULE_DIRS) == null) {
        createMarathonDir(projectDir, Constants.DIR_MODULE);
    }
    if (props.getProperty(Constants.PROP_DATA_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_DATA);
    }
    if (props.getProperty(Constants.PROP_FIXTURE_DIR) == null) {
        createMarathonDir(projectDir, Constants.DIR_FIXTURES);
    }
}
 
Example 20
Project: openrouteservice   File: RoutingProfile.java   View Source Code Vote up 4 votes
public void updateGH(GraphHopper gh) throws Exception {
	if (gh == null)
		throw new Exception("GraphHopper instance is null.");

	try {
		mUpdateRun = true;
		while (true) {
			if (!isGHUsed()) {
				GraphHopper ghOld = mGraphHopper;

				ghOld.close();
				ghOld.clean();

				gh.close();
				// gh.clean(); // do not remove on-disk files, we need to
				// copy them as follows

				RuntimeUtility.clearMemory(LOGGER);

				// Change the content of the graph folder
				String oldLocation = ghOld.getGraphHopperLocation();
				File dstDir = new File(oldLocation);
				File srcDir = new File(gh.getGraphHopperLocation());
				FileUtils.copyDirectory(srcDir, dstDir, true);
				FileUtils.deleteDirectory(srcDir);

				RoutingProfileLoadContext loadCntx = new RoutingProfileLoadContext();

				mGraphHopper = initGraphHopper(ghOld.getDataReaderFile(), _config, RoutingProfileManager.getInstance().getProfiles(), loadCntx);

				loadCntx.release();

				break;
			}

			Thread.sleep(2000);
		}
	} catch (Exception ex) {
		LOGGER.error(ex.getMessage());
	}

	mUpdateRun = false;
}