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 patch class _StdIOUtils { | 5 patch class _StdIOUtils { |
6 static Stream<List<int>> _getStdioInputStream() { | 6 static Stream<List<int>> _getStdioInputStream() { |
7 switch (_getStdioHandleType(0)) { | 7 switch (_getStdioHandleType(0)) { |
8 case _STDIO_HANDLE_TYPE_TERMINAL: | 8 case _STDIO_HANDLE_TYPE_TERMINAL: |
9 case _STDIO_HANDLE_TYPE_PIPE: | 9 case _STDIO_HANDLE_TYPE_PIPE: |
10 case _STDIO_HANDLE_TYPE_SOCKET: | 10 case _STDIO_HANDLE_TYPE_SOCKET: |
11 return new _Socket._readPipe(0); | 11 return new _Socket._readPipe(0); |
12 case _STDIO_HANDLE_TYPE_FILE: | 12 case _STDIO_HANDLE_TYPE_FILE: |
13 return new _FileStream.forStdin(); | 13 return new _FileStream.forStdin(); |
14 default: | 14 default: |
15 throw new FileIOException("Unsupported stdin type"); | 15 throw new FileIOException("Unsupported stdin type"); |
16 } | 16 } |
17 } | 17 } |
18 | 18 |
19 static IOSink _getStdioOutputStream(int fd) { | 19 static IOSink _getStdioOutputStream(int fd) { |
20 assert(fd == 1 || fd == 2); | 20 assert(fd == 1 || fd == 2); |
21 switch (_getStdioHandleType(fd)) { | 21 switch (_getStdioHandleType(fd)) { |
22 case _STDIO_HANDLE_TYPE_TERMINAL: | 22 case _STDIO_HANDLE_TYPE_TERMINAL: |
23 case _STDIO_HANDLE_TYPE_PIPE: | 23 case _STDIO_HANDLE_TYPE_PIPE: |
24 case _STDIO_HANDLE_TYPE_SOCKET: | 24 case _STDIO_HANDLE_TYPE_SOCKET: |
25 return new _Socket._writePipe(fd); | 25 return new _Socket._writePipe(fd); |
26 case _STDIO_HANDLE_TYPE_FILE: | 26 case _STDIO_HANDLE_TYPE_FILE: |
27 return new IOSink(new _FileStreamConsumer.fromStdio(fd)); | 27 return new IOSink(new _FileStreamConsumer.fromStdio(fd), |
| 28 Encoding.ASCII); |
28 default: | 29 default: |
29 throw new FileIOException("Unsupported stdin type"); | 30 throw new FileIOException("Unsupported stdin type"); |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 static int _socketType(nativeSocket) { | 34 static int _socketType(nativeSocket) { |
34 return _getSocketType(nativeSocket); | 35 return _getSocketType(nativeSocket); |
35 } | 36 } |
36 } | 37 } |
37 | 38 |
38 | 39 |
39 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; | 40 _getStdioHandle(_NativeSocket socket, int num) native "Socket_GetStdioHandle"; |
40 _getStdioHandleType(int num) native "File_GetStdioHandleType"; | 41 _getStdioHandleType(int num) native "File_GetStdioHandleType"; |
41 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; | 42 _getSocketType(_NativeSocket nativeSocket) native "Socket_GetType"; |
OLD | NEW |