Chromium Code Reviews| 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 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * | 24 * |
| 25 * 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 |
| 26 * by the application immediately setting the data handler to `null` | 26 * by the application immediately setting the data handler to `null` |
| 27 * will avoid further callbacks until it is set to a function | 27 * will avoid further callbacks until it is set to a function |
| 28 * again. While the data handler is not active system flow control | 28 * again. While the data handler is not active system flow control |
| 29 * will be used to avoid buffering more data than needed. | 29 * will be used to avoid buffering more data than needed. |
| 30 * | 30 * |
| 31 * Always set up appropriate handlers when using input streams. | 31 * Always set up appropriate handlers when using input streams. |
| 32 * | 32 * |
| 33 */ | 33 */ |
| 34 interface InputStream { | 34 abstract class InputStream { |
| 35 /** | 35 /** |
| 36 * Reads data from the stream. Returns a system allocated buffer | 36 * Reads data from the stream. Returns a system allocated buffer |
| 37 * with up to [len] bytes. If no value is passed for [len] all | 37 * with up to [len] bytes. If no value is passed for [len] all |
| 38 * available data will be returned. If no data is available null will | 38 * available data will be returned. If no data is available null will |
| 39 * be returned. | 39 * be returned. |
| 40 */ | 40 */ |
| 41 List<int> read([int len]); | 41 List<int> read([int len]); |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * Reads up to [len] bytes into buffer [buffer] starting at offset | 44 * Reads up to [len] bytes into buffer [buffer] starting at offset |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 const Encoding._internal(String this.name); | 107 const Encoding._internal(String this.name); |
| 108 final String name; | 108 final String name; |
| 109 } | 109 } |
| 110 | 110 |
| 111 | 111 |
| 112 /** | 112 /** |
| 113 * A string input stream wraps a basic input stream and supplies | 113 * 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 | 114 * string data. This data can be read either as string chunks or as |
| 115 * lines separated by line termination character sequences. | 115 * lines separated by line termination character sequences. |
| 116 */ | 116 */ |
| 117 interface StringInputStream default _StringInputStream { | 117 abstract class StringInputStream { |
| 118 /** | 118 /** |
| 119 * Decodes a binary input stream into characters using the specified | 119 * Decodes a binary input stream into characters using the specified |
| 120 * encoding. The default encoding is UTF-8 - `Encoding.UTF_8`. | 120 * encoding. The default encoding is UTF-8 - `Encoding.UTF_8`. |
|
Søren Gjesse
2012/09/18 09:34:16
No need for documentation of the default value.
Mads Ager (google)
2012/09/18 10:46:39
Done.
| |
| 121 */ | 121 */ |
| 122 StringInputStream(InputStream input, [Encoding encoding]); | 122 factory StringInputStream(InputStream input, |
| 123 [Encoding encoding = Encoding.UTF_8]) { | |
| 124 return new _StringInputStream(input, encoding); | |
| 125 } | |
| 123 | 126 |
| 124 /** | 127 /** |
| 125 * Reads as many characters as is available from the stream. If no data is | 128 * Reads as many characters as is available from the stream. If no data is |
| 126 * available null will be returned. | 129 * available null will be returned. |
| 127 */ | 130 */ |
| 128 String read(); | 131 String read(); |
| 129 | 132 |
| 130 /** | 133 /** |
| 131 * Reads the next line from the stream. The line ending characters | 134 * Reads the next line from the stream. The line ending characters |
| 132 * will not be part of the returned string. If a full line is not | 135 * will not be part of the returned string. If a full line is not |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 * communication channel gets into some kind of error situation. | 183 * communication channel gets into some kind of error situation. |
| 181 */ | 184 */ |
| 182 void set onError(void callback(e)); | 185 void set onError(void callback(e)); |
| 183 } | 186 } |
| 184 | 187 |
| 185 | 188 |
| 186 /** | 189 /** |
| 187 * A chunked input stream wraps a basic input stream and supplies | 190 * A chunked input stream wraps a basic input stream and supplies |
| 188 * binary data in configurable chunk sizes. | 191 * binary data in configurable chunk sizes. |
| 189 */ | 192 */ |
| 190 interface ChunkedInputStream default _ChunkedInputStream { | 193 abstract class ChunkedInputStream { |
| 191 /** | 194 /** |
| 192 * Adds buffering to an input stream and provide the ability to read | 195 * Adds buffering to an input stream and provide the ability to read |
| 193 * the data in known size chunks. | 196 * the data in known size chunks. |
| 194 */ | 197 */ |
| 195 ChunkedInputStream(InputStream input, [int chunkSize]); | 198 factory ChunkedInputStream(InputStream input, [int chunkSize = 0]) { |
| 199 return new _ChunkedInputStream(input, chunkSize); | |
| 200 } | |
| 196 | 201 |
| 197 /** | 202 /** |
| 198 * Reads [chunkSize] bytes from the stream. If [chunkSize] bytes are | 203 * Reads [chunkSize] bytes from the stream. If [chunkSize] bytes are |
| 199 * not currently available null is returned. When the stream is | 204 * not currently available null is returned. When the stream is |
| 200 * closed the last call can return with less than [chunkSize] bytes. | 205 * closed the last call can return with less than [chunkSize] bytes. |
| 201 */ | 206 */ |
| 202 List<int> read(); | 207 List<int> read(); |
| 203 | 208 |
| 204 /** | 209 /** |
| 205 * Returns whether the stream has been closed. There might still be | 210 * Returns whether the stream has been closed. There might still be |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 void set onError(void callback(e)); | 242 void set onError(void callback(e)); |
| 238 } | 243 } |
| 239 | 244 |
| 240 | 245 |
| 241 class StreamException implements Exception { | 246 class StreamException implements Exception { |
| 242 const StreamException([String this.message = ""]); | 247 const StreamException([String this.message = ""]); |
| 243 const StreamException.streamClosed() : message = "Stream closed"; | 248 const StreamException.streamClosed() : message = "Stream closed"; |
| 244 String toString() => "StreamException: $message"; | 249 String toString() => "StreamException: $message"; |
| 245 final String message; | 250 final String message; |
| 246 } | 251 } |
| OLD | NEW |