Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top