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

Side by Side Diff: runtime/bin/file_impl.dart

Issue 11345025: Use the encoding parameter for writeString on RandomAccessFile objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | tests/standalone/io/file_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 class _FileInputStream extends _BaseDataInputStream implements InputStream { 5 class _FileInputStream extends _BaseDataInputStream implements InputStream {
6 _FileInputStream(String name) 6 _FileInputStream(String name)
7 : _data = const [], 7 : _data = const [],
8 _position = 0, 8 _position = 0,
9 _filePosition = 0 { 9 _filePosition = 0 {
10 var file = new File(name); 10 var file = new File(name);
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 var result = 895 var result =
896 _writeList(_id, bufferAndOffset.buffer, bufferAndOffset.offset, bytes); 896 _writeList(_id, bufferAndOffset.buffer, bufferAndOffset.offset, bytes);
897 if (result is OSError) { 897 if (result is OSError) {
898 throw new FileIOException("writeList failed for file '$_name'", result); 898 throw new FileIOException("writeList failed for file '$_name'", result);
899 } 899 }
900 return result; 900 return result;
901 } 901 }
902 902
903 Future<RandomAccessFile> writeString(String string, 903 Future<RandomAccessFile> writeString(String string,
904 [Encoding encoding = Encoding.UTF_8]) { 904 [Encoding encoding = Encoding.UTF_8]) {
905 _ensureFileService(); 905 var data = _StringEncoders.encoder(encoding).encodeString(string);
906 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 906 return writeList(data, 0, data.length);
907 if (closed) return _completeWithClosedException(completer);
908 List request = new List(3);
909 request[0] = _WRITE_STRING_REQUEST;
Søren Gjesse 2012/10/30 10:24:31 Shouldn't we fully remove the write string request
Mads Ager (google) 2012/10/30 11:34:05 Whoops! Good catch. Yes we should.
910 request[1] = _id;
911 request[2] = string;
912 return _fileService.call(request).transform((response) {
913 if (_isErrorResponse(response)) {
914 throw _exceptionFromResponse(response,
915 "writeString failed for file '$_name'");
916 }
917 return this;
918 });
919 } 907 }
920 908
921 static _writeString(int id, String string) native "File_WriteString"; 909 static _writeString(int id, String string) native "File_WriteString";
922 910
923 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { 911 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) {
924 _checkNotClosed(); 912 var data = _StringEncoders.encoder(encoding).encodeString(string);
925 if (string is !String) throw new ArgumentError(); 913 return writeListSync(data, 0, data.length);
926 var result = _writeString(_id, string);
927 if (result is OSError) {
928 throw new FileIOException("writeString failed for file '$_name'");
929 }
930 return result;
931 } 914 }
932 915
933 Future<int> position() { 916 Future<int> position() {
934 _ensureFileService(); 917 _ensureFileService();
935 Completer<int> completer = new Completer<int>(); 918 Completer<int> completer = new Completer<int>();
936 if (closed) return _completeWithClosedException(completer); 919 if (closed) return _completeWithClosedException(completer);
937 List request = new List(2); 920 List request = new List(2);
938 request[0] = _POSITION_REQUEST; 921 request[0] = _POSITION_REQUEST;
939 request[1] = _id; 922 request[1] = _id;
940 return _fileService.call(request).transform((response) { 923 return _fileService.call(request).transform((response) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 new FileIOException("File closed '$_name'")); 1069 new FileIOException("File closed '$_name'"));
1087 }); 1070 });
1088 return completer.future; 1071 return completer.future;
1089 } 1072 }
1090 1073
1091 final String _name; 1074 final String _name;
1092 int _id; 1075 int _id;
1093 1076
1094 SendPort _fileService; 1077 SendPort _fileService;
1095 } 1078 }
OLDNEW
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698