javaclass

Change of java/io.py

88:6837caf38a99
java/io.py
     1.1 --- a/java/io.py	Fri Dec 10 01:27:38 2004 +0100
     1.2 +++ b/java/io.py	Tue Dec 14 01:34:44 2004 +0100
     1.3 @@ -1,6 +1,77 @@
     1.4  #!/usr/bin/env python
     1.5  
     1.6 -class FilterOutputStream:
     1.7 +class InputStream(object):
     1.8 +    def __init__(self, stream):
     1.9 +        # NOTE: Python-only method.
    1.10 +        self.stream = stream
    1.11 +    def read___(self):
    1.12 +        s = self.stream.read(1)
    1.13 +        if s != "":
    1.14 +            return -1
    1.15 +        else:
    1.16 +            return ord(s)
    1.17 +    def read____B__array_(self, b, off=0, length=None):
    1.18 +        if b is None:
    1.19 +            import java.lang
    1.20 +            raise java.lang.NullPointerException
    1.21 +        if len(b) == 0:
    1.22 +            return 0
    1.23 +        if length is None:
    1.24 +            length = len(b)
    1.25 +        elif length + off > len(b):
    1.26 +            import java.lang
    1.27 +            raise java.lang.IndexOutOfBoundsException
    1.28 +        s = self.stream.read(length)
    1.29 +        if s == "":
    1.30 +            return -1
    1.31 +        for i in range(0, length):
    1.32 +            b[i + off] = s[i]
    1.33 +        return len(s)
    1.34 +    read____B__array_____I_____I_ = read____B__array_ 
    1.35 +    def skip(self, n):
    1.36 +        number = 0
    1.37 +        for i in range(0, n):
    1.38 +            s = self.stream.read(1)
    1.39 +            if s == "":
    1.40 +                break
    1.41 +            number += 1
    1.42 +        return number
    1.43 +    skip____L_ = skip
    1.44 +    def available(self):
    1.45 +        raise NotImplementedError, "available"
    1.46 +    available___ = available
    1.47 +    def close(self):
    1.48 +        self.stream.close()
    1.49 +    close___ = close
    1.50 +    def mark(self, readlimit):
    1.51 +        raise NotImplementedError, "mark"
    1.52 +    mark___ = mark
    1.53 +    def reset(self):
    1.54 +        raise NotImplementedError, "reset"
    1.55 +    reset___ = reset
    1.56 +    def markSupported(self):
    1.57 +        raise NotImplementedError, "markSupported"
    1.58 +    markSupported___ = markSupported
    1.59 +
    1.60 +class IOException(Exception):
    1.61 +    def __init__(self, *args):
    1.62 +        self.args = args
    1.63 +
    1.64 +setattr(IOException, "__init_____", IOException.__init__)
    1.65 +setattr(IOException, "__init_____java__lang__String", IOException.__init__)
    1.66 +
    1.67 +class OutputStream(object):
    1.68 +    def write(self, b, *args):
    1.69 +        raise NotImplementedError, "write"
    1.70 +    write___java__lang__String = write
    1.71 +    def flush(self):
    1.72 +        raise NotImplementedError, "flush"
    1.73 +    flush___ = flush
    1.74 +    def close(self):
    1.75 +        raise NotImplementedError, "close"
    1.76 +    close___ = close
    1.77 +
    1.78 +class FilterOutputStream(OutputStream):
    1.79      def __init__(self, out):
    1.80          self.out = out
    1.81      def write(self, value, *args):
    1.82 @@ -18,38 +89,46 @@
    1.83          self.out.close()
    1.84      close___ = close
    1.85  
    1.86 -class InputStream:
    1.87 -    def read(self, *args):
    1.88 -        raise NotImplementedError, "read"
    1.89 -    read___ = read
    1.90 -    def skip(self, n):
    1.91 -        raise NotImplementedError, "skip"
    1.92 -    skip___int = skip
    1.93 -    def available(self):
    1.94 -        raise NotImplementedError, "available"
    1.95 -    available___ = available
    1.96 +setattr(FilterOutputStream, "__init_____java__io__OutputStream", FilterOutputStream.__init__)
    1.97 +
    1.98 +class PrintStream(FilterOutputStream):
    1.99 +    def init__out(self, out):
   1.100 +        FilterOutputStream.__init__(self, out)
   1.101 +    def init__out_autoFlush(self, out, autoFlush):
   1.102 +        FilterOutputStream.__init__(self, out)
   1.103 +        self.autoFlush = autoFlush
   1.104 +    def checkError(self):
   1.105 +        # NOTE: Implement properly.
   1.106 +        self.flush()
   1.107 +    checkError___ = checkError
   1.108      def close(self):
   1.109 -        raise NotImplementedError, "close"
   1.110 +        self.flush()
   1.111 +        FilterOutputStream.close(self)
   1.112      close___ = close
   1.113 -    def mark(self, readlimit):
   1.114 -        raise NotImplementedError, "mark"
   1.115 -    mark___ = mark
   1.116 -    def reset(self):
   1.117 -        raise NotImplementedError, "reset"
   1.118 -    reset___ = reset
   1.119 -    def markSupported(self):
   1.120 -        raise NotImplementedError, "markSupported"
   1.121 -    markSupported___ = markSupported
   1.122 +    def flush(self):
   1.123 +        FilterOutputStream.flush(self)
   1.124 +    flush___ = flush
   1.125 +    def print_(self, obj):
   1.126 +        # NOTE: Check for arrays.
   1.127 +        if isinstance(obj, list):
   1.128 +            for i in obj:
   1.129 +                self.print_(i)
   1.130 +        else:
   1.131 +            # NOTE: Using Python string conversion.
   1.132 +            FilterOutputStream.write(self, unicode(obj))
   1.133 +    print____Z_ = print_
   1.134 +    print____C_ = print_
   1.135 +    print____C__array_ = print_
   1.136 +    print____D_ = print_
   1.137 +    print____F_ = print_
   1.138 +    print____I_ = print_
   1.139 +    print____L_ = print_
   1.140 +    print___java__lang__Object = print_
   1.141 +    print___java__lang__String = print_
   1.142  
   1.143 -class OutputStream:
   1.144 -    def write(self, b, *args):
   1.145 -        raise NotImplementedError, "write"
   1.146 -    write___java__lang__String = write
   1.147 -    def flush(self):
   1.148 -        raise NotImplementedError, "flush"
   1.149 -    flush___ = flush
   1.150 -    def close(self):
   1.151 -        raise NotImplementedError, "close"
   1.152 -    close___ = close
   1.153 +    # NOTE: To be completed.
   1.154 +
   1.155 +setattr(PrintStream, "__init_____java__io__OutputStream", PrintStream.init__out)
   1.156 +setattr(PrintStream, "__init_____java__io__OutputStream____Z_", PrintStream.init__out_autoFlush)
   1.157  
   1.158  # vim: tabstop=4 expandtab shiftwidth=4