| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Basic input stream which supplies binary data. | 6 * Basic input stream which supplies binary data. |
| 7 * | 7 * |
| 8 * Input streams are used to read data sequentially from some data | 8 * Input streams are used to read data sequentially from some data |
| 9 * source. All input streams are non-blocking. They each have a number | 9 * source. All input streams are non-blocking. They each have a number |
| 10 * of read calls which will always return without any IO related | 10 * of read calls which will always return without any IO related |
| 11 * blocking. If the requested data is not available a read call will | 11 * blocking. If the requested data is not available a read call will |
| 12 * return `null`. All input streams have one or more handlers which | 12 * return [:null:]. All input streams have one or more handlers which |
| 13 * will trigger when data is available. | 13 * will trigger when data is available. |
| 14 * | 14 * |
| 15 * The following example shows a data handler in an ordinary input | 15 * The following example shows a data handler in an ordinary input |
| 16 * stream which will be called when some data is available and a call | 16 * stream which will be called when some data is available and a call |
| 17 * to read will not return `null`. | 17 * to read will not return [:null:]. |
| 18 * | 18 * |
| 19 * InputStream input = ... | 19 * [: |
| 20 * input.onData = () { | 20 * InputStream input = ... |
| 21 * var data = input.read(); | 21 * input.onData = () { |
| 22 * ... | 22 * var data = input.read(); |
| 23 * }; | 23 * ... |
| 24 * }; |
| 25 * :] |
| 24 * | 26 * |
| 25 * If for some reason the data from an input stream cannot be handled | 27 * If for some reason the data from an input stream cannot be handled |
| 26 * by the application immediately setting the data handler to `null` | 28 * by the application immediately setting the data handler to [:null:] |
| 27 * will avoid further callbacks until it is set to a function | 29 * will avoid further callbacks until it is set to a function |
| 28 * again. While the data handler is not active system flow control | 30 * again. While the data handler is not active system flow control |
| 29 * will be used to avoid buffering more data than needed. | 31 * will be used to avoid buffering more data than needed. |
| 30 * | 32 * |
| 31 * Always set up appropriate handlers when using input streams. | 33 * Always set up appropriate handlers when using input streams. |
| 32 * | 34 * |
| 33 */ | 35 */ |
| 34 interface InputStream { | 36 interface InputStream { |
| 35 /** | 37 /** |
| 36 * Reads data from the stream. Returns a system allocated buffer | 38 * Reads data from the stream. Returns a system allocated buffer |
| (...skipping 13 matching lines...) Expand all Loading... |
| 50 | 52 |
| 51 /** | 53 /** |
| 52 * Returns the number of bytes available for immediate reading. | 54 * Returns the number of bytes available for immediate reading. |
| 53 */ | 55 */ |
| 54 int available(); | 56 int available(); |
| 55 | 57 |
| 56 /** | 58 /** |
| 57 * Pipe the content of this input stream directly to the output | 59 * Pipe the content of this input stream directly to the output |
| 58 * stream [output]. The default behavior is to close the output when | 60 * stream [output]. The default behavior is to close the output when |
| 59 * all the data from the input stream have been written. Specifying | 61 * all the data from the input stream have been written. Specifying |
| 60 * `false` for the optional argument [close] keeps the output | 62 * [:false:] for the optional argument [close] keeps the output |
| 61 * stream open after writing all data from the input stream. The | 63 * stream open after writing all data from the input stream. The |
| 62 * default value for [close] is `true`. | 64 * default value for [close] is [:true:]. |
| 63 */ | 65 */ |
| 64 void pipe(OutputStream output, [bool close]); | 66 void pipe(OutputStream output, [bool close]); |
| 65 | 67 |
| 66 /** | 68 /** |
| 67 * Close the underlying communication channel to avoid getting any | 69 * Close the underlying communication channel to avoid getting any |
| 68 * more data. In normal situations, where all data is read from the | 70 * more data. In normal situations, where all data is read from the |
| 69 * stream until the close handler is called, calling [close] is not | 71 * stream until the close handler is called, calling [close] is not |
| 70 * required. When [close] is used the close handler will still be | 72 * required. When [close] is used the close handler will still be |
| 71 * called. | 73 * called. |
| 72 */ | 74 */ |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 112 |
| 111 | 113 |
| 112 /** | 114 /** |
| 113 * A string input stream wraps a basic input stream and supplies | 115 * A string input stream wraps a basic input stream and supplies |
| 114 * string data. This data can be read either as string chunks or as | 116 * string data. This data can be read either as string chunks or as |
| 115 * lines separated by line termination character sequences. | 117 * lines separated by line termination character sequences. |
| 116 */ | 118 */ |
| 117 interface StringInputStream default _StringInputStream { | 119 interface StringInputStream default _StringInputStream { |
| 118 /** | 120 /** |
| 119 * Decodes a binary input stream into characters using the specified | 121 * Decodes a binary input stream into characters using the specified |
| 120 * encoding. The default encoding is UTF-8 - `Encoding.UTF_8`. | 122 * encoding. The default encoding is UTF-8 - [:Encoding.UTF_8:]. |
| 121 */ | 123 */ |
| 122 StringInputStream(InputStream input, [Encoding encoding]); | 124 StringInputStream(InputStream input, [Encoding encoding]); |
| 123 | 125 |
| 124 /** | 126 /** |
| 125 * Reads as many characters as is available from the stream. If no data is | 127 * Reads as many characters as is available from the stream. If no data is |
| 126 * available null will be returned. | 128 * available null will be returned. |
| 127 */ | 129 */ |
| 128 String read(); | 130 String read(); |
| 129 | 131 |
| 130 /** | 132 /** |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void set onError(void callback(e)); | 239 void set onError(void callback(e)); |
| 238 } | 240 } |
| 239 | 241 |
| 240 | 242 |
| 241 class StreamException implements Exception { | 243 class StreamException implements Exception { |
| 242 const StreamException([String this.message = ""]); | 244 const StreamException([String this.message = ""]); |
| 243 const StreamException.streamClosed() : message = "Stream closed"; | 245 const StreamException.streamClosed() : message = "Stream closed"; |
| 244 String toString() => "StreamException: $message"; | 246 String toString() => "StreamException: $message"; |
| 245 final String message; | 247 final String message; |
| 246 } | 248 } |
| OLD | NEW |