| 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 = -1; | 11 const int _STDIO_HANDLE_TYPE_OTHER = -1; |
| 12 | 12 |
| 13 | 13 |
| 14 class StdioType { | 14 class StdioType { |
| 15 static const StdioType TERMINAL = const StdioType._("terminal"); | 15 static const StdioType TERMINAL = const StdioType._("terminal"); |
| 16 static const StdioType PIPE = const StdioType._("pipe"); | 16 static const StdioType PIPE = const StdioType._("pipe"); |
| 17 static const StdioType FILE = const StdioType._("file"); | 17 static const StdioType FILE = const StdioType._("file"); |
| 18 static const StdioType OTHER = const StdioType._("other"); | 18 static const StdioType OTHER = const StdioType._("other"); |
| 19 const StdioType._(String this.name); | 19 const StdioType._(String this.name); |
| 20 final String name; | 20 final String name; |
| 21 } | 21 } |
| 22 | 22 |
| 23 | 23 |
| 24 InputStream _stdin; | 24 Stream<List<int>> _stdin; |
| 25 OutputStream _stdout; | 25 IOSink _stdout; |
| 26 OutputStream _stderr; | 26 IOSink _stderr; |
| 27 | 27 |
| 28 | 28 |
| 29 InputStream get stdin { | 29 Stream<List<int>> get stdin { |
| 30 if (_stdin == null) { | 30 if (_stdin == null) { |
| 31 _stdin = _StdIOUtils._getStdioInputStream(); | 31 _stdin = _StdIOUtils._getStdioInputStream(); |
| 32 } | 32 } |
| 33 return _stdin; | 33 return _stdin; |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 OutputStream get stdout { | 37 IOSink get stdout { |
| 38 if (_stdout == null) { | 38 if (_stdout == null) { |
| 39 _stdout = _StdIOUtils._getStdioOutputStream(1); | 39 _stdout = _StdIOUtils._getStdioOutputStream(1); |
| 40 } | 40 } |
| 41 return _stdout; | 41 return _stdout; |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 OutputStream get stderr { | 45 IOSink get stderr { |
| 46 if (_stderr == null) { | 46 if (_stderr == null) { |
| 47 _stderr = _StdIOUtils._getStdioOutputStream(2); | 47 _stderr = _StdIOUtils._getStdioOutputStream(2); |
| 48 } | 48 } |
| 49 return _stderr; | 49 return _stderr; |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 StdioType stdioType(object) { | 53 StdioType stdioType(object) { |
| 54 if (object is _FileOutputStream || object is _FileInputStream) { | 54 if (object is _FileStream) { |
| 55 return StdioType.FILE; | 55 return StdioType.FILE; |
| 56 } | 56 } |
| 57 if (object is !_SocketOutputStream && object is !_SocketInputStream) { | 57 if (object is Socket) { |
| 58 return StdioType.OTHER; | 58 switch (_StdIOUtils._socketType(object._nativeSocket)) { |
| 59 case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL; |
| 60 case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE; |
| 61 case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE; |
| 62 } |
| 59 } | 63 } |
| 60 switch (_StdIOUtils._socketType(object._socket)) { | 64 if (object is IOSink) { |
| 61 case _STDIO_HANDLE_TYPE_TERMINAL: return StdioType.TERMINAL; | 65 try { |
| 62 case _STDIO_HANDLE_TYPE_PIPE: return StdioType.PIPE; | 66 if (object._sink.target is _FileStreamConsumer) { |
| 63 case _STDIO_HANDLE_TYPE_FILE: return StdioType.FILE; | 67 return StdioType.FILE; |
| 64 default: return StdioType.OTHER; | 68 } |
| 69 } catch (e) { |
| 70 // Only the interface implemented, _sink not available. |
| 71 } |
| 65 } | 72 } |
| 73 return StdioType.OTHER; |
| 66 } | 74 } |
| 67 | 75 |
| 68 | 76 |
| 69 class _StdIOUtils { | 77 class _StdIOUtils { |
| 70 external static OutputStream _getStdioOutputStream(int fd); | 78 external static OutputStream _getStdioOutputStream(int fd); |
| 71 external static InputStream _getStdioInputStream(); | 79 external static InputStream _getStdioInputStream(); |
| 72 external static int _socketType(Socket socket); | 80 external static int _socketType(nativeSocket); |
| 73 } | 81 } |
| OLD | NEW |