Chromium Code Reviews| Index: runtime/bin/input_stream.dart |
| diff --git a/runtime/bin/input_stream.dart b/runtime/bin/input_stream.dart |
| index 48320138d136e70f4d746a33113404c3bbb1ee70..7575b0811569672e7d6aba5279b340297028edd4 100644 |
| --- a/runtime/bin/input_stream.dart |
| +++ b/runtime/bin/input_stream.dart |
| @@ -10,15 +10,109 @@ |
| */ |
| interface InputStream { |
| /** |
| - * Reads [len] bytes into [buffer] buffer starting at [offset] offset. |
| - * [callback] callback is invoked on completion unless it is null. |
| + * Reads data from the stream. Returns a system allocated buffer |
| + * with up to [len] bytes. If no value is passed for [len] all |
| + * available data will be returned. If no data is available null will |
| + * be returned. |
| */ |
| - bool read(List<int> buffer, int offset, int len, void callback()); |
| + List<int> read([int len]); |
| /** |
| - * Reads data from the stream into a buffer until a given [pattern] occurs and |
| - * hands that buffer over as an input to the registered [callback]. |
| - * The callback is not invoked if a read error occurs. |
| + * Reads up to [len] bytes into buffer [buffer] starting at offset |
| + * [offset]. Returns the number of bytes actually read which might |
| + * be zero. If [offset] is not specified 0 is used. If [len] is not |
| + * specified the length of [buffer] is used. |
| */ |
| - void readUntil(List<int> pattern, void callback(List<int> buffer)); |
| + int readInto(List<int> buffer, [int offset, int len]); |
| + |
| + /** |
| + * Returns the number of bytes available for immediate reading. |
| + */ |
| + int available(); |
| + |
| + /** |
| + * Returns whether the stream has been closed. There might still be |
| + * more data to read. |
| + */ |
| + bool closed(); |
| + |
| + /** |
| + * Sets the data handler gets called when data is available. |
|
Mads Ager (google)
2011/10/26 10:56:07
get called -> which gets called
As a separate cha
Søren Gjesse
2011/10/26 12:03:31
Done.
|
| + */ |
| + void set dataHandler(void callback()); |
| + |
| + /** |
| + * The close handler gets called when the underlying communication |
|
Mads Ager (google)
2011/10/26 10:56:07
As discussed offline we should rename to endHandle
Søren Gjesse
2011/10/26 12:03:31
Will do in a separate cl.
|
| + * channel is closed and no more data will become available. Not all |
| + * types of communication channels will emit close events. |
| + */ |
| + void set closeHandler(void callback()); |
| + |
| + /** |
| + * The error handler gets called when the underlying communication |
| + * channel gets into some kind of error situation. |
| + */ |
| + void set errorHandler(void callback()); |
| +} |
| + |
| + |
| +interface StringInputStream factory _StringInputStream { |
| + /** |
| + * Decodes a binary input stream into characters using the specified |
| + * encoding. |
| + */ |
| + StringInputStream(InputStream input, [String encoding]); |
| + |
| + /** |
| + * Reads as many characters as is available from the stream. If no data is |
| + * available null will be returned. |
| + */ |
| + String read(); |
| + |
| + /** |
| + * Reads the next line from the stream. The line ending characters |
| + * will not be part og the returned string. If a full line is not |
| + * available null will be returned.. |
|
Mads Ager (google)
2011/10/26 10:56:07
.. -> .
Søren Gjesse
2011/10/26 12:03:31
Done.
|
| + */ |
| + String readLine(); |
| + |
| + /** |
| + * Returns whether the stream has been closed. There might still be |
| + * more data to read. |
| + */ |
| + bool get closed(); |
|
Mads Ager (google)
2011/10/26 10:56:07
If we rename closeHandler to endHandler maybe this
Søren Gjesse
2011/10/26 12:03:31
Separate cl. Probably ended or maybe isEnded.
|
| + |
| + /** |
| + * Returns the encoding used to decode the binary data into characters. |
| + */ |
| + String get encoding(); |
| + |
| + /** |
| + * The data handler gets called when data is available. |
| + */ |
| + void set dataHandler(void callback()); |
| + |
| + /** |
| + * The close handler gets called when the underlying communication |
| + * channel is closed and no more data will become available. Not all |
| + * types of communication channels will emit close events. |
| + */ |
| + void set closeHandler(void callback()); |
| + |
| + /** |
| + * The error handler gets called when the underlying communication |
| + * channel gets into some kind of error situation. |
| + */ |
| + void set errorHandler(void callback()); |
| +} |
| + |
| + |
| +class StreamException implements Exception { |
| + const StreamException([String this.message = ""]); |
| + String toString() => "StreamException: $message"; |
| + |
| + /* |
| + * Contains the exception message. |
|
Mads Ager (google)
2011/10/26 10:56:07
Remove comment. Doesn't add much.
Søren Gjesse
2011/10/26 12:03:31
Done.
|
| + */ |
| + final String message; |
| } |