Closed GoogleCodeExporter closed 9 years ago
Out of curiosity, what are you interested in using this method for? It's
primarily designed around the use case of files, where the actual number of
bytes in the stream could differ from what you get when you check the length of
the file beforehand (but in most cases won't). It handles the stream having
both more and fewer bytes than the expected size gracefully... for other use
cases, it's possible that's not the best behavior.
Note that using limit() with toByteArray() does not have the same result: if
there are more than the expected number of bytes in the stream when using
limit, it will read at most the expected number of bytes, where this method
will read all bytes regardless.
Original comment by cgdecker@google.com
on 23 Jun 2014 at 4:21
Dang it, you're right -- I misread the code. However, I could still use it in
combination with ByteStreams.limit -- that would get me the behavior I would
like, i.e. avoiding the extra copy of ByteStreams.toArray(InputStream). That
would probably be too contrived as an API, though.
Thinking a bit more about it, I think I'll probably be better off just using a
customized ByteArrayOutputStream (to gain access to its internal buffer) and
using ByteStreams.copy().
Feel free to close this.
Original comment by bardur.a...@gmail.com
on 23 Jun 2014 at 4:57
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<issue id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:08
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:17
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:07
Original issue reported on code.google.com by
bardur.a...@gmail.com
on 22 Jun 2014 at 10:00