Example usage for java.nio.file StandardCopyOption REPLACE_EXISTING

List of usage examples for java.nio.file StandardCopyOption REPLACE_EXISTING

Introduction

In this page you can find the example usage for java.nio.file StandardCopyOption REPLACE_EXISTING.

Prototype

StandardCopyOption REPLACE_EXISTING

To view the source code for java.nio.file StandardCopyOption REPLACE_EXISTING.

Click Source Link

Document

Replace an existing file if it exists.

Usage

From source file:com.twitter.heron.apiserver.utils.FileHelper.java

public static boolean copy(Path from, Path to) {
    try {//from  w w w  .j a v a  2  s  .c  o m
        Files.copy(from, to, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException ioe) {
        LOG.error("Failed to copy file from {} to {}", from, to, ioe);
        return false;
    }
    return true;
}

From source file:org.roda.core.storage.RandomMockContentPayload.java

@Override
public void writeToPath(Path path) throws IOException {
    Files.copy(createInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
}

From source file:org.roda.core.storage.InputStreamContentPayload.java

@Override
public void writeToPath(Path path) throws IOException {
    InputStream inputStream = createInputStream();
    Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING);
    IOUtils.closeQuietly(inputStream);/*w w  w.  j av  a 2 s  .c o m*/
}

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 w  w w. j a v a2 s . co  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:org.roda.core.storage.fedora.FedoraContentPayload.java

@Override
public void writeToPath(Path path) throws IOException {
    InputStream inputStream = createInputStream();
    Files.copy(inputStream, path, StandardCopyOption.REPLACE_EXISTING);
    IOUtils.closeQuietly(inputStream);// w w w  . j a  v a 2s.  c  om

}

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  . j av  a2  s.  c o  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:gov.nist.appvet.tool.sigverifier.util.FileUtil.java

public static boolean copyFile(String sourceFilePath, String destFilePath) {
    if (sourceFilePath == null || destFilePath == null) {
        return false;
    }/*from  ww w.j  a  va2s . c  om*/
    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:ms.dew.devops.kernel.plugin.appkind.frontend_node.FrontendNodeBuildFlow.java

protected void preDockerBuild(FinalProjectConfig config, String flowBasePath) throws IOException {
    String preparePath = config.getTargetDirectory() + "dew_prepare" + File.separator;
    FileUtils.deleteDirectory(new File(flowBasePath + "dist"));
    Files.move(Paths.get(preparePath + "dist"), Paths.get(flowBasePath + "dist"),
            StandardCopyOption.REPLACE_EXISTING);
    if (config.getApp().getServerConfig() != null && !config.getApp().getServerConfig().isEmpty()) {
        Files.write(Paths.get(flowBasePath + "custom.conf"), config.getApp().getServerConfig().getBytes());
    } else {/*from  ww w.  j av  a2s . co  m*/
        Files.write(Paths.get(flowBasePath + "custom.conf"), "".getBytes());
    }
    $.file.copyStreamToPath(DevOps.class.getResourceAsStream("/dockerfile/frontend_node/Dockerfile"),
            flowBasePath + "Dockerfile");
}

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 {//  w w w  .j a va 2 s .  c  o m
        request.getHttpResponse().setStatusCode(HttpStatus.SC_BAD_REQUEST);
        request.getHttpResponse().setEntity(new StringEntity("BAD REQUEST"));
    }
}