Hi,

On 10/14/07, Niall Pemberton <[EMAIL PROTECTED]> 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
java.io.InputStream 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.

BR,

Jukka Zitting

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to