Summary
Change java.nio.channels.FileChannel::transferFrom
to extend the channel's file if position > size()
instead of writing no bytes.
Problem
Currently passing a position
value which is greater than FileChannel::size
to FileChannel::transferFrom
results in no bytes being written. This is inconsistent with FileChannel::write(ByteBuffer,long)
which extends the channel's file if position > size()
.
Solution
Modify FileChannel::transferFrom
to extend the channel's file when position > size()
in the same manner as the positional FileChannel:write
.
Specification
--- a/src/java.base/share/classes/java/nio/channels/FileChannel.java
+++ b/src/java.base/share/classes/java/nio/channels/FileChannel.java
@@ -701,8 +701,10 @@ public abstract class FileChannel
* source has reached end-of-stream.
*
* <p> This method does not modify this channel's position. If the given
- * position is greater than the file's current size then no bytes are
- * transferred. If the source channel has a position then bytes are read
+ * position is greater than or equal to the file's current size then the
+ * file will be grown to accommodate the new bytes; the values of any bytes
+ * between the previous end-of-file and the newly-written bytes are
+ * unspecified. If the source channel has a position then bytes are read
* starting at that position and then the position is incremented by the
* number of bytes read.
*
- csr of
-
JDK-8303260 (fc) FileChannel::transferFrom should support position > size()
-
- Closed
-