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

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

Issue 10945004: Make it possible to read a specific number of characters from a string input stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | runtime/bin/input_stream.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 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 opened.closeSync(); 715 opened.closeSync();
716 return result; 716 return result;
717 } 717 }
718 718
719 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) { 719 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) {
720 _ensureFileService(); 720 _ensureFileService();
721 return readAsBytes().transform((bytes) { 721 return readAsBytes().transform((bytes) {
722 if (bytes.length == 0) return ""; 722 if (bytes.length == 0) return "";
723 var decoder = _StringDecoders.decoder(encoding); 723 var decoder = _StringDecoders.decoder(encoding);
724 decoder.write(bytes); 724 decoder.write(bytes);
725 return decoder.decoded; 725 return decoder.decoded();
726 }); 726 });
727 } 727 }
728 728
729 String readAsTextSync([Encoding encoding = Encoding.UTF_8]) { 729 String readAsTextSync([Encoding encoding = Encoding.UTF_8]) {
730 var decoder = _StringDecoders.decoder(encoding); 730 var decoder = _StringDecoders.decoder(encoding);
731 List<int> bytes = readAsBytesSync(); 731 List<int> bytes = readAsBytesSync();
732 if (bytes.length == 0) return ""; 732 if (bytes.length == 0) return "";
733 decoder.write(bytes); 733 decoder.write(bytes);
734 return decoder.decoded; 734 return decoder.decoded();
735 } 735 }
736 736
737 List<String> _getDecodedLines(_StringDecoder decoder) { 737 List<String> _getDecodedLines(_StringDecoder decoder) {
738 List<String> result = []; 738 List<String> result = [];
739 var line = decoder.decodedLine; 739 var line = decoder.decodedLine;
740 while (line != null) { 740 while (line != null) {
741 result.add(line); 741 result.add(line);
742 line = decoder.decodedLine; 742 line = decoder.decodedLine;
743 } 743 }
744 // If there is more data with no terminating line break we treat 744 // If there is more data with no terminating line break we treat
745 // it as the last line. 745 // it as the last line.
746 var data = decoder.decoded; 746 var data = decoder.decoded();
747 if (data != null) { 747 if (data != null) {
748 result.add(data); 748 result.add(data);
749 } 749 }
750 return result; 750 return result;
751 } 751 }
752 752
753 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]) { 753 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]) {
754 _ensureFileService(); 754 _ensureFileService();
755 Completer<List<String>> completer = new Completer<List<String>>(); 755 Completer<List<String>> completer = new Completer<List<String>>();
756 return readAsBytes().transform((bytes) { 756 return readAsBytes().transform((bytes) {
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 new FileIOException("File closed '$_name'")); 1165 new FileIOException("File closed '$_name'"));
1166 }); 1166 });
1167 return completer.future; 1167 return completer.future;
1168 } 1168 }
1169 1169
1170 final String _name; 1170 final String _name;
1171 int _id; 1171 int _id;
1172 1172
1173 SendPort _fileService; 1173 SendPort _fileService;
1174 } 1174 }
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/input_stream.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698