List of usage examples for java.nio.file Files copy
public static long copy(InputStream in, Path target, CopyOption... options) throws IOException
From source file:com.twitter.heron.downloader.Extractor.java
static void extract(InputStream in, Path destination) throws IOException { try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(in); final GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream( bufferedInputStream); final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzipInputStream)) { final String destinationAbsolutePath = destination.toFile().getAbsolutePath(); TarArchiveEntry entry;/*from www . ja va 2 s . c o m*/ while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) { if (entry.isDirectory()) { File f = Paths.get(destinationAbsolutePath, entry.getName()).toFile(); f.mkdirs(); } else { Path fileDestinationPath = Paths.get(destinationAbsolutePath, entry.getName()); Files.copy(tarInputStream, fileDestinationPath, StandardCopyOption.REPLACE_EXISTING); } } } }
From source file:com.stratio.mojo.scala.crossbuild.FileRewriter.java
static void restoreFile(final File origFile) throws IOException { final File bkpFile = getBackupFileName(origFile); Files.copy(bkpFile.toPath(), origFile.toPath(), StandardCopyOption.REPLACE_EXISTING); }
From source file:gov.nist.appvet.shared.FileUtil.java
public static synchronized boolean copyFile(String sourceFilePath, String destFilePath) { if (sourceFilePath == null || destFilePath == null) { return false; }//from w w w.ja v a 2 s .co m File sourceFile = new File(sourceFilePath); if (!sourceFile.exists()) { return false; } File destFile = new File(destFilePath); try { Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e) { log.error(e.getMessage()); return false; } finally { sourceFile = null; destFile = null; } return true; }
From source file:com.teradata.tempto.internal.convention.SqlTestsFileUtils.java
private static Consumer<Path> copyFileRecursive(Path source, Path target) { return (Path file) -> { try {//from w w w . ja va 2 s. c o m Files.copy(file, target.resolve(source.relativize(file).toString()), COPY_ATTRIBUTES); } catch (IOException exception) { throw new RuntimeException(exception); } }; }
From source file:gov.nist.appvet.tool.sigverifier.util.FileUtil.java
public static boolean copyFile(String sourceFilePath, String destFilePath) { if (sourceFilePath == null || destFilePath == null) { return false; }//from w w w . j a va 2s . co m File sourceFile = new File(sourceFilePath); if (!sourceFile.exists()) { return false; } File destFile = new File(destFilePath); try { Files.copy(sourceFile.toPath(), destFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e) { log.error(e.toString()); return false; } finally { sourceFile = null; destFile = null; } return true; }
From source file:onl.area51.filesystem.http.server.SaveContentAction.java
@Override public void apply(Request request) throws HttpException, IOException { Path path = request.getAttribute("path"); HttpRequest req = request.getHttpRequest(); if (path != null && req instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) req; HttpEntity entity = entityRequest.getEntity(); Files.copy(entity.getContent(), path, StandardCopyOption.REPLACE_EXISTING); request.getHttpResponse().setStatusCode(HttpStatus.SC_OK); request.getHttpResponse().setEntity(new StringEntity("OK")); } else {/*from w w w .j a v a 2s . c o m*/ request.getHttpResponse().setStatusCode(HttpStatus.SC_BAD_REQUEST); request.getHttpResponse().setEntity(new StringEntity("BAD REQUEST")); } }
From source file:com.netflix.dynomitemanager.defaultimpl.test.FloridaStandardTunerTest.java
@Test public void testWriteAllProperties() throws Exception { DynomiteStandardTuner tuner = new DynomiteStandardTuner(new BlankConfiguration(), new FakeInstanceIdentity(), null, null); String yamlPath = System.getProperty("java.io.tmpdir") + "/yaml-tunner.yaml"; String templateYamlPath = new File(".").getCanonicalPath() + "/src/test/resources/sample-yaml.yaml"; Files.copy(Paths.get(templateYamlPath), Paths.get(yamlPath), REPLACE_EXISTING); /*/*from ww w . j a v a 2 s . co m*/ * Not testing this until we fix it * tuner.writeAllProperties(yamlPath); String result = FileUtils.readFileToString(new File(yamlPath)); Assert.assertNotNull(result); Assert.assertTrue(result.contains("101134286")); Assert.assertTrue(result.contains("/apps/dynomite/conf/dynomite.pem")); Assert.assertTrue(result.contains(new FakeInstanceIdentity().getSeeds().get(0))); Assert.assertTrue(result.contains(new FakeInstanceIdentity().getSeeds().get(1))); Assert.assertTrue(result.contains(new FakeInstanceIdentity().getSeeds().get(2))); */ }
From source file:nl.uva.mlc.eurovoc.dataprocessor.DataSeperator.java
public void Seperator(File mainFile, String ConceptDir, String TrainDir) { File[] files = mainFile.listFiles(); for (File folder : files) { if (folder.isDirectory()) { for (File file : folder.listFiles()) if (file.getName().startsWith("jrc") && file.getName().endsWith(".xml")) { if (fileCount <= conceptPerc) { File f = new File(ConceptDir + "/" + file.getName()); try { Files.copy(file.toPath(), f.toPath(), REPLACE_EXISTING); } catch (IOException ex) { log.error(ex); }/*from ww w .j a v a2 s. c o m*/ } else { File f = new File(TrainDir + "/" + file.getName()); try { Files.copy(file.toPath(), f.toPath(), REPLACE_EXISTING); } catch (IOException ex) { log.error(ex); } } fileCount++; } } else { if (folder.getName().startsWith("jrc") && folder.getName().endsWith(".xml")) { if (fileCount <= conceptPerc) { File f = new File(ConceptDir + "/" + folder.getName()); try { Files.copy(folder.toPath(), f.toPath(), REPLACE_EXISTING); } catch (IOException ex) { log.error(ex); } } else { File f = new File(TrainDir + "/" + folder.getName()); try { Files.copy(folder.toPath(), f.toPath(), REPLACE_EXISTING); } catch (IOException ex) { log.error(ex); } } fileCount++; } } } }
From source file:de.douglas.maven.plugin.rpmsystemd.systemd.SystemdMojoTest.java
public void testGenerateSystemdFileWithDefaultSettings() throws Exception { String testPomName = "pom-defaults.xml"; Path testBaseDir = createDir(systemdTestsBaseDir.resolve("defaults")); Path pomPath = testBaseDir.resolve(testPomName); Path srcPom = systemdSrcDir.resolve(testPomName); Files.copy(srcPom, pomPath, StandardCopyOption.REPLACE_EXISTING); createDir(SystemPaths$.MODULE$.generationRootDir(testBaseDir)); SystemdMojo systemdMojo = (SystemdMojo) lookupMojo(pomPath, "generate-systemd-file"); systemdMojo.execute();// ww w . jav a2 s .c o m assertTrue("Generated systemd service file does not equal expected one", FileUtils.contentEquals(systemdSrcDir.resolve("test-module.service-defaults-expected").toFile(), testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin") .resolve("test-module.service").toFile())); }
From source file:de.douglas.maven.plugin.rpmsystemd.rpm.PostInstMojoTest.java
public void testGenerateRpmPostInstFileWithDefaultSettings() throws Exception { String testPomName = "pom-defaults.xml"; Path testBaseDir = createDir(postInstTestsBaseDir.resolve("defaults")); Path pomPath = testBaseDir.resolve(testPomName); Path srcPom = postInstSrcDir.resolve(testPomName); Files.copy(srcPom, pomPath, StandardCopyOption.REPLACE_EXISTING); createDir(SystemPaths$.MODULE$.generationRootDir(testBaseDir)); PostInstMojo postInstMojo = (PostInstMojo) lookupMojo(pomPath, "generate-rpm-postinst-file"); postInstMojo.execute();/*from ww w .j a v a 2 s. c o m*/ assertTrue("Generated postinst file does not equal expected one", FileUtils.contentEquals( postInstSrcDir.resolve("postinst-defaults-expected").toFile(), testBaseDir.resolve("target").resolve("rpm-systemd-maven-plugin").resolve("postinst").toFile())); }