List of usage examples for java.nio.file StandardCopyOption REPLACE_EXISTING
StandardCopyOption REPLACE_EXISTING
To view the source code for java.nio.file StandardCopyOption REPLACE_EXISTING.
Click Source Link
From source file:com.yahoo.parsec.gradle.utils.FileUtils.java
/** * Write resource to file./*from www . j a v a 2 s. c o m*/ * * @param inputStream input stream * @param outputFile output file * @param overwrite overwrite flag * @throws IOException IOException */ public void writeResourceToFile(final InputStream inputStream, String outputFile, boolean overwrite) throws IOException { File file = new File(outputFile); String outputFileDigest = ""; if (file.exists()) { if (!overwrite) { logger.info("Skipping pre-existing " + outputFile); return; } else { try (InputStream outputFileStream = new FileInputStream(file)) { outputFileDigest = DigestUtils.md5Hex(outputFileStream); } catch (IOException e) { throw e; } } } try { byte[] bytes = IOUtils.toByteArray(inputStream); if (DigestUtils.md5Hex(bytes).equals(outputFileDigest)) { logger.info("Skipping unmodified " + outputFile); return; } else { logger.info("Creating file " + outputFile); Files.copy(new ByteArrayInputStream(bytes), Paths.get(outputFile), StandardCopyOption.REPLACE_EXISTING); } } catch (IOException e) { throw e; } }
From source file:com.aspose.barcode.maven.examples.AsposeExampleSupport.java
public void createExample() { String srcExamplePath = System.getProperty("user.home") + File.separator + localExampleFolder + File.separator + localExampleSourceFolder; String srcExampleResourcePath = System.getProperty("user.home") + File.separator + localExampleFolder + File.separator + localExampleResourceFolder; String destProjectExamplePath = selectedProjectPath + File.separator + localExampleSourceFolder; String destProjectExampleResourcePath = selectedProjectPath + File.separator + localExampleResourceFolder; File srcExampleCategoryPath = new File(srcExamplePath + File.separator + exampleCategory); File destExampleCategoryPath = new File(destProjectExamplePath + File.separator + exampleCategory); Path srcUtil = new File(srcExamplePath + File.separator + "Utils.java").toPath(); Path destUtil = new File(destProjectExamplePath + File.separator + "Utils.java").toPath(); File srcExampleResourceCategoryPath = new File(srcExampleResourcePath + File.separator + exampleCategory); File destExampleResourceCategoryPath = new File( destProjectExampleResourcePath + File.separator + exampleCategory); String repositoryPOM_XML = System.getProperty("user.home") + File.separator + localExampleFolder + File.separator + AsposeConstants.MAVEN_POM_XML; try {/*from w w w . java2s.co m*/ FileUtils.copyDirectory(srcExampleCategoryPath, destExampleCategoryPath); Files.copy(srcUtil, destUtil, StandardCopyOption.REPLACE_EXISTING); FileUtils.copyDirectory(srcExampleResourceCategoryPath, destExampleResourceCategoryPath); NodeList examplesNoneAsposeDependencies = AsposeMavenProjectManager.getInstance() .getDependenciesFromPOM(repositoryPOM_XML, AsposeConstants.ASPOSE_GROUP_ID); AsposeMavenProjectManager.getInstance().addMavenDependenciesInProject(examplesNoneAsposeDependencies); NodeList examplesNoneAsposeRepositories = AsposeMavenProjectManager.getInstance() .getRepositoriesFromPOM(repositoryPOM_XML, AsposeConstants.ASPOSE_MAVEN_REPOSITORY); AsposeMavenProjectManager.getInstance().addMavenRepositoriesInProject(examplesNoneAsposeRepositories); project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (IOException | CoreException e) { e.printStackTrace(); } }
From source file:org.apdplat.superword.tools.WordClassifierForWebster.java
public static void parseZip(String zipFile) { LOGGER.info("?ZIP" + zipFile); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), WordClassifierForWebster.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/*from w w w.j a v a 2s. co m*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/origin-html-temp.txt"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); parseFile(temp.toFile().getAbsolutePath()); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } }
From source file:com.btkelly.gnag.tasks.CheckLocalTask.java
private void copyCssFile(final File gnagReportDirectory) throws IOException { final InputStream gnagCssFileInputStream = getClass().getClassLoader().getResourceAsStream(CSS_FILE_NAME); Enumeration<URL> e = getClass().getClassLoader().getResources("."); while (e.hasMoreElements()) { System.out.println(e.nextElement()); }/*from www. j ava 2s . c o m*/ final Path gnagCssFileTargetPath = Paths.get(gnagReportDirectory.getAbsolutePath(), CSS_FILE_NAME); try { Files.copy(gnagCssFileInputStream, gnagCssFileTargetPath, StandardCopyOption.REPLACE_EXISTING); } catch (final IOException ignored) { Logger.logError("Error copying CSS file for local report."); } finally { try { gnagCssFileInputStream.close(); } catch (final IOException ignored) { } } }
From source file:org.roda.common.certification.OOXMLSignatureUtils.java
public static void runDigitalSignatureStrip(Path input, Path output) throws IOException, InvalidFormatException { CopyOption[] copyOptions = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING }; Files.copy(input, output, copyOptions); OPCPackage pkg = OPCPackage.open(output.toString(), PackageAccess.READ_WRITE); ArrayList<PackagePart> pps = pkg.getPartsByContentType(SIGN_CONTENT_TYPE_OOXML); for (PackagePart pp : pps) { pkg.removePart(pp);// w ww . j a va 2s. c o m } ArrayList<PackagePart> ppct = pkg.getPartsByRelationshipType(SIGN_REL_TYPE_OOXML); for (PackagePart pp : ppct) { pkg.removePart(pp); } for (PackageRelationship r : pkg.getRelationships()) { if (r.getRelationshipType().equals(SIGN_REL_TYPE_OOXML)) { pkg.removeRelationship(r.getId()); } } pkg.close(); }
From source file:de.flashpixx.rrd_antlr4.engine.template.IBaseTemplate.java
/** * copies files from the directory of the template to the output directory * * @param p_templatefile file within the template directory * @param p_output output directory/* ww w .j a v a2 s . c om*/ * @throws IOException on IO error * @throws URISyntaxException on URL syntax error */ protected final void copy(final String p_templatefile, final Path p_output) throws IOException, URISyntaxException { final Path l_target = Paths.get(p_output.toString(), p_templatefile); Files.createDirectories(l_target.getParent()); Files.copy(CCommon.resourceurl(MessageFormat.format("{0}{1}{2}{3}", "de/flashpixx/rrd_antlr4/template/", m_name, "/", p_templatefile)).openStream(), l_target, StandardCopyOption.REPLACE_EXISTING); }
From source file:org.forgerock.openidm.maintenance.upgrade.FileStateCheckerTest.java
@Test public void testUpdateStateAddition() throws IOException, URISyntaxException, NoSuchAlgorithmException { Files.copy(Paths.get(getClass().getResource("/checksums2.csv").toURI()), tempFile, StandardCopyOption.REPLACE_EXISTING); ChecksumFile tempChecksumFile = new ChecksumFile(tempFile); FileStateChecker checker = new FileStateChecker(tempChecksumFile); Path filepath = Paths.get("badformat.csv"); assertThat(checker.getCurrentFileState(filepath).equals(FileState.NONEXISTENT)); checker.updateState(filepath);/*from ww w . ja va2 s . c o m*/ checker = new FileStateChecker(tempChecksumFile); assertThat(checker.getCurrentFileState(filepath).equals(FileState.UNCHANGED)); }
From source file:org.roda.core.plugins.plugins.characterization.OOXMLSignatureUtils.java
public static void runDigitalSignatureStrip(Path input, Path output) throws IOException, InvalidFormatException { CopyOption[] copyOptions = new CopyOption[] { StandardCopyOption.REPLACE_EXISTING }; Files.copy(input, output, copyOptions); try (OPCPackage pkg = OPCPackage.open(output.toString(), PackageAccess.READ_WRITE)) { ArrayList<PackagePart> pps = pkg.getPartsByContentType(SIGN_CONTENT_TYPE_OOXML); for (PackagePart pp : pps) { pkg.removePart(pp);/*from w ww.j ava 2 s .c om*/ } ArrayList<PackagePart> ppct = pkg.getPartsByRelationshipType(SIGN_REL_TYPE_OOXML); for (PackagePart pp : ppct) { pkg.removePart(pp); } for (PackageRelationship r : pkg.getRelationships()) { if (r.getRelationshipType().equals(SIGN_REL_TYPE_OOXML)) { pkg.removeRelationship(r.getId()); } } } }
From source file:org.structr.media.ConverterProcess.java
@Override public VideoFile processExited(int exitCode) { final App app = StructrApp.getInstance(securityContext); if (exitCode == 0) { try (final Tx tx = app.tx()) { // move converted file into place final java.io.File diskFile = new java.io.File(outputFileName + fileExtension); final java.io.File dstFile = new java.io.File(outputFileName); if (diskFile.exists()) { Files.move(diskFile.toPath(), dstFile.toPath(), StandardCopyOption.REPLACE_EXISTING); FileHelper.updateMetadata(newFile); // create link between the two videos newFile.setProperty(StructrApp.key(VideoFile.class, "originalVideo"), inputFile); }/*w w w . j a va 2 s . c o m*/ tx.success(); } catch (FrameworkException | IOException fex) { logger.warn("", fex); } } else { // delete file, conversion has failed try (final Tx tx = app.tx()) { app.delete(newFile); tx.success(); } catch (FrameworkException fex) { logger.warn("", fex); } } return newFile; }
From source file:org.apdplat.superword.tools.WordClassifierForOxford.java
public static void parseZip(String zipFile) { LOGGER.info("?ZIP" + zipFile); try (FileSystem fs = FileSystems.newFileSystem(Paths.get(zipFile), WordClassifierForOxford.class.getClassLoader())) { for (Path path : fs.getRootDirectories()) { LOGGER.info("?" + path); Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override/* ww w . ja va 2s .c om*/ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { LOGGER.info("?" + file); // ? Path temp = Paths.get("target/origin-html-temp.txt"); Files.copy(file, temp, StandardCopyOption.REPLACE_EXISTING); parseFile(temp.toFile().getAbsolutePath()); return FileVisitResult.CONTINUE; } }); } } catch (Exception e) { LOGGER.error("?", e); } }