It's not a secret anymore!
The moose likes I/O and Streams and the fly likes Convert to ByteArryInputStream? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Convert to ByteArryInputStream?" Watch "Convert to ByteArryInputStream?" New topic

Convert to ByteArryInputStream?

myron schabe

Joined: Aug 21, 2002
Posts: 19
How can I convert a to a ByteArrayInputStream?
Many Thanks.
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Why would you want to do that? A ByteArrayInputStream doesn't seem to have any methods that any other InputStream doesn't have. It just has the additional ability (or restriction in this case) that it reads input from an existing byte array. Which means you would need to create the byte array first, since it doesn't exist initially. Why bother? I mean, you can do it:

But isn't this easier?

The only advantage I see to the former method is that a ByteArrayInputStream will never block, and will always be able to read all bytes you ask for up to the end of the byte array. This may be useful or necessary for some applications. If not though, I'd keep things simple where possible, and just use the BufferedInputStream technique.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Convert to ByteArryInputStream?
It's not a secret anymore!