1 #!/usr/bin/env python 2 3 class InputStream(object): 4 def __init__(self, stream): 5 # NOTE: Python-only method. 6 self.stream = stream 7 def read___(self): 8 s = self.stream.read(1) 9 if s != "": 10 return -1 11 else: 12 return ord(s) 13 def read____B__array_(self, b, off=0, length=None): 14 if b is None: 15 import java.lang 16 raise java.lang.NullPointerException 17 if len(b) == 0: 18 return 0 19 if length is None: 20 length = len(b) 21 elif length + off > len(b): 22 import java.lang 23 raise java.lang.IndexOutOfBoundsException 24 s = self.stream.read(length) 25 if s == "": 26 return -1 27 for i in range(0, length): 28 b[i + off] = s[i] 29 return len(s) 30 read____B__array_____I_____I_ = read____B__array_ 31 def skip(self, n): 32 number = 0 33 for i in range(0, n): 34 s = self.stream.read(1) 35 if s == "": 36 break 37 number += 1 38 return number 39 skip____L_ = skip 40 def available(self): 41 raise NotImplementedError, "available" 42 available___ = available 43 def close(self): 44 self.stream.close() 45 close___ = close 46 def mark(self, readlimit): 47 raise NotImplementedError, "mark" 48 mark___ = mark 49 def reset(self): 50 raise NotImplementedError, "reset" 51 reset___ = reset 52 def markSupported(self): 53 raise NotImplementedError, "markSupported" 54 markSupported___ = markSupported 55 56 class IOException(Exception): 57 def __init__(self, *args): 58 self.args = args 59 60 setattr(IOException, "__init_____", IOException.__init__) 61 setattr(IOException, "__init_____java__lang__String", IOException.__init__) 62 63 class OutputStream(object): 64 def write(self, b, *args): 65 raise NotImplementedError, "write" 66 write___java__lang__String = write 67 def flush(self): 68 raise NotImplementedError, "flush" 69 flush___ = flush 70 def close(self): 71 raise NotImplementedError, "close" 72 close___ = close 73 74 class FilterOutputStream(OutputStream): 75 def __init__(self, out): 76 self.out = out 77 def write(self, value, *args): 78 if args: 79 start, length = args 80 self.out.write(value[start:start+length]) 81 else: 82 self.out.write(value) 83 write___java__lang__String = write 84 write___java__lang__String____I_____I_ = write 85 def flush(self): 86 self.out.flush() 87 flush___ = flush 88 def close(self): 89 self.out.close() 90 close___ = close 91 92 setattr(FilterOutputStream, "__init_____java__io__OutputStream", FilterOutputStream.__init__) 93 94 class PrintStream(FilterOutputStream): 95 def init__out(self, out): 96 FilterOutputStream.__init__(self, out) 97 def init__out_autoFlush(self, out, autoFlush): 98 FilterOutputStream.__init__(self, out) 99 self.autoFlush = autoFlush 100 def checkError(self): 101 # NOTE: Implement properly. 102 self.flush() 103 checkError___ = checkError 104 def close(self): 105 self.flush() 106 FilterOutputStream.close(self) 107 close___ = close 108 def flush(self): 109 FilterOutputStream.flush(self) 110 flush___ = flush 111 def print_(self, obj): 112 # NOTE: Check for arrays. 113 if isinstance(obj, list): 114 for i in obj: 115 self.print_(i) 116 else: 117 # NOTE: Using Python string conversion. 118 FilterOutputStream.write(self, unicode(obj)) 119 print____Z_ = print_ 120 print____C_ = print_ 121 print____C__array_ = print_ 122 print____D_ = print_ 123 print____F_ = print_ 124 print____I_ = print_ 125 print____L_ = print_ 126 print___java__lang__Object = print_ 127 print___java__lang__String = print_ 128 129 # NOTE: To be completed. 130 131 setattr(PrintStream, "__init_____java__io__OutputStream", PrintStream.init__out) 132 setattr(PrintStream, "__init_____java__io__OutputStream____Z_", PrintStream.init__out_autoFlush) 133 134 # vim: tabstop=4 expandtab shiftwidth=4