# HG changeset patch # User Paul Boddie # Date 1102984484 -3600 # Node ID 6837caf38a992d83e46e9398fcd0b91addfd6577 # Parent 964002d174b744d7d773b760716030fdcf7574c4 Added some real behaviour to InputStream and added stream classes of use for java.lang.System. diff -r 964002d174b7 -r 6837caf38a99 java/io.py --- a/java/io.py Fri Dec 10 01:27:38 2004 +0100 +++ b/java/io.py Tue Dec 14 01:34:44 2004 +0100 @@ -1,6 +1,77 @@ #!/usr/bin/env python -class FilterOutputStream: +class InputStream(object): + def __init__(self, stream): + # NOTE: Python-only method. + self.stream = stream + def read___(self): + s = self.stream.read(1) + if s != "": + return -1 + else: + return ord(s) + def read____B__array_(self, b, off=0, length=None): + if b is None: + import java.lang + raise java.lang.NullPointerException + if len(b) == 0: + return 0 + if length is None: + length = len(b) + elif length + off > len(b): + import java.lang + raise java.lang.IndexOutOfBoundsException + s = self.stream.read(length) + if s == "": + return -1 + for i in range(0, length): + b[i + off] = s[i] + return len(s) + read____B__array_____I_____I_ = read____B__array_ + def skip(self, n): + number = 0 + for i in range(0, n): + s = self.stream.read(1) + if s == "": + break + number += 1 + return number + skip____L_ = skip + def available(self): + raise NotImplementedError, "available" + available___ = available + def close(self): + self.stream.close() + close___ = close + def mark(self, readlimit): + raise NotImplementedError, "mark" + mark___ = mark + def reset(self): + raise NotImplementedError, "reset" + reset___ = reset + def markSupported(self): + raise NotImplementedError, "markSupported" + markSupported___ = markSupported + +class IOException(Exception): + def __init__(self, *args): + self.args = args + +setattr(IOException, "__init_____", IOException.__init__) +setattr(IOException, "__init_____java__lang__String", IOException.__init__) + +class OutputStream(object): + def write(self, b, *args): + raise NotImplementedError, "write" + write___java__lang__String = write + def flush(self): + raise NotImplementedError, "flush" + flush___ = flush + def close(self): + raise NotImplementedError, "close" + close___ = close + +class FilterOutputStream(OutputStream): def __init__(self, out): self.out = out def write(self, value, *args): @@ -18,38 +89,46 @@ self.out.close() close___ = close -class InputStream: - def read(self, *args): - raise NotImplementedError, "read" - read___ = read - def skip(self, n): - raise NotImplementedError, "skip" - skip___int = skip - def available(self): - raise NotImplementedError, "available" - available___ = available +setattr(FilterOutputStream, "__init_____java__io__OutputStream", FilterOutputStream.__init__) + +class PrintStream(FilterOutputStream): + def init__out(self, out): + FilterOutputStream.__init__(self, out) + def init__out_autoFlush(self, out, autoFlush): + FilterOutputStream.__init__(self, out) + self.autoFlush = autoFlush + def checkError(self): + # NOTE: Implement properly. + self.flush() + checkError___ = checkError def close(self): - raise NotImplementedError, "close" + self.flush() + FilterOutputStream.close(self) close___ = close - def mark(self, readlimit): - raise NotImplementedError, "mark" - mark___ = mark - def reset(self): - raise NotImplementedError, "reset" - reset___ = reset - def markSupported(self): - raise NotImplementedError, "markSupported" - markSupported___ = markSupported + def flush(self): + FilterOutputStream.flush(self) + flush___ = flush + def print_(self, obj): + # NOTE: Check for arrays. + if isinstance(obj, list): + for i in obj: + self.print_(i) + else: + # NOTE: Using Python string conversion. + FilterOutputStream.write(self, unicode(obj)) + print____Z_ = print_ + print____C_ = print_ + print____C__array_ = print_ + print____D_ = print_ + print____F_ = print_ + print____I_ = print_ + print____L_ = print_ + print___java__lang__Object = print_ + print___java__lang__String = print_ -class OutputStream: - def write(self, b, *args): - raise NotImplementedError, "write" - write___java__lang__String = write - def flush(self): - raise NotImplementedError, "flush" - flush___ = flush - def close(self): - raise NotImplementedError, "close" - close___ = close + # NOTE: To be completed. + +setattr(PrintStream, "__init_____java__io__OutputStream", PrintStream.init__out) +setattr(PrintStream, "__init_____java__io__OutputStream____Z_", PrintStream.init__out_autoFlush) # vim: tabstop=4 expandtab shiftwidth=4