from org.python.core.util import FileUtil from java.io import InputStream class InfiniteInputStream(InputStream): def read(self, *args): if len(args) == 0: return ord('x') elif len(args) == 1: return InputStream.read(self, args[0]) else: return self.read_buffer(*args) def read_buffer(self, buf, off, length): if length > 0: buf[off] = ord('x') return 1 return 0 iis = InfiniteInputStream() f = FileUtil.wrap(iis, 'rb') size = 10000 print len(f.read(size)), '?=', size print len(f.read(size)), '?=', size print len(f.read(size)), '?=', size