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