Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: sdk/lib/io/stdio.dart

Issue 2761673002: [dart:io][windows] Use WriteFile instead of _write (Closed)
Patch Set: Format stdio.dart Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 * the output is written. 176 * the output is written.
177 * 177 *
178 * In some situations this blocking behavior is undesirable as it does not 178 * In some situations this blocking behavior is undesirable as it does not
179 * provide the same non-blocking behavior as dart:io in general exposes. 179 * provide the same non-blocking behavior as dart:io in general exposes.
180 * Use the property [nonBlocking] to get an `IOSink` which has the non-blocking 180 * Use the property [nonBlocking] to get an `IOSink` which has the non-blocking
181 * behavior. 181 * behavior.
182 * 182 *
183 * This class can also be used to check whether `stdout` or `stderr` is 183 * This class can also be used to check whether `stdout` or `stderr` is
184 * connected to a terminal and query some terminal properties. 184 * connected to a terminal and query some terminal properties.
185 */ 185 */
186 class Stdout extends _StdFileSink implements IOSink { 186 class Stdout extends _StdSink implements IOSink {
187 final int _fd; 187 final int _fd;
188 IOSink _nonBlocking; 188 IOSink _nonBlocking;
189 189
190 Stdout._(IOSink sink, this._fd) : super(sink); 190 Stdout._(IOSink sink, this._fd) : super(sink);
191 191
192 /** 192 /**
193 * Returns true if there is a terminal attached to stdout. 193 * Returns true if there is a terminal attached to stdout.
194 */ 194 */
195 bool get hasTerminal => _hasTerminal(_fd); 195 bool get hasTerminal => _hasTerminal(_fd);
196 196
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 cancelOnError: true); 293 cancelOnError: true);
294 return completer.future; 294 return completer.future;
295 } 295 }
296 296
297 Future close() { 297 Future close() {
298 _file.closeSync(); 298 _file.closeSync();
299 return new Future.value(); 299 return new Future.value();
300 } 300 }
301 } 301 }
302 302
303 class _StdSinkHelper implements IOSink { 303 class _StdSink implements IOSink {
304 final IOSink _sink; 304 final IOSink _sink;
305 final bool _isTranslatable; 305 final bool _isTranslatable;
306 306
307 _StdSinkHelper(this._sink, this._isTranslatable); 307 _StdSink(this._sink);
308 308
309 Encoding get encoding => _sink.encoding; 309 Encoding get encoding => _sink.encoding;
310 void set encoding(Encoding encoding) { 310 void set encoding(Encoding encoding) {
311 _sink.encoding = encoding; 311 _sink.encoding = encoding;
312 } 312 }
313 313
314 void set _translation(_FileTranslation t) {
315 if (_isTranslatable) {
316 _IOSinkImpl sink = _sink;
317 _StdConsumer target = sink._target;
318 target._file.translation = t;
319 }
320 }
321
322 void write(object) { 314 void write(object) {
323 _translation = _FileTranslation.text;
324 _sink.write(object); 315 _sink.write(object);
325 } 316 }
326 317
327 void writeln([object = ""]) { 318 void writeln([object = ""]) {
328 _translation = _FileTranslation.text;
329 _sink.writeln(object); 319 _sink.writeln(object);
330 } 320 }
331 321
332 void writeAll(objects, [sep = ""]) { 322 void writeAll(objects, [sep = ""]) {
333 _translation = _FileTranslation.text;
334 _sink.writeAll(objects, sep); 323 _sink.writeAll(objects, sep);
335 } 324 }
336 325
337 void add(List<int> data) { 326 void add(List<int> data) {
338 _translation = _FileTranslation.binary;
339 _sink.add(data); 327 _sink.add(data);
340 } 328 }
341 329
342 void addError(error, [StackTrace stackTrace]) { 330 void addError(error, [StackTrace stackTrace]) {
343 _sink.addError(error, stackTrace); 331 _sink.addError(error, stackTrace);
344 } 332 }
345 333
346 void writeCharCode(int charCode) { 334 void writeCharCode(int charCode) {
347 _translation = _FileTranslation.text;
348 _sink.writeCharCode(charCode); 335 _sink.writeCharCode(charCode);
349 } 336 }
350 337
351 Future addStream(Stream<List<int>> stream) { 338 Future addStream(Stream<List<int>> stream) => _sink.addStream(stream);
352 _translation = _FileTranslation.binary;
353 return _sink.addStream(stream);
354 }
355
356 Future flush() => _sink.flush(); 339 Future flush() => _sink.flush();
357 Future close() => _sink.close(); 340 Future close() => _sink.close();
358 Future get done => _sink.done; 341 Future get done => _sink.done;
359 } 342 }
360 343
361 class _StdFileSink extends _StdSinkHelper {
362 // The target of `sink` is expected to be a _StdConsumer.
363 _StdFileSink(IOSink sink) : super(sink, true);
364 }
365
366 class _StdSocketSink extends _StdSinkHelper {
367 _StdSocketSink(IOSink sink) : super(sink, false);
368 }
369
370 /// The type of object a standard IO stream is attached to. 344 /// The type of object a standard IO stream is attached to.
371 class StdioType { 345 class StdioType {
372 static const StdioType TERMINAL = const StdioType._("terminal"); 346 static const StdioType TERMINAL = const StdioType._("terminal");
373 static const StdioType PIPE = const StdioType._("pipe"); 347 static const StdioType PIPE = const StdioType._("pipe");
374 static const StdioType FILE = const StdioType._("file"); 348 static const StdioType FILE = const StdioType._("file");
375 static const StdioType OTHER = const StdioType._("other"); 349 static const StdioType OTHER = const StdioType._("other");
376 final String name; 350 final String name;
377 const StdioType._(this.name); 351 const StdioType._(this.name);
378 String toString() => "StdioType: $name"; 352 String toString() => "StdioType: $name";
379 } 353 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 423 }
450 424
451 class _StdIOUtils { 425 class _StdIOUtils {
452 external static _getStdioOutputStream(int fd); 426 external static _getStdioOutputStream(int fd);
453 external static Stdin _getStdioInputStream(); 427 external static Stdin _getStdioInputStream();
454 428
455 /// Returns the socket type or `null` if [socket] is not a builtin socket. 429 /// Returns the socket type or `null` if [socket] is not a builtin socket.
456 external static int _socketType(Socket socket); 430 external static int _socketType(Socket socket);
457 external static _getStdioHandleType(int fd); 431 external static _getStdioHandleType(int fd);
458 } 432 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698