javaclass

java/io.py

114:2420bedaf184
2005-01-10 Paul Boddie Moved the lang module contents into the lang package. Fixed various java.lang and java.io circular imports by introducing a java.lang._object module. Corrected various base classes (object -> java.lang.Object, Exception -> java.lang.Exception) and fixed raising of exceptions in certain cases. Added reflection capabilities.
     1 #!/usr/bin/env python     2      3 from java.lang._object import Object, NullPointerException, IndexOutOfBoundsException, Exception as _Exception     4      5 class InputStream(Object):     6     def __init__(self, stream):     7         # NOTE: Python-only method.     8         self.stream = stream     9     def read___(self):    10         s = self.stream.read(1)    11         if s != "":    12             return -1    13         else:    14             return ord(s)    15     def read____B__array_(self, b, off=0, length=None):    16         if b is None:    17             raise Exception, NullPointerException()    18         if len(b) == 0:    19             return 0    20         if length is None:    21             length = len(b)    22         elif length + off > len(b):    23             raise Exception, 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, ending=""):   112         # NOTE: Check for arrays.   113         if isinstance(obj, list):   114             for i in obj:   115                 self.print_(i, ending)   116         else:   117             # NOTE: Using Python string conversion.   118             FilterOutputStream.write(self, unicode(obj) + ending)   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     def println(self, obj):   130         self.print_(obj, "\n")   131     println____Z_ = println   132     println____C_ = println   133     println____C__array_ = println   134     println____D_ = println   135     println____F_ = println   136     println____I_ = println   137     println____L_ = println   138     println___java__lang__Object = println   139     println___java__lang__String = println   140    141     # NOTE: To be completed.   142    143 setattr(PrintStream, "__init_____java__io__OutputStream", PrintStream.init__out)   144 setattr(PrintStream, "__init_____java__io__OutputStream____Z_", PrintStream.init__out_autoFlush)   145    146 # vim: tabstop=4 expandtab shiftwidth=4