Changeset 7003 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2014-04-26T14:30:11+02:00 (11 years ago)
Author:
Don-vip
Message:

see #8465 - use Files.copy()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6999 r7003  
    1717import java.io.Closeable;
    1818import java.io.File;
    19 import java.io.FileInputStream;
    20 import java.io.FileOutputStream;
    2119import java.io.IOException;
    2220import java.io.InputStream;
     
    2927import java.net.URLConnection;
    3028import java.net.URLEncoder;
    31 import java.nio.channels.FileChannel;
    3229import java.nio.charset.Charset;
     30import java.nio.file.Files;
     31import java.nio.file.Path;
     32import java.nio.file.StandardCopyOption;
    3333import java.security.MessageDigest;
    3434import java.security.NoSuchAlgorithmException;
     
    323323    /**
    324324     * Simple file copy function that will overwrite the target file.<br>
    325      * Taken from <a href="http://www.rgagnon.com/javadetails/java-0064.html">this article</a> (CC-NC-BY-SA)
    326325     * @param in The source file
    327326     * @param out The destination file
     327     * @return the path to the target file
    328328     * @throws java.io.IOException If any I/O error occurs
    329      */
    330     public static void copyFile(File in, File out) throws IOException  {
    331         // TODO: remove this function when we move to Java 7 (use Files.copy instead)
    332         FileInputStream inStream = null;
    333         FileOutputStream outStream = null;
    334         try {
    335             inStream = new FileInputStream(in);
    336             outStream = new FileOutputStream(out);
    337             FileChannel inChannel = inStream.getChannel();
    338             inChannel.transferTo(0, inChannel.size(), outStream.getChannel());
    339         }
    340         catch (IOException e) {
    341             throw e;
    342         }
    343         finally {
    344             close(outStream);
    345             close(inStream);
    346         }
     329     * @throws IllegalArgumentException If {@code in} or {@code out} is {@code null}
     330     * @since 7003
     331     */
     332    public static Path copyFile(File in, File out) throws IOException, IllegalArgumentException  {
     333        CheckParameterUtil.ensureParameterNotNull(in, "in");
     334        CheckParameterUtil.ensureParameterNotNull(out, "out");
     335        return Files.copy(in.toPath(), out.toPath(), StandardCopyOption.REPLACE_EXISTING);
    347336    }
    348337
Note: See TracChangeset for help on using the changeset viewer.