diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-12-13 15:26:41 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2017-12-13 15:26:41 +0100 |
commit | d3c1c98b5e67cf8f9bb9f3efdef3161f63c19ffc (patch) | |
tree | 05aea3ca495d6acf87ee3817d6f2957a57c39339 /vespajlib/src/main | |
parent | 3783a9b21f8ab7ca3700903d9780a9f7374cf0c5 (diff) | |
parent | 540b84751e90d60c13c4da3e1e15d47b720c327e (diff) |
Merge with master
Diffstat (limited to 'vespajlib/src/main')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/io/IOUtils.java | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java index 2572842b213..febe02cb33e 100644 --- a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java +++ b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java @@ -3,6 +3,7 @@ package com.yahoo.io; import java.io.*; +import java.nio.channels.FileChannel; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.util.List; @@ -155,33 +156,22 @@ public abstract class IOUtils { /** * Copies a file to another file. * If the out file exists it will be overwritten. - * NOTE: Not an optimal implementation currently. * * @throws IOException if copying fails */ public static void copy(String inFile, String outFile) throws IOException { - BufferedReader reader=null; - BufferedWriter writer=null; - - try { - reader = createReader(inFile); - writer = createWriter(outFile, false); - int c; - while (-1 != (c = reader.read()) ) - writer.write(c); - } finally { - closeReader(reader); - closeWriter(writer); - } + copy(new File(inFile), new File(outFile)); } /** * Copies a file to another file. * If the out file exists it will be overwritten. - * NOTE: Not an optimal implementation currently. */ public static void copy(File inFile, File outFile) throws IOException { - copy(inFile.toString(),outFile.toString()); + try (FileChannel sourceChannel = new FileInputStream(inFile).getChannel(); + FileChannel destChannel = new FileOutputStream(outFile).getChannel()) { + destChannel.transferFrom(sourceChannel, 0, sourceChannel.size()); + } } /** @@ -275,8 +265,8 @@ public abstract class IOUtils { } /** - * Returns the number of line in a file. - * If the files does not exists, 0 is returned + * Returns the number of lines in a file. + * If the file does not exists, 0 is returned */ public static int countLines(String file) { BufferedReader reader = null; @@ -292,7 +282,6 @@ public abstract class IOUtils { } finally { closeReader(reader); } - } /** |