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; |
11 const int _STDIO_HANDLE_TYPE_OTHER = 4; | 11 const int _STDIO_HANDLE_TYPE_OTHER = 4; |
12 | 12 |
13 | 13 |
14 class _StdStream extends Stream<List<int>> { | 14 class _StdStream extends Stream<List<int>> { |
15 final Stream<List<int>> _stream; | 15 final Stream<List<int>> _stream; |
16 | 16 |
17 _StdStream(Stream<List<int>> this._stream); | 17 _StdStream(this._stream); |
18 | 18 |
19 StreamSubscription<List<int>> listen(void onData(List<int> event), | 19 StreamSubscription<List<int>> listen(void onData(List<int> event), |
20 {Function onError, | 20 {Function onError, |
21 void onDone(), | 21 void onDone(), |
22 bool cancelOnError}) { | 22 bool cancelOnError}) { |
23 return _stream.listen( | 23 return _stream.listen( |
24 onData, | 24 onData, |
25 onError: onError, | 25 onError: onError, |
26 onDone: onDone, | 26 onDone: onDone, |
27 cancelOnError: cancelOnError); | 27 cancelOnError: cancelOnError); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 199 |
200 String toString() { | 200 String toString() { |
201 return "StdoutException: $message${osError == null ? "" : ", $osError"}"; | 201 return "StdoutException: $message${osError == null ? "" : ", $osError"}"; |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 | 205 |
206 class _StdSink implements IOSink { | 206 class _StdSink implements IOSink { |
207 final IOSink _sink; | 207 final IOSink _sink; |
208 | 208 |
209 _StdSink(IOSink this._sink); | 209 _StdSink(this._sink); |
210 | 210 |
211 Encoding get encoding => _sink.encoding; | 211 Encoding get encoding => _sink.encoding; |
212 void set encoding(Encoding encoding) { | 212 void set encoding(Encoding encoding) { |
213 _sink.encoding = encoding; | 213 _sink.encoding = encoding; |
214 } | 214 } |
215 void write(object) => _sink.write(object); | 215 void write(object) => _sink.write(object); |
216 void writeln([object = "" ]) => _sink.writeln(object); | 216 void writeln([object = "" ]) => _sink.writeln(object); |
217 void writeAll(objects, [sep = ""]) => _sink.writeAll(objects, sep); | 217 void writeAll(objects, [sep = ""]) => _sink.writeAll(objects, sep); |
218 void add(List<int> data) => _sink.add(data); | 218 void add(List<int> data) => _sink.add(data); |
219 void addError(error, [StackTrace stackTrace]) => | 219 void addError(error, [StackTrace stackTrace]) => |
220 _sink.addError(error, stackTrace); | 220 _sink.addError(error, stackTrace); |
221 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); | 221 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); |
222 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream); | 222 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream); |
223 Future flush() => _sink.flush(); | 223 Future flush() => _sink.flush(); |
224 Future close() => _sink.close(); | 224 Future close() => _sink.close(); |
225 Future get done => _sink.done; | 225 Future get done => _sink.done; |
226 } | 226 } |
227 | 227 |
228 /// The type of object a standard IO stream is attached to. | 228 /// The type of object a standard IO stream is attached to. |
229 class StdioType { | 229 class StdioType { |
230 static const StdioType TERMINAL = const StdioType._("terminal"); | 230 static const StdioType TERMINAL = const StdioType._("terminal"); |
231 static const StdioType PIPE = const StdioType._("pipe"); | 231 static const StdioType PIPE = const StdioType._("pipe"); |
232 static const StdioType FILE = const StdioType._("file"); | 232 static const StdioType FILE = const StdioType._("file"); |
233 static const StdioType OTHER = const StdioType._("other"); | 233 static const StdioType OTHER = const StdioType._("other"); |
234 final String name; | 234 final String name; |
235 const StdioType._(String this.name); | 235 const StdioType._(this.name); |
236 String toString() => "StdioType: $name"; | 236 String toString() => "StdioType: $name"; |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 Stdin _stdin; | 240 Stdin _stdin; |
241 Stdout _stdout; | 241 Stdout _stdout; |
242 IOSink _stderr; | 242 IOSink _stderr; |
243 | 243 |
244 | 244 |
245 /// The standard input stream of data read by this program. | 245 /// The standard input stream of data read by this program. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 298 } |
299 return StdioType.OTHER; | 299 return StdioType.OTHER; |
300 } | 300 } |
301 | 301 |
302 | 302 |
303 class _StdIOUtils { | 303 class _StdIOUtils { |
304 external static _getStdioOutputStream(int fd); | 304 external static _getStdioOutputStream(int fd); |
305 external static Stdin _getStdioInputStream(); | 305 external static Stdin _getStdioInputStream(); |
306 external static int _socketType(nativeSocket); | 306 external static int _socketType(nativeSocket); |
307 } | 307 } |
OLD | NEW |