-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure exception on chunk reaching beyond limit
This is a subtle behavior, but previous behavior has been that the first invocation to read(byte[]) with an array that would be filled with more elements if not being limited, would actually throw an exception. This commit preserves this behavior. One might argue that the most beneficial way to handle reading the "last chunk" before reaching the limit would be to fill the the array with any remaining "allowed" bytes, and return an int indicating the amount of bytes propagated to the array, though this also indicates that the stream reached a normal last chunk of bytes, and one can assume next read would return -1 (EOF). When setting up the LimitedInputStream to throw an exception if reading past the limit, this will ensure that code which assume that they can read one chunk of bytes, and as long as the read succeeds, they should be given complete and well-formed data. This would not be the case if the LimitedInputStream limits the bytes, and if it is set up to throw an exception, this exception must be thrown. If the LimitedInputStream is set up to "silently" yield EOF on reaching the limit, the read chunk is correctly chopped accordinly, and the next read will yield EOF as expected.
- Loading branch information
1 parent
ecb3a8e
commit 5e5178b
Showing
2 changed files
with
88 additions
and
6 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