-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix three bugs with
FileChannel.transferFrom
:
1. `transferFrom` was not behaving according to the spec when given a position that was greater than the size of that file. The spec says that nothing is transferred in that case, but Jimfs was using the same behavior as `write` in this case: the file was first zero-filled from the start until the given position and then bytes were transferred starting there. Jimfs now simply returns 0 in this case. 2. When given a non-blocking channel that can return 0 bytes from a call to `read`, `transferFrom` was spinning until the input channel returned -1. The spec is for `transferFrom` to return immediately in that case. 3. When a transfer ended on a block boundary (i.e. after exactly filling one block) but still had bytes remaining based on the given `count`, an extra (empty) block would be left allocated on the end of the file. That block is now correctly de-allocated so it can be used elsewhere. Fixes #163. Also simplify the implementation of `transferFrom` a bit. RELNOTES=Fixed several bugs with the behavior of `FileChannel.transferFrom`. PiperOrigin-RevId: 390208683
- Loading branch information
Showing
3 changed files
with
98 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters