lib/serialization: adds a method to detect unserializable type
[nit.git] / lib / standard / stream.nit
index 968cc8b..f161ebb 100644 (file)
@@ -11,7 +11,7 @@
 # another product.
 
 # Input and output streams of characters
-package stream
+module stream
 
 import string
 
@@ -61,7 +61,7 @@ interface IStream
                return s.to_s
        end
 
-       # Read a string until the end of the line and append it to `s'.
+       # Read a string until the end of the line and append it to `s`.
        fun append_line_to(s: Buffer)
        do
                loop
@@ -195,7 +195,7 @@ abstract class BufferedIStream
        # Is the last fill_buffer reach the end 
        protected fun end_reached: Bool is abstract
 
-       # Allocate a `_buffer' for a given `capacity'.
+       # Allocate a `_buffer` for a given `capacity`.
        protected fun prepare_buffer(capacity: Int)
        do
                _buffer = new Buffer.with_capacity(capacity)
@@ -296,3 +296,13 @@ redef interface Object
 
        private fun intern_poll( in_fds : Array[Int], out_fds : Array[Int] ) : nullable Int is extern import Array::length, Array::[], nullable Object as ( Int ), Int as nullable
 end
+
+# Stream to a String. Mainly used for compatibility with OStream type and tests.
+class StringOStream
+       super OStream
+
+       private var content = new Array[String]
+       redef fun to_s do return content.to_s
+       redef fun is_writable do return true
+       redef fun write(str) do content.add(str)
+end