OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
7 */ | 7 */ |
8 library io; | 8 library io; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 Future pipeInputToInput(InputStream source, ListInputStream sink) { | 575 Future pipeInputToInput(InputStream source, ListInputStream sink) { |
576 var completer = new Completer(); | 576 var completer = new Completer(); |
577 source.onClosed = () { | 577 source.onClosed = () { |
578 sink.markEndOfStream(); | 578 sink.markEndOfStream(); |
579 completer.complete(null); | 579 completer.complete(null); |
580 }; | 580 }; |
581 source.onData = () { | 581 source.onData = () { |
582 // Even if the sink is closed and we aren't going to do anything with more | 582 // Even if the sink is closed and we aren't going to do anything with more |
583 // data, we still need to drain it from source to work around issue 7218. | 583 // data, we still need to drain it from source to work around issue 7218. |
584 var data = source.read(); | 584 var data = source.read(); |
585 if (!sink.closed) sink.write(data); | 585 try { |
| 586 if (!sink.closed) sink.write(data); |
| 587 } on StreamException catch (e, stackTrace) { |
| 588 // Ignore an exception to work around issue 4222. |
| 589 log.io("Writing to an unclosed ListInputStream caused exception $e\n" |
| 590 "$stackTrace"); |
| 591 } |
586 }; | 592 }; |
587 // TODO(nweiz): propagate this error to the sink. See issue 3657. | 593 // TODO(nweiz): propagate this error to the sink. See issue 3657. |
588 source.onError = (e) { throw e; }; | 594 source.onError = (e) { throw e; }; |
589 return completer.future; | 595 return completer.future; |
590 } | 596 } |
591 | 597 |
592 /** | 598 /** |
593 * Buffers all input from an InputStream and returns it as a future. | 599 * Buffers all input from an InputStream and returns it as a future. |
594 */ | 600 */ |
595 Future<List<int>> consumeInputStream(InputStream stream) { | 601 Future<List<int>> consumeInputStream(InputStream stream) { |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 return new Directory(entry); | 1122 return new Directory(entry); |
1117 } | 1123 } |
1118 | 1124 |
1119 /** | 1125 /** |
1120 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1126 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1121 */ | 1127 */ |
1122 Uri _getUri(uri) { | 1128 Uri _getUri(uri) { |
1123 if (uri is Uri) return uri; | 1129 if (uri is Uri) return uri; |
1124 return new Uri.fromString(uri); | 1130 return new Uri.fromString(uri); |
1125 } | 1131 } |
OLD | NEW |