commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jukka Zitting" <>
Subject Re: RereadableInputStream
Date Mon, 15 Oct 2007 12:40:48 GMT

On 10/14/07, Niall Pemberton <> wrote:
> I don't see anything in the javadocs for the mark/reset methods in
> InputStream that prevent it from being used for streams of arbitrary
> length.
> [...]
> Secondly, from a Commons IO perspective, we already have some of the
> functionality for some parts of what you're trying to achieve:

For the record, I have some existing code from previous projects that
resembles what Niall outlined. The TeeInputStream I contributed is
actually part of that codebase, and I'm planning to contribute also
the rest to commons-io once I've cleaned it up.

The use case that Keith is also coming from, is to be able to pass a
stream to a process (a parser in Tika) that will read an unknown
number of bytes from the stream and might even use mark/reset on it's
own to manage the stream. For such cases the standard mark feature in is not enough.

The solution I've been using is an application of the Memento pattern
where you can "freeze" multiple states of the input stream and later
restore the stream to such a frozen state. Each frozen state is
essentially a growing buffer (optionally on disk) that keeps track of
all bytes read from the stream, and restoring a state means rewinding
the stream to the beginning of the buffer associated with that state.


Jukka Zitting

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message