Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mark / reset in InputStreamReader #20

Open
nishihatapalmer opened this issue Aug 26, 2019 · 2 comments
Open

Support mark / reset in InputStreamReader #20

nishihatapalmer opened this issue Aug 26, 2019 · 2 comments

Comments

@nishihatapalmer
Copy link
Owner

nishihatapalmer commented Aug 26, 2019

InputStreamReader gives up if it can't find a Window in the cache from a position which has already been read, and throws a WindowMissingException. This is because you can't rewind streams, so if it isn't in the cache, we can't get the data.

If the underlying InputStream supported mark / reset, we have the possibility of rewinding the stream.

It still may fail, but then we just might get another IOException - instead of the guaranteed WindowMissingException (which is an IOException).

If it succeeds, we can read forward again in the stream to obtain the missing data.

@nishihatapalmer
Copy link
Owner Author

nishihatapalmer commented Aug 26, 2019

The simple implementation is to call mark() immediately on any stream we get (which we also assume is position 0).

Then we are relying on the underlying implementation being able to rewind the stream back to the point we got it, even if we've subsequently read a lot of data.

If it can't do that, it will fail sometimes. Whether failing every time is better than failing sometimes is something which only a user can answer - it depends on what is being used for.

@nishihatapalmer
Copy link
Owner Author

Another consideration is that in order to be able to rewind the stream, the stream must be performing some kind of caching.

If the stream supports caching, should we even bother doing our own caching?

I guess if we don't want to do our own caching, we can just pass a NoCache into the cache constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant