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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 void add(List<int> data) => _sink.add(data); | 164 void add(List<int> data) => _sink.add(data); |
165 void addError(error, [StackTrace stackTrace]) => | 165 void addError(error, [StackTrace stackTrace]) => |
166 _sink.addError(error, stackTrace); | 166 _sink.addError(error, stackTrace); |
167 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); | 167 void writeCharCode(int charCode) => _sink.writeCharCode(charCode); |
168 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream); | 168 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream); |
169 Future flush() => _sink.flush(); | 169 Future flush() => _sink.flush(); |
170 Future close() => _sink.close(); | 170 Future close() => _sink.close(); |
171 Future get done => _sink.done; | 171 Future get done => _sink.done; |
172 } | 172 } |
173 | 173 |
| 174 /// The type of object a standard IO stream is attached to. |
174 class StdioType { | 175 class StdioType { |
175 static const StdioType TERMINAL = const StdioType._("terminal"); | 176 static const StdioType TERMINAL = const StdioType._("terminal"); |
176 static const StdioType PIPE = const StdioType._("pipe"); | 177 static const StdioType PIPE = const StdioType._("pipe"); |
177 static const StdioType FILE = const StdioType._("file"); | 178 static const StdioType FILE = const StdioType._("file"); |
178 static const StdioType OTHER = const StdioType._("other"); | 179 static const StdioType OTHER = const StdioType._("other"); |
179 final String name; | 180 final String name; |
180 const StdioType._(String this.name); | 181 const StdioType._(String this.name); |
181 String toString() => "StdioType: $name"; | 182 String toString() => "StdioType: $name"; |
182 } | 183 } |
183 | 184 |
184 | 185 |
185 Stdin _stdin; | 186 Stdin _stdin; |
186 IOSink _stdout; | 187 IOSink _stdout; |
187 IOSink _stderr; | 188 IOSink _stderr; |
188 | 189 |
189 | 190 |
| 191 /// The standard input stream of data read by this program. |
190 Stdin get stdin { | 192 Stdin get stdin { |
191 if (_stdin == null) { | 193 if (_stdin == null) { |
192 _stdin = _StdIOUtils._getStdioInputStream(); | 194 _stdin = _StdIOUtils._getStdioInputStream(); |
193 } | 195 } |
194 return _stdin; | 196 return _stdin; |
195 } | 197 } |
196 | 198 |
197 | 199 |
| 200 /// The standard output stream of data written by this program. |
198 IOSink get stdout { | 201 IOSink get stdout { |
199 if (_stdout == null) { | 202 if (_stdout == null) { |
200 _stdout = _StdIOUtils._getStdioOutputStream(1); | 203 _stdout = _StdIOUtils._getStdioOutputStream(1); |
201 } | 204 } |
202 return _stdout; | 205 return _stdout; |
203 } | 206 } |
204 | 207 |
205 | 208 |
| 209 /// The standard output stream of errors written by this program. |
206 IOSink get stderr { | 210 IOSink get stderr { |
207 if (_stderr == null) { | 211 if (_stderr == null) { |
208 _stderr = _StdIOUtils._getStdioOutputStream(2); | 212 _stderr = _StdIOUtils._getStdioOutputStream(2); |
209 } | 213 } |
210 return _stderr; | 214 return _stderr; |
211 } | 215 } |
212 | 216 |
213 | 217 |
| 218 /// For a stream, returns whether it is attached to a file, pipe, terminal, or |
| 219 /// something else. |
214 StdioType stdioType(object) { | 220 StdioType stdioType(object) { |
215 if (object is _StdStream) { | 221 if (object is _StdStream) { |
216 object = object._stream; | 222 object = object._stream; |
217 } else if (object is _StdSink) { | 223 } else if (object is _StdSink) { |
218 object = object._sink; | 224 object = object._sink; |
219 } | 225 } |
220 if (object is _FileStream) { | 226 if (object is _FileStream) { |
221 return StdioType.FILE; | 227 return StdioType.FILE; |
222 } | 228 } |
223 if (object is Socket) { | 229 if (object is Socket) { |
(...skipping 14 matching lines...) Expand all Loading... |
238 } | 244 } |
239 return StdioType.OTHER; | 245 return StdioType.OTHER; |
240 } | 246 } |
241 | 247 |
242 | 248 |
243 class _StdIOUtils { | 249 class _StdIOUtils { |
244 external static IOSink _getStdioOutputStream(int fd); | 250 external static IOSink _getStdioOutputStream(int fd); |
245 external static Stdin _getStdioInputStream(); | 251 external static Stdin _getStdioInputStream(); |
246 external static int _socketType(nativeSocket); | 252 external static int _socketType(nativeSocket); |
247 } | 253 } |
OLD | NEW |