<s> """<STR_LIT>""" <EOL> import unittest <EOL> from org . python . core . util import FileUtil <EOL> from org . python . core . io import StreamIO <EOL> from java . io import InputStream <EOL> from java . nio import ByteBuffer ; <EOL> class InfiniteInputStream ( InputStream ) : <EOL> def read ( self , * args ) : <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> return ord ( '<STR_LIT:x>' ) <EOL> elif len ( args ) == <NUM_LIT:1> : <EOL> return InputStream . read ( self , args [ <NUM_LIT:0> ] ) <EOL> else : <EOL> return self . read_buffer ( * args ) <EOL> def read_buffer ( self , buf , off , length ) : <EOL> if length > <NUM_LIT:0> : <EOL> buf [ off ] = ord ( '<STR_LIT:x>' ) <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> class IoTestCase ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_infinite_input ( self ) : <EOL> iis = InfiniteInputStream ( ) <EOL> f = FileUtil . wrap ( iis , '<STR_LIT:rb>' ) <EOL> size = <NUM_LIT> <EOL> self . assertEqual ( len ( f . read ( size ) ) , size ) <EOL> self . assertEqual ( len ( f . read ( size ) ) , size ) <EOL> self . assertEqual ( len ( f . read ( size ) ) , size ) <EOL> def test_buffer_no_array ( self ) : <EOL> """<STR_LIT>""" <EOL> size = <NUM_LIT> <EOL> without_array = ByteBuffer . allocateDirect ( size ) <EOL> self . assertFalse ( without_array . hasArray ( ) ) <EOL> with_array = ByteBuffer . allocate ( size ) <EOL> self . assertTrue ( with_array . hasArray ( ) ) <EOL> bbs = [ with_array , without_array ] <EOL> for bb in bbs : <EOL> iis = InfiniteInputStream ( ) <EOL> io = StreamIO ( iis , True ) <EOL> self . assertEqual ( io . readinto ( bb ) , size ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
