< prev index next >
src/java.base/share/classes/java/io/InputStream.java
Print this page
@@ -27,10 +27,11 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
+import jdk.internal.io.IOSupport;
/**
* This abstract class is the superclass of all classes representing
* an input stream of bytes.
*
@@ -540,15 +541,8 @@
*
* @since 9
*/
public long transferTo(OutputStream out) throws IOException {
Objects.requireNonNull(out, "out");
- long transferred = 0;
- byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
- int read;
- while ((read = this.read(buffer, 0, DEFAULT_BUFFER_SIZE)) >= 0) {
- out.write(buffer, 0, read);
- transferred += read;
- }
- return transferred;
+ return IOSupport.copy(this, out);
}
}
< prev index next >