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
{{ message }}
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
The read(byte[]) method in ByteSource was designed to behave like readFully in DataInputStream, i.e. fail when trying to read more data than available. For example the Blink codec relies on this behaviour.
The read(byte[]) method in InputStream is designed to read as much as possible, i.e. a "try read". The wrapper ByteSourceInputStream copies the behaviour from ByteSource to InputStream, and apparently this is not OK. For example the JSON codec (Jackson behind the scenes) relies on the "try read" behaviour to fill an internal parse buffer from the InputStream. This will fail whenever the internal parse buffer is larger than the remaining data, i.e. in most cases.
The ByteSourceInputStream wrapper is not easily fixed, since there is no "tryRead" in ByteSource or any way to find out how many remaining bytes there are.
I think an API change in ByteSource is hard to avoid, and hence this will likely be a major version bump. For example, rename existing read(byte[]) into readFully and add a new "try" read(byte[]) with InputStream semantics, or add a int remaining() or add tryRead(byte[]). All implementations of ByteSource will break...
If you need a failing test case in msgcodec-json to illustrate this, let me know.
The text was updated successfully, but these errors were encountered:
The
read(byte[])
method inByteSource
was designed to behave likereadFully
inDataInputStream
, i.e. fail when trying to read more data than available. For example the Blink codec relies on this behaviour.The
read(byte[])
method inInputStream
is designed to read as much as possible, i.e. a "try read". The wrapperByteSourceInputStream
copies the behaviour fromByteSource
toInputStream
, and apparently this is not OK. For example the JSON codec (Jackson behind the scenes) relies on the "try read" behaviour to fill an internal parse buffer from theInputStream
. This will fail whenever the internal parse buffer is larger than the remaining data, i.e. in most cases.The
ByteSourceInputStream
wrapper is not easily fixed, since there is no "tryRead" inByteSource
or any way to find out how many remaining bytes there are.I think an API change in ByteSource is hard to avoid, and hence this will likely be a major version bump. For example, rename existing
read(byte[])
intoreadFully
and add a new "try"read(byte[])
withInputStream
semantics, or add aint remaining()
or addtryRead(byte[])
. All implementations ofByteSource
will break...If you need a failing test case in msgcodec-json to illustrate this, let me know.
The text was updated successfully, but these errors were encountered: