List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:com.gemstone.gemfire.internal.logging.log4j.LogWriterLoggerPerformanceTest.java
protected Logger createLogger() throws IOException { // create configuration with log-file and log-level this.configDirectory = new File(getUniqueName()); this.configDirectory.mkdir(); assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite()); // copy the log4j2-test.xml to the configDirectory //final URL srcURL = getClass().getResource("/com/gemstone/gemfire/internal/logging/log4j/log4j2-test.xml"); final URL srcURL = getClass().getResource("log4j2-test.xml"); final File src = new File(srcURL.getFile()); FileUtils.copyFileToDirectory(src, this.configDirectory); this.config = new File(this.configDirectory, "log4j2-test.xml"); assertTrue(this.config.exists()); this.logFile = new File(this.configDirectory, "gemfire.log"); final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile); final String logFileName = FileUtil.stripOffExtension(logFilePath); setPropertySubstitutionValues(logFileName, DEFAULT_LOG_FILE_SIZE_LIMIT, DEFAULT_LOG_FILE_COUNT_LIMIT); final String configPath = "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config); System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath); final Logger logger = LogWriterLogger.create(this.getClass().getName(), false); return logger; }
From source file:com.gemstone.gemfire.internal.logging.log4j.Log4J2PerformanceTest.java
protected Logger createLogger() throws IOException { // create configuration with log-file and log-level this.configDirectory = new File(getUniqueName()); this.configDirectory.mkdir(); assertTrue(this.configDirectory.isDirectory() && this.configDirectory.canWrite()); // copy the log4j2-test.xml to the configDirectory //final URL srcURL = getClass().getResource("/com/gemstone/gemfire/internal/logging/log4j/log4j2-test.xml"); final URL srcURL = getClass().getResource("log4j2-test.xml"); final File src = new File(srcURL.getFile()); FileUtils.copyFileToDirectory(src, this.configDirectory); this.config = new File(this.configDirectory, "log4j2-test.xml"); assertTrue(this.config.exists()); this.logFile = new File(this.configDirectory, "gemfire.log"); final String logFilePath = IOUtils.tryGetCanonicalPathElseGetAbsolutePath(logFile); final String logFileName = FileUtil.stripOffExtension(logFilePath); setPropertySubstitutionValues(logFileName, DEFAULT_LOG_FILE_SIZE_LIMIT, DEFAULT_LOG_FILE_COUNT_LIMIT); final String configPath = "file://" + IOUtils.tryGetCanonicalPathElseGetAbsolutePath(this.config); System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configPath); final Logger logger = LogManager.getLogger(); return logger; }
From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBServiceWithSSLTest.java
@BeforeClass public static void setUpClass() throws Exception { orientdbHome.mkdirs();// w ww . j a v a 2s . co m FileUtils.cleanDirectory(orientdbHome); FileUtils.deleteDirectory(orientdbHome); log.logp(INFO, CLASS_NAME, "setUpClass", String.format("orientdbHome.exists() = %s", orientdbHome.exists())); final File configDirSrc = new File("src/test/resources/orientdb/config"); final File configDirTarget = new File(orientdbHome, "config"); FileUtils.copyFileToDirectory(new File(configDirSrc, "default-distributed-db-config.json"), configDirTarget); FileUtils.copyFileToDirectory(new File(configDirSrc, "hazelcast.xml"), configDirTarget); final File configCertDirSrc = new File("src/test/resources/orientdb/config/cert"); final File configCertDirTarget = new File(orientdbHome, "config/cert"); FileUtils.copyDirectory(configCertDirSrc, configCertDirTarget); final ApplicationId appId = ApplicationId.builder().group("co.runrightfast") .name("runrightfast-vertx-orientdb").version("1.0.0").build(); final AppEventLogger appEventLogger = new AppEventJDKLogger(appId); final EmbeddedOrientDBServiceConfig config = EmbeddedOrientDBServiceConfig.builder() .orientDBRootDir(orientdbHome.toPath()).handler(new OGraphServerHandlerConfig()) .handler(EmbeddedOrientDBServiceWithSSLTest::oHazelcastPlugin) .handler(EmbeddedOrientDBServiceWithSSLTest::oServerSideScriptInterpreter) .networkConfig(oServerNetworkConfiguration()) .user(new OServerUserConfiguration(ROOT_USER, "root", "*")) .property(OGlobalConfiguration.DB_POOL_MIN, "1").property(OGlobalConfiguration.DB_POOL_MAX, "50") .databasePoolConfig(new OrientDBPoolConfig(CLASS_NAME, "remote:localhost/" + CLASS_NAME, "admin", "admin", 10, ImmutableSet.of(() -> new SetCreatedOnAndUpdatedOn()))) .lifecycleListener(() -> new RunRightFastOrientDBLifeCycleListener(appEventLogger)).build(); service = new EmbeddedOrientDBService(config); ServiceUtils.start(service); initDatabase(); }
From source file:com.photon.phresco.plugins.SharePointDeploy.java
private void extractBuild() throws MojoExecutionException { try {//w w w . j av a 2s. c om ArchiveUtil.extractArchive(buildFile.getPath(), tempDir.getPath(), ArchiveType.ZIP); FileUtils.copyFileToDirectory(temp, build); FileUtils.deleteDirectory(tempDir); } catch (PhrescoException e) { throw new MojoExecutionException(e.getErrorMessage(), e); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }
From source file:eu.openanalytics.rsb.DirectoryDepositITCase.java
protected void doInvalidZipDeposit(final String jobFileName) throws IOException, InterruptedException, FileNotFoundException { FileUtils.copyFileToDirectory(getTestFile(jobFileName), jobsDirectory); final File acceptedFile = ponderUntilJobAccepted(jobFileName); assertThat("file was not created: " + acceptedFile, acceptedFile.isFile(), is(true)); final File resultFile = ponderUntilJobError(jobFileName); assertThat("file was not created: " + resultFile, resultFile.isFile(), is(true)); validateErrorResult(new FileInputStream(resultFile)); }
From source file:com.iyonger.apm.web.model.Home.java
/** * Copy the given file from given location. * * @param from file location//ww w.ja va 2 s . com */ public void copyFrom(File from) { // Copy missing files try { for (File file : checkNotNull(from.listFiles())) { if (!(new File(directory, file.getName()).exists())) { FileUtils.copyFileToDirectory(file, directory); } else { File orgConf = new File(directory, "org_conf"); if (orgConf.mkdirs()) { LOGGER.info("{}", orgConf.getPath()); } FileUtils.copyFile(file, new File(orgConf, file.getName())); } } } catch (IOException e) { throw processException("Fail to copy files from " + from.getAbsolutePath(), e); } }
From source file:co.cask.tigon.sql.internal.StreamBinaryGenerator.java
private File createStreamLibrary(File dir) throws IOException, ArchiveException { if (!dir.exists()) { dir.mkdirs();/*from w ww .ja va 2 s.c om*/ } //Get the library zip, copy it to temp dir, unzip it String libFile = Platform.libraryResource(); File libZip = new File(dir, libFile); libZip.createNewFile(); copyResourceFileToDir(libFile, libZip); unzipFile(libZip); //Create directory structure to place the Stream Engine Config Files File workDir = new File(dir, "work"); workDir.mkdirs(); File queryDir = new File(workDir, "query"); queryDir.mkdirs(); FileUtils.copyFileToDirectory(new File(dir, "cfg/external_fcns.def"), queryDir); FileUtils.copyFileToDirectory(new File(dir, "cfg/internal_fcn.def"), queryDir); return queryDir; }
From source file:co.runrightfast.vertx.orientdb.impl.embedded.EmbeddedOrientDBServiceWithSSLWithClientAuthTest.java
@BeforeClass public static void setUpClass() throws Exception { orientdbHome.mkdirs();/*from w ww . ja va2 s . c o m*/ FileUtils.cleanDirectory(orientdbHome); FileUtils.deleteDirectory(orientdbHome); log.logp(INFO, CLASS_NAME, "setUpClass", String.format("orientdbHome.exists() = %s", orientdbHome.exists())); final File configDirSrc = new File("src/test/resources/orientdb/config"); final File configDirTarget = new File(orientdbHome, "config"); FileUtils.copyFileToDirectory(new File(configDirSrc, "default-distributed-db-config.json"), configDirTarget); FileUtils.copyFileToDirectory(new File(configDirSrc, "hazelcast.xml"), configDirTarget); final File configCertDirSrc = new File("src/test/resources/orientdb/config/cert"); final File configCertDirTarget = new File(orientdbHome, "config/cert"); FileUtils.copyDirectory(configCertDirSrc, configCertDirTarget); final ApplicationId appId = ApplicationId.builder().group("co.runrightfast") .name("runrightfast-vertx-orientdb").version("1.0.0").build(); final AppEventLogger appEventLogger = new AppEventJDKLogger(appId); setSSLSystemProperties(); final EmbeddedOrientDBServiceConfig config = EmbeddedOrientDBServiceConfig.builder() .orientDBRootDir(orientdbHome.toPath()).handler(new OGraphServerHandlerConfig(false)) .handler(EmbeddedOrientDBServiceWithSSLWithClientAuthTest::oHazelcastPlugin) .handler(EmbeddedOrientDBServiceWithSSLWithClientAuthTest::oServerSideScriptInterpreter) .networkConfig(oServerNetworkConfiguration()) .user(new OServerUserConfiguration(ROOT_USER, "root", "*")) .property(OGlobalConfiguration.DB_POOL_MIN, "1").property(OGlobalConfiguration.DB_POOL_MAX, "50") .databasePoolConfig(new OrientDBPoolConfig(CLASS_NAME, "remote:localhost/" + CLASS_NAME, "admin", "admin", 10, ImmutableSet.of(() -> new SetCreatedOnAndUpdatedOn()))) .lifecycleListener(() -> new RunRightFastOrientDBLifeCycleListener(appEventLogger)).build(); service = new EmbeddedOrientDBService(config); ServiceUtils.start(service); initDatabase(); }
From source file:com.temenos.interaction.loader.classloader.CachingParentLastURLClassloaderFactory.java
protected synchronized URLClassLoader createClassLoader(Object currentState, FileEvent<File> param) { try {//from w w w .j av a 2 s . co m LOGGER.debug( "Classloader requested from CachingParentLastURLClassloaderFactory, based on FileEvent reflecting change in {}", param.getResource().getAbsolutePath()); Set<URL> urls = new HashSet<URL>(); File newTempDir = new File(FileUtils.getTempDirectory(), currentState.toString()); FileUtils.forceMkdir(newTempDir); Collection<File> files = FileUtils.listFiles(param.getResource(), new String[] { "jar" }, true); for (File f : files) { try { LOGGER.trace("Adding {} to list of URLs to create classloader from", f.toURI().toURL()); FileUtils.copyFileToDirectory(f, newTempDir); urls.add(new File(newTempDir, f.getName()).toURI().toURL()); } catch (MalformedURLException ex) { // should not happen, we do have the file there // but if, what can we do - just log it LOGGER.warn("Trying to intilialize classloader based on URL failed!", ex); } } lastClassloaderTempDir = newTempDir; URLClassLoader classloader = new ParentLastURLClassloader(urls.toArray(new URL[] {}), Thread.currentThread().getContextClassLoader()); return classloader; } catch (IOException ex) { throw new RuntimeException("Unexpected error trying to create new classloader.", ex); } }
From source file:launcher.workflow.update.UpdateWorkflow.java
public static void begin(final Settings launcherCfg, final String license) { WorkflowStep prepare = new WorkflowStep("Preparing to launch the game", new WorkflowAction() { @Override/*from w ww. ja v a 2 s. c o m*/ public boolean act() { return true; } }); WorkflowStep checkLicense = new WorkflowStep("Checking to see if a license has been entered.", new WorkflowAction() { @Override public boolean act() throws Exception { if (license == null || license.isEmpty()) { LaunchLogger.error(LaunchLogger.Tab + "No valid license found."); return false; } WorkflowWindowManager.setProgressVisible(true); URL licenseCheckUrl = new URL(launcherCfg.licenseCall(license)); String response = IOUtils.toString(licenseCheckUrl.openStream()); WorkflowWindowManager.setProgressVisible(false); if (response.contains("true")) { LaunchLogger.info(LaunchLogger.Tab + "License is valid."); return true; } else { if (License.isCached()) { LaunchLogger .info("Invalid license was found. Deleting the locally cached license."); License.deleteCache(); return false; } } return false; } }); WorkflowStep checkVersion = new WorkflowStep("Checking for updates.", new WorkflowAction() { @Override public boolean act() throws Exception { File versionPath = new File("assets/data/version.dat"); String myVersion = "0.0.0"; if (versionPath.exists()) { myVersion = FileUtils.readFileToString(versionPath); LaunchLogger.info("Detected version: " + myVersion); } WorkflowWindowManager.setProgressVisible(true); URL versionCheckUrl = new URL(launcherCfg.versionCall(myVersion)); String result = IOUtils.toString(versionCheckUrl.openStream()); WorkflowWindowManager.setProgressVisible(false); if (result.contains("true")) { LaunchLogger.info(LaunchLogger.Tab + "Local copy of the game is out of date."); return true; } LaunchLogger.info(LaunchLogger.Tab + "Local copy of the game is up to date. No update required."); return false; } }); WorkflowStep downloadUpdate = new WorkflowStep("Preparing the update location", new WorkflowAction() { @Override public boolean act() throws Exception { if (UpdateWorkflowData.UpdateArchive.exists()) { FileUtils.forceDelete(UpdateWorkflowData.UpdateArchive); } int responseTimeoutMs = launcherCfg.responseTimeoutMilliseconds; int downloadTimeoutMs = launcherCfg.downloadTimeoutMilliseconds; LaunchLogger.info("Attempting to download an update using license: [" + license + "]"); WorkflowWindowManager.setProgressVisible(true); String downloadUrl = launcherCfg.downloadCall(license, "update"); LaunchLogger.info("Downloading latest stable edition"); FileUtils.copyURLToFile(new URL(downloadUrl), UpdateWorkflowData.UpdateArchive, responseTimeoutMs, downloadTimeoutMs); WorkflowWindowManager.setProgressVisible(false); LaunchLogger.info(LaunchLogger.Tab + "Update downloaded successfully."); return true; } }); WorkflowStep applyUpdate = new WorkflowStep("Unpacking update archive", new WorkflowAction() { @Override public boolean act() throws IOException { WorkflowWindowManager.setProgressVisible(true); Archive.unzip(UpdateWorkflowData.UpdateArchive, UpdateWorkflowData.UpdateWorkingDirectory); LaunchLogger.info("Replacing old content"); File game = new File(UpdateWorkflowData.UpdateWorkingDirectory + "/game.jar"); File gameTarget = new File("./"); LaunchLogger.info("Attempting to copy: " + game + " to " + gameTarget); FileUtils.copyFileToDirectory(game, gameTarget); File assets = new File(UpdateWorkflowData.UpdateWorkingDirectory + "/assets"); File assetsTarget = new File("./assets"); LaunchLogger.info("Attempting to copy: " + assets + " to " + assetsTarget); FileUtils.copyDirectory(assets, assetsTarget); WorkflowWindowManager.setProgressVisible(false); LaunchLogger.info(LaunchLogger.Tab + "Update applied successfully."); return true; } }); WorkflowStep clean = new WorkflowStep("Cleaning up temporary files", new WorkflowAction() { @Override public boolean act() throws IOException { if (UpdateWorkflowData.UpdateArchive.exists()) { FileUtils.forceDelete(UpdateWorkflowData.UpdateArchive); } if (UpdateWorkflowData.UpdateWorkingDirectory.exists()) { FileUtils.deleteDirectory(UpdateWorkflowData.UpdateWorkingDirectory); } return true; } }); prepare.setOnSuccess(checkLicense); checkLicense.setOnSuccess(checkVersion); checkVersion.setOnSuccess(downloadUpdate); downloadUpdate.setOnSuccess(applyUpdate); applyUpdate.setOnSuccess(clean); prepare.setOnFailure(clean); checkLicense.setOnFailure(clean); checkVersion.setOnFailure(clean); downloadUpdate.setOnFailure(clean); applyUpdate.setOnFailure(clean); prepare.execute(); }