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

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

Issue 230583002: Merge r34868 to trunk. (Closed) Base URL: https://dart.googlecode.com/svn/trunk/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 // Read the file in blocks of size 64k. 7 // Read the file in blocks of size 64k.
8 const int _BLOCK_SIZE = 64 * 1024; 8 const int _BLOCK_SIZE = 64 * 1024;
9 9
10 10
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 }, 445 },
446 onError: (e, StackTrace stackTrace) { 446 onError: (e, StackTrace stackTrace) {
447 completer.completeError(e, stackTrace); 447 completer.completeError(e, stackTrace);
448 }, 448 },
449 cancelOnError: true); 449 cancelOnError: true);
450 return completer.future; 450 return completer.future;
451 } 451 }
452 452
453 List<int> readAsBytesSync() { 453 List<int> readAsBytesSync() {
454 var opened = openSync(); 454 var opened = openSync();
455 var builder = new BytesBuilder(); 455 try {
456 var data; 456 var builder = new BytesBuilder();
457 while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) { 457 var data;
458 builder.add(data); 458 while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) {
459 builder.add(data);
460 }
461 return builder.takeBytes();
462 } finally {
463 opened.closeSync();
459 } 464 }
460 opened.closeSync();
461 return builder.takeBytes();
462 } 465 }
463 466
464 String _tryDecode(List<int> bytes, Encoding encoding) { 467 String _tryDecode(List<int> bytes, Encoding encoding) {
465 try { 468 try {
466 return encoding.decode(bytes); 469 return encoding.decode(bytes);
467 } catch (_) { 470 } catch (_) {
468 throw new FileSystemException( 471 throw new FileSystemException(
469 "Failed to decode data using encoding '${encoding.name}'", path); 472 "Failed to decode data using encoding '${encoding.name}'", path);
470 } 473 }
471 } 474 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 return sink.done.then((_) => this); 522 return sink.done.then((_) => this);
520 } catch (e) { 523 } catch (e) {
521 return new Future.error(e); 524 return new Future.error(e);
522 } 525 }
523 } 526 }
524 527
525 void writeAsBytesSync(List<int> bytes, 528 void writeAsBytesSync(List<int> bytes,
526 {FileMode mode: FileMode.WRITE, 529 {FileMode mode: FileMode.WRITE,
527 bool flush: false}) { 530 bool flush: false}) {
528 RandomAccessFile opened = openSync(mode: mode); 531 RandomAccessFile opened = openSync(mode: mode);
529 opened.writeFromSync(bytes, 0, bytes.length); 532 try {
530 if (flush) opened.flushSync(); 533 opened.writeFromSync(bytes, 0, bytes.length);
531 opened.closeSync(); 534 if (flush) opened.flushSync();
535 } finally {
536 opened.closeSync();
537 }
532 } 538 }
533 539
534 Future<File> writeAsString(String contents, 540 Future<File> writeAsString(String contents,
535 {FileMode mode: FileMode.WRITE, 541 {FileMode mode: FileMode.WRITE,
536 Encoding encoding: UTF8, 542 Encoding encoding: UTF8,
537 bool flush: false}) { 543 bool flush: false}) {
538 try { 544 try {
539 return writeAsBytes(encoding.encode(contents), mode: mode, flush: flush); 545 return writeAsBytes(encoding.encode(contents), mode: mode, flush: flush);
540 } catch (e) { 546 } catch (e) {
541 return new Future.error(e); 547 return new Future.error(e);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 907
902 void _checkAvailable() { 908 void _checkAvailable() {
903 if (_asyncDispatched) { 909 if (_asyncDispatched) {
904 throw new FileSystemException("An async operation is currently pending", p ath); 910 throw new FileSystemException("An async operation is currently pending", p ath);
905 } 911 }
906 if (closed) { 912 if (closed) {
907 throw new FileSystemException("File closed", path); 913 throw new FileSystemException("File closed", path);
908 } 914 }
909 } 915 }
910 } 916 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698