OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; | 7 const int _STDIO_HANDLE_TYPE_TERMINAL = 0; |
8 const int _STDIO_HANDLE_TYPE_PIPE = 1; | 8 const int _STDIO_HANDLE_TYPE_PIPE = 1; |
9 const int _STDIO_HANDLE_TYPE_FILE = 2; | 9 const int _STDIO_HANDLE_TYPE_FILE = 2; |
10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; | 10 const int _STDIO_HANDLE_TYPE_SOCKET = 3; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 final OSError osError; | 184 final OSError osError; |
185 | 185 |
186 const StdoutException(this.message, [this.osError]); | 186 const StdoutException(this.message, [this.osError]); |
187 | 187 |
188 String toString() { | 188 String toString() { |
189 return "StdoutException: $message${osError == null ? "" : ", $osError"}"; | 189 return "StdoutException: $message${osError == null ? "" : ", $osError"}"; |
190 } | 190 } |
191 } | 191 } |
192 | 192 |
193 | 193 |
| 194 class _StdConsumer implements StreamConsumer<List<int>> { |
| 195 final _file; |
| 196 |
| 197 _StdConsumer(int fd) : _file = _File._openStdioSync(fd); |
| 198 |
| 199 Future addStream(Stream<List<int>> stream) { |
| 200 var completer = new Completer(); |
| 201 var sub; |
| 202 sub = stream.listen( |
| 203 (data) { |
| 204 try { |
| 205 _file.writeFromSync(data); |
| 206 } catch (e, s) { |
| 207 sub.cancel(); |
| 208 completer.completeError(e, s); |
| 209 } |
| 210 }, |
| 211 onError: completer.completeError, |
| 212 onDone: completer.complete, |
| 213 cancelOnError: true); |
| 214 return completer.future; |
| 215 } |
| 216 |
| 217 Future close() { |
| 218 _file.closeSync(); |
| 219 return new Future.value(); |
| 220 } |
| 221 } |
| 222 |
| 223 |
194 class _StdSink implements IOSink { | 224 class _StdSink implements IOSink { |
195 final IOSink _sink; | 225 final IOSink _sink; |
196 | 226 |
197 _StdSink(this._sink); | 227 _StdSink(this._sink); |
198 | 228 |
199 Encoding get encoding => _sink.encoding; | 229 Encoding get encoding => _sink.encoding; |
200 void set encoding(Encoding encoding) { | 230 void set encoding(Encoding encoding) { |
201 _sink.encoding = encoding; | 231 _sink.encoding = encoding; |
202 } | 232 } |
203 void write(object) => _sink.write(object); | 233 void write(object) => _sink.write(object); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 return StdioType.OTHER; | 321 return StdioType.OTHER; |
292 } | 322 } |
293 | 323 |
294 | 324 |
295 class _StdIOUtils { | 325 class _StdIOUtils { |
296 external static _getStdioOutputStream(int fd); | 326 external static _getStdioOutputStream(int fd); |
297 external static Stdin _getStdioInputStream(); | 327 external static Stdin _getStdioInputStream(); |
298 external static int _socketType(nativeSocket); | 328 external static int _socketType(nativeSocket); |
299 external static _getStdioHandleType(int fd); | 329 external static _getStdioHandleType(int fd); |
300 } | 330 } |
OLD | NEW |