changeset 48444:315c690bb90b

8193842: Replace Files.copy(InputStream,OutputStream) with InputStream.transferTo(OutputStream) Reviewed-by: clanger, alanb
author bpb
date Wed, 20 Dec 2017 08:05:04 -0800
parents 9b700a5c4381
children c96d4c720995
files src/java.base/share/classes/java/nio/file/Files.java
diffstat 1 files changed, 2 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/nio/file/Files.java	Wed Dec 20 15:33:31 2017 +0000
+++ b/src/java.base/share/classes/java/nio/file/Files.java	Wed Dec 20 08:05:04 2017 -0800
@@ -2955,22 +2955,6 @@
     }
 
     /**
-     * Reads all bytes from an input stream and writes them to an output stream.
-     */
-    private static long copy(InputStream source, OutputStream sink)
-        throws IOException
-    {
-        long nread = 0L;
-        byte[] buf = new byte[BUFFER_SIZE];
-        int n;
-        while ((n = source.read(buf)) > 0) {
-            sink.write(buf, 0, n);
-            nread += n;
-        }
-        return nread;
-    }
-
-    /**
      * Copies all bytes from an input stream to a file. On return, the input
      * stream will be at end of stream.
      *
@@ -3082,7 +3066,7 @@
 
         // do the copy
         try (OutputStream out = ostream) {
-            return copy(in, out);
+            return in.transferTo(out);
         }
     }
 
@@ -3124,7 +3108,7 @@
         Objects.requireNonNull(out);
 
         try (InputStream in = newInputStream(source)) {
-            return copy(in, out);
+            return in.transferTo(out);
         }
     }