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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 /** | 94 /** |
95 * Sets the handler that gets called when the underlying | 95 * Sets the handler that gets called when the underlying |
96 * communication channel gets into some kind of error situation. | 96 * communication channel gets into some kind of error situation. |
97 */ | 97 */ |
98 void set onError(void callback()); | 98 void set onError(void callback()); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 /** | 102 /** |
| 103 * String encoding. |
| 104 */ |
| 105 interface Encoding { |
| 106 final String name; |
| 107 } |
| 108 |
| 109 |
| 110 /** |
| 111 * String encodings supported by [StringInputStream] and |
| 112 * [StringOutputStream]. |
| 113 */ |
| 114 interface Encodings { |
| 115 static final Encoding UTF_8 = const _Encoding("UTF-8"); |
| 116 static final Encoding ISO_8859_1 = const _Encoding("ISO-8859-1"); |
| 117 static final Encoding ASCII = const _Encoding("ASCII"); |
| 118 } |
| 119 |
| 120 |
| 121 /** |
103 * A string input stream wraps a basic input stream and supplies | 122 * A string input stream wraps a basic input stream and supplies |
104 * string data. This data can be read either as string chunks or as | 123 * string data. This data can be read either as string chunks or as |
105 * lines separated by line termination character sequences. | 124 * lines separated by line termination character sequences. |
106 */ | 125 */ |
107 interface StringInputStream default _StringInputStream { | 126 interface StringInputStream default _StringInputStream { |
108 /** | 127 /** |
109 * Decodes a binary input stream into characters using the specified | 128 * Decodes a binary input stream into characters using the specified |
110 * encoding. | 129 * encoding. The default encoding is UTF-8 - [:Encodings.UTF_8:]. |
111 */ | 130 */ |
112 StringInputStream(InputStream input, [String encoding]); | 131 StringInputStream(InputStream input, [Encoding encoding]); |
113 | 132 |
114 /** | 133 /** |
115 * Reads as many characters as is available from the stream. If no data is | 134 * Reads as many characters as is available from the stream. If no data is |
116 * available null will be returned. | 135 * available null will be returned. |
117 */ | 136 */ |
118 String read(); | 137 String read(); |
119 | 138 |
120 /** | 139 /** |
121 * Reads the next line from the stream. The line ending characters | 140 * Reads the next line from the stream. The line ending characters |
122 * will not be part of the returned string. If a full line is not | 141 * will not be part of the returned string. If a full line is not |
(...skipping 13 matching lines...) Expand all Loading... |
136 | 155 |
137 /** | 156 /** |
138 * Returns whether the stream has been closed. There might still be | 157 * Returns whether the stream has been closed. There might still be |
139 * more data to read. | 158 * more data to read. |
140 */ | 159 */ |
141 bool get closed(); | 160 bool get closed(); |
142 | 161 |
143 /** | 162 /** |
144 * Returns the encoding used to decode the binary data into characters. | 163 * Returns the encoding used to decode the binary data into characters. |
145 */ | 164 */ |
146 String get encoding(); | 165 Encoding get encoding(); |
147 | 166 |
148 /** | 167 /** |
149 * Sets the handler that gets called when data is available. The two | 168 * Sets the handler that gets called when data is available. The two |
150 * handlers [onData] and [onLine] are mutually exclusive | 169 * handlers [onData] and [onLine] are mutually exclusive |
151 * and setting one will remove the other. | 170 * and setting one will remove the other. |
152 */ | 171 */ |
153 void set onData(void callback()); | 172 void set onData(void callback()); |
154 | 173 |
155 /** | 174 /** |
156 * Sets the handler that gets called when a line is available. The | 175 * Sets the handler that gets called when a line is available. The |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 void set onError(void callback()); | 246 void set onError(void callback()); |
228 } | 247 } |
229 | 248 |
230 | 249 |
231 class StreamException implements Exception { | 250 class StreamException implements Exception { |
232 const StreamException([String this.message = ""]); | 251 const StreamException([String this.message = ""]); |
233 const StreamException.streamClosed() : message = "Stream closed"; | 252 const StreamException.streamClosed() : message = "Stream closed"; |
234 String toString() => "StreamException: $message"; | 253 String toString() => "StreamException: $message"; |
235 final String message; | 254 final String message; |
236 } | 255 } |
OLD | NEW |