views:

674

answers:

2

Good day,

Currently, we are using ByteArrayInputStream for our reset-able InputStream. My problem with it is that it consumes a lot of memory (it loads all the bytes it represents in memory unlike some other InputStream implementations).

My question then is, is there any lighter implementation of InputStream which supports mark() & read()?

I tried searching in commons-io as well, but I fail to see any.

Thanks, Franz

+3  A: 

Would using a BufferedInputStream work for you? Without knowing where the original data is coming from (eg, why you have a ByteArrayInputStream) to begin with it is a bit hard to answer your question.

TofuBeer
Thanks...BufferInputStream does work. I guess my problem was I was trying to buffer ServletInputStream which I can't since it's #available() always returns 0 (and BufferInputStream relies on that).
Franz See
+3  A: 

I most often use a PushbackInputStream when parsing data, and have the need to go back and re-read the data. Here is an explanation:

http://tutorials.jenkov.com/java-io/pushbackinputstream.html

There is also a PushbackReader should you need a character based stream instead.

Jakob Jenkov