mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8193842: Replace Files.copy(InputStream,OutputStream) with InputStream.transferTo(OutputStream)
Reviewed-by: clanger, alanb
This commit is contained in:
parent
ede41aa311
commit
c4f1bb0019
1 changed files with 2 additions and 18 deletions
|
@ -2954,22 +2954,6 @@ public final class Files {
|
||||||
return newBufferedWriter(path, StandardCharsets.UTF_8, options);
|
return newBufferedWriter(path, StandardCharsets.UTF_8, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
* Copies all bytes from an input stream to a file. On return, the input
|
||||||
* stream will be at end of stream.
|
* stream will be at end of stream.
|
||||||
|
@ -3082,7 +3066,7 @@ public final class Files {
|
||||||
|
|
||||||
// do the copy
|
// do the copy
|
||||||
try (OutputStream out = ostream) {
|
try (OutputStream out = ostream) {
|
||||||
return copy(in, out);
|
return in.transferTo(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3124,7 +3108,7 @@ public final class Files {
|
||||||
Objects.requireNonNull(out);
|
Objects.requireNonNull(out);
|
||||||
|
|
||||||
try (InputStream in = newInputStream(source)) {
|
try (InputStream in = newInputStream(source)) {
|
||||||
return copy(in, out);
|
return in.transferTo(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue