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 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 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 var length = opened.lengthSync(); | 602 var length = opened.lengthSync(); |
603 var result = new Uint8List(length); | 603 var result = new Uint8List(length); |
604 var read = opened.readListSync(result, 0, length); | 604 var read = opened.readListSync(result, 0, length); |
605 if (read != length) { | 605 if (read != length) { |
606 throw new FileIOException("Failed to read file"); | 606 throw new FileIOException("Failed to read file"); |
607 } | 607 } |
608 opened.closeSync(); | 608 opened.closeSync(); |
609 return result; | 609 return result; |
610 } | 610 } |
611 | 611 |
612 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) { | 612 Future<String> readAsString([Encoding encoding = Encoding.UTF_8]) { |
613 _ensureFileService(); | 613 _ensureFileService(); |
614 return readAsBytes().transform((bytes) { | 614 return readAsBytes().transform((bytes) { |
615 if (bytes.length == 0) return ""; | 615 if (bytes.length == 0) return ""; |
616 var decoder = _StringDecoders.decoder(encoding); | 616 var decoder = _StringDecoders.decoder(encoding); |
617 decoder.write(bytes); | 617 decoder.write(bytes); |
618 return decoder.decoded(); | 618 return decoder.decoded(); |
619 }); | 619 }); |
620 } | 620 } |
621 | 621 |
622 String readAsTextSync([Encoding encoding = Encoding.UTF_8]) { | 622 String readAsStringSync([Encoding encoding = Encoding.UTF_8]) { |
623 var decoder = _StringDecoders.decoder(encoding); | 623 var decoder = _StringDecoders.decoder(encoding); |
624 List<int> bytes = readAsBytesSync(); | 624 List<int> bytes = readAsBytesSync(); |
625 if (bytes.length == 0) return ""; | 625 if (bytes.length == 0) return ""; |
626 decoder.write(bytes); | 626 decoder.write(bytes); |
627 return decoder.decoded(); | 627 return decoder.decoded(); |
628 } | 628 } |
629 | 629 |
630 List<String> _getDecodedLines(_StringDecoder decoder) { | 630 List<String> _getDecodedLines(_StringDecoder decoder) { |
631 List<String> result = []; | 631 List<String> result = []; |
632 var line = decoder.decodedLine; | 632 var line = decoder.decodedLine; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 new FileIOException("File closed '$_name'")); | 1080 new FileIOException("File closed '$_name'")); |
1081 }); | 1081 }); |
1082 return completer.future; | 1082 return completer.future; |
1083 } | 1083 } |
1084 | 1084 |
1085 final String _name; | 1085 final String _name; |
1086 int _id; | 1086 int _id; |
1087 | 1087 |
1088 SendPort _fileService; | 1088 SendPort _fileService; |
1089 } | 1089 } |
OLD | NEW |