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

InputStream does not need support mark/reset #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saper
Copy link

@saper saper commented May 22, 2015

Use lookahead variable to avoid using mark()/reset()
on the java.io.InputStream

Use lookahead variable to avoid using mark()/reset()
on the java.io.InputStream
@saper
Copy link
Author

saper commented May 22, 2015

This allows me to use Jython this way:

Jython 2.5.3 (2.5:c56500f08d34+, Aug 13 2012, 14:48:36) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_80
Type "help", "copyright", "credits" or "license" for more information.
>>> from  org.bitlet.wetorrent import *
>>> mf = Metafile(file('/path/to/some.torrent'))  
>>> mf.length
99893498L

@abahgat
Copy link
Member

abahgat commented Jun 7, 2015

Thanks, will take a look today.
For context, is this needed because is.markSupported is false in Jython?

is.mark(0);
int readChar = is.read();
switch (readChar) {
private int readHead(InputStream is) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can avoid this method and just call is.read in every place instead of readHead(is).

@saper
Copy link
Author

saper commented Jun 8, 2015

This is just for clarity, that a lookahead is being used. I introduced readHead to make sure I replace only those calls to is.read that read one character "in advance". In the end, we ended up not having any other is.read() calls.

Similar for parseInteger, parseList and parseDictionary - they use (head, tail) split just to clarify the algorithm; technically those methods could be as well embedded in parse, as they are only called from there.

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

Successfully merging this pull request may close these issues.

None yet

3 participants