You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
0 commit comments