List of usage examples for org.apache.commons.io FileUtils copyFileToDirectory
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException
From source file:org.apache.drill.exec.udf.dynamic.TestDynamicUDFSupport.java
@BeforeClass public static void buildAndStoreDefaultJars() throws IOException { jarsDir = dirTestWatcher.makeSubDir(Paths.get("jars")); buildDirectory = dirTestWatcher.makeSubDir(Paths.get("drill-udf")); jarBuilder = new JarBuilder("src/test/resources/drill-udf"); defaultBinaryJar = buildJars(DEFAULT_JAR_NAME, "**/CustomLowerFunction.java", null); defaultSourceJar = JarUtil.getSourceName(defaultBinaryJar); FileUtils.copyFileToDirectory(new File(buildDirectory, defaultBinaryJar), jarsDir); FileUtils.copyFileToDirectory(new File(buildDirectory, defaultSourceJar), jarsDir); }
From source file:org.apache.druid.cli.PullDependencies.java
/** * Download the extension given its maven coordinate * * @param versionedArtifact The maven artifact of the extension * @param toLocation The location where this extension will be downloaded to *//*from w w w. j a v a 2 s .c o m*/ private void downloadExtension(Artifact versionedArtifact, File toLocation) { final CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME)); final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils .andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), new DependencyFilter() { @Override public boolean accept(DependencyNode node, List<DependencyNode> parents) { String scope = node.getDependency().getScope(); if (scope != null) { scope = StringUtils.toLowerCase(scope); if ("provided".equals(scope)) { return false; } if ("test".equals(scope)) { return false; } if ("system".equals(scope)) { return false; } } if (accept(node.getArtifact())) { return false; } for (DependencyNode parent : parents) { if (accept(parent.getArtifact())) { return false; } } return true; } private boolean accept(final Artifact artifact) { return exclusions.contains(artifact.getGroupId()); } })); try { log.info("Start downloading extension [%s]", versionedArtifact); final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest); for (Artifact artifact : artifacts) { if (!exclusions.contains(artifact.getGroupId())) { log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath()); FileUtils.copyFileToDirectory(artifact.getFile(), toLocation); } else { log.debug("Skipped Artifact[%s]", artifact); } } } catch (Exception e) { log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest); throw Throwables.propagate(e); } log.info("Finish downloading extension [%s]", versionedArtifact); }
From source file:org.apache.geode.internal.cache.DiskInitFile.java
public void copyTo(File targetDir) throws IOException { lock(false);/*from www. j ava 2s .co m*/ try { FileUtils.copyFileToDirectory(this.ifFile, targetDir); } finally { unlock(false); } }
From source file:org.apache.geode.internal.cache.Oplog.java
public void copyTo(File targetDir) throws IOException { if (this.crf.f != null && this.crf.f.exists()) { FileUtils.copyFileToDirectory(this.crf.f, targetDir); }/*www . java 2 s. com*/ if (this.drf.f.exists()) { FileUtils.copyFileToDirectory(this.drf.f, targetDir); } // this krf existence check fixes 45089 // TODO: should we wait for the async KRF creation to finish by calling this.finishKrf? if (getParent().getDiskInitFile().hasKrf(this.oplogId)) { if (this.getKrfFile().exists()) { FileUtils.copyFileToDirectory(this.getKrfFile(), targetDir); } } }
From source file:org.apache.geode.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("/org/apache/geode/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, DistributionConfig.GEMFIRE_PREFIX + "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:org.apache.geode.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("/org/apache/geode/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, DistributionConfig.GEMFIRE_PREFIX + "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:org.apache.geode.test.dunit.standalone.ProcessManager.java
public synchronized void launchVM(String version, int vmNum, boolean bouncedVM) throws IOException { if (processes.containsKey(vmNum)) { throw new IllegalStateException("VM " + vmNum + " is already running."); }/*from www . j ava2s. c om*/ String[] cmd = buildJavaCommand(vmNum, namingPort, version); System.out.println("Executing " + Arrays.toString(cmd)); File workingDir = getVMDir(version, vmNum); if (!workingDir.exists()) { workingDir.mkdirs(); } else if (!bouncedVM || DUnitLauncher.MAKE_NEW_WORKING_DIRS) { try { FileUtil.delete(workingDir); } catch (IOException e) { // This delete is occasionally failing on some platforms, maybe due to a lingering // process. Allow the process to be launched anyway. System.err.println("Unable to delete " + workingDir + ". Currently contains " + Arrays.asList(workingDir.list())); } workingDir.mkdirs(); } if (log4jConfig != null) { FileUtils.copyFileToDirectory(log4jConfig, workingDir); } // TODO - delete directory contents, preferably with commons io FileUtils Process process = Runtime.getRuntime().exec(cmd, null, workingDir); pendingVMs++; ProcessHolder holder = new ProcessHolder(process); processes.put(vmNum, holder); linkStreams(version, vmNum, holder, process.getErrorStream(), System.err); linkStreams(version, vmNum, holder, process.getInputStream(), System.out); }
From source file:org.apache.geronimo.tomcat.deployment.TomcatModuleBuilderTest.java
public void recursiveCopy(File src, File dest) throws IOException { Collection files = FileUtils.listFiles(src, null, true); Iterator iterator = files.iterator(); while (iterator.hasNext()) { File file = (File) iterator.next(); if (file.getAbsolutePath().indexOf(".svn") < 0) { String pathToFile = file.getPath(); String relativePath = pathToFile.substring(src.getPath().length(), pathToFile.length() - (file.getName().length())); FileUtils.copyFileToDirectory(file, new File(dest.getPath() + relativePath)); }/* w w w.j av a 2s.co m*/ } }
From source file:org.apache.helix.tools.ZkGrep.java
/** * parse zk-transaction-logs between start and end, if not already parsed * @param zkLogDir/*from ww w.ja v a 2s. c o m*/ * @param start * @param end * @return list of parsed zklogs between start and end, in order of last modified timestamp */ static List<File> parseZkLogs(String zkLogDir, long start, long end) { File zkParsedDir = new File(String.format("%s/zklog-parsed", System.getProperty("user.home"))); File[] zkLogs = getSortedFiles(zkLogDir, log); // printFiles(zkDataFiles); List<File> parsedZkLogs = new ArrayList<File>(); boolean stop = false; for (File zkLog : zkLogs) { if (stop) { break; } if (zkLog.lastModified() < start) { continue; } if (zkLog.lastModified() > end) { stop = true; } try { File parsedZkLog = new File(zkParsedDir, stripGzSuffix(zkLog.getName()) + ".parsed"); if (!parsedZkLog.exists() || parsedZkLog.lastModified() <= zkLog.lastModified()) { if (zkLog.getName().endsWith(gzSuffix)) { // copy and gunzip it FileUtils.copyFileToDirectory(zkLog, zkParsedDir); File zkLogGz = new File(zkParsedDir, zkLog.getName()); File tmpZkLog = gunzip(zkLogGz); // parse gunzip file ZKLogFormatter.main( new String[] { log, tmpZkLog.getAbsolutePath(), parsedZkLog.getAbsolutePath() }); // delete it zkLogGz.delete(); tmpZkLog.delete(); } else { // parse it directly ZKLogFormatter .main(new String[] { log, zkLog.getAbsolutePath(), parsedZkLog.getAbsolutePath() }); } } parsedZkLogs.add(parsedZkLog); } catch (Exception e) { LOG.error("fail to parse zkLog: " + zkLog, e); } } return parsedZkLogs; }
From source file:org.apache.helix.tools.ZkGrep.java
/** * parse the last zk-snapshots by by-time, if not already parsed * @param zkSnapshotDir/*from ww w . j a va 2 s .c om*/ * @param byTime * @return File array which the first element is the last zk-snapshot by by-time and the second * element is its parsed file */ static File[] parseZkSnapshot(String zkSnapshotDir, long byTime) { File[] retFiles = new File[2]; File zkParsedDir = new File(String.format("%s/zklog-parsed", System.getProperty("user.home"))); File[] zkSnapshots = getSortedFiles(zkSnapshotDir, snapshot); // printFiles(zkDataFiles); File lastZkSnapshot = null; for (int i = 0; i < zkSnapshots.length; i++) { File zkSnapshot = zkSnapshots[i]; if (zkSnapshot.lastModified() >= byTime) { break; } lastZkSnapshot = zkSnapshot; retFiles[0] = lastZkSnapshot; } try { File parsedZkSnapshot = new File(zkParsedDir, stripGzSuffix(lastZkSnapshot.getName()) + ".parsed"); if (!parsedZkSnapshot.exists() || parsedZkSnapshot.lastModified() <= lastZkSnapshot.lastModified()) { if (lastZkSnapshot.getName().endsWith(gzSuffix)) { // copy and gunzip it FileUtils.copyFileToDirectory(lastZkSnapshot, zkParsedDir); File lastZkSnapshotGz = new File(zkParsedDir, lastZkSnapshot.getName()); File tmpLastZkSnapshot = gunzip(lastZkSnapshotGz); // parse gunzip file ZKLogFormatter.main(new String[] { snapshot, tmpLastZkSnapshot.getAbsolutePath(), parsedZkSnapshot.getAbsolutePath() }); // delete it lastZkSnapshotGz.delete(); tmpLastZkSnapshot.delete(); } else { // parse it directly ZKLogFormatter.main(new String[] { snapshot, lastZkSnapshot.getAbsolutePath(), parsedZkSnapshot.getAbsolutePath() }); } } retFiles[1] = parsedZkSnapshot; return retFiles; } catch (Exception e) { LOG.error("fail to parse zkSnapshot: " + lastZkSnapshot, e); } return null; }