| OLD | NEW |
| 1 // Copyright (c) 2011, 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. |
| 7 * |
| 6 * Input streams are used to read data sequentially from some data | 8 * Input streams are used to read data sequentially from some data |
| 7 * 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 |
| 8 * of read calls which will always return without any IO related | 10 * of read calls which will always return without any IO related |
| 9 * 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 |
| 10 * return [:null:]. All input streams have one or more handlers which | 12 * return [:null:]. All input streams have one or more handlers which |
| 11 * will trigger when data is available. | 13 * will trigger when data is available. |
| 12 * | 14 * |
| 13 * The following example shows a data handler in an ordinary input | 15 * The following example shows a data handler in an ordinary input |
| 14 * 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 |
| 15 * to read will not return [:null:]. | 17 * to read will not return [:null:]. |
| 16 * | 18 * |
| 17 * [: | 19 * [: |
| 18 * InputStream input = ... | 20 * InputStream input = ... |
| 19 * input.dataHandler = () { | 21 * input.dataHandler = () { |
| 20 * var data = input.read(); | 22 * var data = input.read(); |
| 21 * ... | 23 * ... |
| 22 * }; | 24 * }; |
| 23 * :] | 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 | |
| 34 /** | |
| 35 * Basic input stream which supplies binary data. | |
| 36 */ | 35 */ |
| 37 interface InputStream { | 36 interface InputStream { |
| 38 /** | 37 /** |
| 39 * Reads data from the stream. Returns a system allocated buffer | 38 * Reads data from the stream. Returns a system allocated buffer |
| 40 * with up to [len] bytes. If no value is passed for [len] all | 39 * with up to [len] bytes. If no value is passed for [len] all |
| 41 * available data will be returned. If no data is available null will | 40 * available data will be returned. If no data is available null will |
| 42 * be returned. | 41 * be returned. |
| 43 */ | 42 */ |
| 44 List<int> read([int len]); | 43 List<int> read([int len]); |
| 45 | 44 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 void set errorHandler(void callback()); | 217 void set errorHandler(void callback()); |
| 219 } | 218 } |
| 220 | 219 |
| 221 | 220 |
| 222 class StreamException implements Exception { | 221 class StreamException implements Exception { |
| 223 const StreamException([String this.message = ""]); | 222 const StreamException([String this.message = ""]); |
| 224 const StreamException.streamClosed() : message = "Stream closed"; | 223 const StreamException.streamClosed() : message = "Stream closed"; |
| 225 String toString() => "StreamException: $message"; | 224 String toString() => "StreamException: $message"; |
| 226 final String message; | 225 final String message; |
| 227 } | 226 } |
| OLD | NEW |