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

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

Issue 11663004: Fix File.writeAsString to use named optional arguments. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_write_as_test.dart » ('j') | 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) 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 part of dart.io; 5 part of dart.io;
6 6
7 class _FileInputStream extends _BaseDataInputStream implements InputStream { 7 class _FileInputStream extends _BaseDataInputStream implements InputStream {
8 _FileInputStream(String name) 8 _FileInputStream(String name)
9 : _data = const [], 9 : _data = const [],
10 _position = 0, 10 _position = 0,
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 return completer.future; 676 return completer.future;
677 } 677 }
678 678
679 void writeAsBytesSync(List<int> bytes, [FileMode mode = FileMode.WRITE]) { 679 void writeAsBytesSync(List<int> bytes, [FileMode mode = FileMode.WRITE]) {
680 RandomAccessFile opened = openSync(mode); 680 RandomAccessFile opened = openSync(mode);
681 opened.writeListSync(bytes, 0, bytes.length); 681 opened.writeListSync(bytes, 0, bytes.length);
682 opened.closeSync(); 682 opened.closeSync();
683 } 683 }
684 684
685 Future<File> writeAsString(String contents, 685 Future<File> writeAsString(String contents,
686 [FileMode mode = FileMode.WRITE, 686 {FileMode mode: FileMode.WRITE,
687 Encoding encoding = Encoding.UTF_8]) { 687 Encoding encoding: Encoding.UTF_8}) {
688 try { 688 try {
689 var data = _StringEncoders.encoder(encoding).encodeString(contents); 689 var data = _StringEncoders.encoder(encoding).encodeString(contents);
690 return writeAsBytes(data, mode); 690 return writeAsBytes(data, mode);
691 } catch (e) { 691 } catch (e) {
692 var completer = new Completer(); 692 var completer = new Completer();
693 new Timer(0, (t) => completer.completeException(e)); 693 new Timer(0, (t) => completer.completeException(e));
694 return completer.future; 694 return completer.future;
695 } 695 }
696 } 696 }
697 697
698 void writeAsStringSync(String contents, 698 void writeAsStringSync(String contents,
699 [FileMode mode = FileMode.WRITE, 699 {FileMode mode: FileMode.WRITE,
700 Encoding encoding = Encoding.UTF_8]) { 700 Encoding encoding: Encoding.UTF_8}) {
701 var data = _StringEncoders.encoder(encoding).encodeString(contents); 701 var data = _StringEncoders.encoder(encoding).encodeString(contents);
702 writeAsBytesSync(data, mode); 702 writeAsBytesSync(data, mode);
703 } 703 }
704 704
705 String get name => _name; 705 String get name => _name;
706 706
707 void _ensureFileService() { 707 void _ensureFileService() {
708 if (_fileService == null) { 708 if (_fileService == null) {
709 _fileService = _FileUtils._newServicePort(); 709 _fileService = _FileUtils._newServicePort();
710 } 710 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 new FileIOException("File closed '$_name'")); 1159 new FileIOException("File closed '$_name'"));
1160 }); 1160 });
1161 return completer.future; 1161 return completer.future;
1162 } 1162 }
1163 1163
1164 final String _name; 1164 final String _name;
1165 int _id; 1165 int _id;
1166 1166
1167 SendPort _fileService; 1167 SendPort _fileService;
1168 } 1168 }
OLDNEW
« no previous file with comments | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_write_as_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698