mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8272297: FileInputStream should override transferTo() for better performance
Reviewed-by: alanb
This commit is contained in:
parent
3677734584
commit
82688258f6
2 changed files with 148 additions and 0 deletions
|
@ -354,6 +354,24 @@ public class FileInputStream extends InputStream
|
|||
return (capacity == nread) ? buf : Arrays.copyOf(buf, nread);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public long transferTo(OutputStream out) throws IOException {
|
||||
long transferred = 0L;
|
||||
if (out instanceof FileOutputStream fos) {
|
||||
FileChannel fc = getChannel();
|
||||
long pos = fc.position();
|
||||
transferred = fc.transferTo(pos, Long.MAX_VALUE, fos.getChannel());
|
||||
long newPos = pos + transferred;
|
||||
fc.position(newPos);
|
||||
if (newPos >= fc.size()) {
|
||||
return transferred;
|
||||
}
|
||||
}
|
||||
return transferred + super.transferTo(out);
|
||||
}
|
||||
|
||||
private long length() throws IOException {
|
||||
return length0();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue