bitlet icon indicating copy to clipboard operation
bitlet copied to clipboard

InputStream does not need support mark/reset

Open saper opened this issue 10 years ago • 3 comments

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

saper avatar May 22 '15 08:05 saper

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

saper avatar May 22 '15 09:05 saper

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

abahgat avatar Jun 07 '15 14:06 abahgat

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.

saper avatar Jun 08 '15 02:06 saper