update NOTICE and LICENSE
[nit.git] / lib / filter_stream.nit
index bcd01be..66366c6 100644 (file)
@@ -1,6 +1,7 @@
 # This file is part of NIT ( http://www.nitlanguage.org ).
 #
 # Copyright 2006 Floréal Morandat <morandat@lirmm.fr>
+# Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
 #
 # This file is free software, which comes along with NIT.  This software is
 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
@@ -11,9 +12,9 @@
 # another product.
 
 class FilterIStream
-special IStream
+       super IStream
        # Filter readed elements
-       readable var _stream: IStream 
+       readable var _stream: nullable IStream
 
        redef fun eof: Bool
        do
@@ -21,16 +22,16 @@ special IStream
                return stream.eof
        end
 
-       private fun stream=(i: IStream)
+       private fun stream=(i: nullable IStream)
        do
                _stream = i
        end
 end
 
 class FilterOStream
-special OStream
+       super OStream
        # Filter outputed elements
-       readable var _stream: OStream 
+       readable var _stream: nullable OStream
 
        # Can the stream be used to write
        redef fun is_writable: Bool
@@ -46,7 +47,7 @@ special OStream
 end
 
 class StreamCat
-special FilterIStream
+       super FilterIStream
        var _streams: Iterator[IStream]
 
        redef fun eof: Bool
@@ -62,7 +63,7 @@ special FilterIStream
                end
        end
 
-       redef fun stream: IStream
+       redef fun stream: nullable IStream
        do
                if _stream == null and _streams.is_ok then
                        stream = _streams.item
@@ -97,7 +98,7 @@ special FilterIStream
 end
 
 class StreamDemux
-special FilterOStream
+       super FilterOStream
        var _streams: Array[OStream]
 
        redef fun is_writable: Bool
@@ -126,6 +127,15 @@ special FilterOStream
                end
        end
 
+       redef fun close
+       do
+               for i in _streams
+               do
+                       stream = i
+                       stream.close
+               end
+       end
+
        init with_streams(streams: Array[OStream])
        do
                _streams = streams