| 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 var file = new File(name); | 7 var file = new File(name); |
| 8 _data = []; | 8 _data = []; |
| 9 _position = 0; | 9 _position = 0; |
| 10 var chained = file.open(FileMode.READ).chain((openedFile) { | 10 var chained = file.open(FileMode.READ).chain((openedFile) { |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 var read = opened.readListSync(result, 0, length); | 643 var read = opened.readListSync(result, 0, length); |
| 644 if (read != length) { | 644 if (read != length) { |
| 645 throw new FileIOException("Failed to read file"); | 645 throw new FileIOException("Failed to read file"); |
| 646 } | 646 } |
| 647 opened.closeSync(); | 647 opened.closeSync(); |
| 648 return result; | 648 return result; |
| 649 } | 649 } |
| 650 | 650 |
| 651 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) { | 651 Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) { |
| 652 _ensureFileService(); | 652 _ensureFileService(); |
| 653 var decoder = _StringDecoders.decoder(encoding); | |
| 654 return readAsBytes().transform((bytes) { | 653 return readAsBytes().transform((bytes) { |
| 654 var decoder = _StringDecoders.decoder(encoding); |
| 655 decoder.write(bytes); | 655 decoder.write(bytes); |
| 656 return decoder.decoded; | 656 return decoder.decoded; |
| 657 }); | 657 }); |
| 658 } | 658 } |
| 659 | 659 |
| 660 String readAsTextSync([Encoding encoding = Encoding.UTF_8]) { | 660 String readAsTextSync([Encoding encoding = Encoding.UTF_8]) { |
| 661 var decoder = _StringDecoders.decoder(encoding); | 661 var decoder = _StringDecoders.decoder(encoding); |
| 662 List<int> bytes = readAsBytesSync(); | 662 List<int> bytes = readAsBytesSync(); |
| 663 decoder.write(bytes); | 663 decoder.write(bytes); |
| 664 return decoder.decoded; | 664 return decoder.decoded; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 676 var data = decoder.decoded; | 676 var data = decoder.decoded; |
| 677 if (data != null) { | 677 if (data != null) { |
| 678 result.add(data); | 678 result.add(data); |
| 679 } | 679 } |
| 680 return result; | 680 return result; |
| 681 } | 681 } |
| 682 | 682 |
| 683 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]) { | 683 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]) { |
| 684 _ensureFileService(); | 684 _ensureFileService(); |
| 685 Completer<List<String>> completer = new Completer<List<String>>(); | 685 Completer<List<String>> completer = new Completer<List<String>>(); |
| 686 var decoder = _StringDecoders.decoder(encoding); | |
| 687 return readAsBytes().transform((bytes) { | 686 return readAsBytes().transform((bytes) { |
| 687 var decoder = _StringDecoders.decoder(encoding); |
| 688 decoder.write(bytes); | 688 decoder.write(bytes); |
| 689 return _getDecodedLines(decoder); | 689 return _getDecodedLines(decoder); |
| 690 }); | 690 }); |
| 691 } | 691 } |
| 692 | 692 |
| 693 List<String> readAsLinesSync([Encoding encoding = Encoding.UTF_8]) { | 693 List<String> readAsLinesSync([Encoding encoding = Encoding.UTF_8]) { |
| 694 var decoder = _StringDecoders.decoder(encoding); | 694 var decoder = _StringDecoders.decoder(encoding); |
| 695 List<int> bytes = readAsBytesSync(); | 695 List<int> bytes = readAsBytesSync(); |
| 696 decoder.write(bytes); | 696 decoder.write(bytes); |
| 697 return _getDecodedLines(decoder); | 697 return _getDecodedLines(decoder); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 709 | 709 |
| 710 SendPort _fileService; | 710 SendPort _fileService; |
| 711 } | 711 } |
| 712 | 712 |
| 713 | 713 |
| 714 class _RandomAccessFile extends _FileBase implements RandomAccessFile { | 714 class _RandomAccessFile extends _FileBase implements RandomAccessFile { |
| 715 _RandomAccessFile(int this._id, String this._name); | 715 _RandomAccessFile(int this._id, String this._name); |
| 716 | 716 |
| 717 Future<RandomAccessFile> close() { | 717 Future<RandomAccessFile> close() { |
| 718 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 718 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 719 if (_id == 0) { | 719 if (_isClosed) return _completeWithClosedException(completer); |
| 720 // Complete asynchronously so the user has a chance to setup | |
| 721 // handlers without getting exceptions when registering the | |
| 722 // then handler. | |
| 723 new Timer(0, (t) { | |
| 724 completer.completeException( | |
| 725 new FileIOException("Cannot close file '$_name'")); | |
| 726 }); | |
| 727 return completer.future; | |
| 728 } | |
| 729 _ensureFileService(); | 720 _ensureFileService(); |
| 730 List request = new List(2); | 721 List request = new List(2); |
| 731 request[0] = _FileUtils.kCloseRequest; | 722 request[0] = _FileUtils.kCloseRequest; |
| 732 request[1] = _id; | 723 request[1] = _id; |
| 733 // Set the id_ to 0 (NULL) to ensure the no more async requests | 724 // Set the id_ to 0 (NULL) to ensure the no more async requests |
| 734 // can be issues for this file. | 725 // can be issues for this file. |
| 735 _id = 0; | 726 _id = 0; |
| 736 _fileService.call(request).then((result) { | 727 _fileService.call(request).then((result) { |
| 737 if (result != -1) { | 728 if (result != -1) { |
| 738 _id = result; | 729 _id = result; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 749 var id = _FileUtils.close(_id); | 740 var id = _FileUtils.close(_id); |
| 750 if (id == -1) { | 741 if (id == -1) { |
| 751 throw new FileIOException("Cannot close file '$_name'"); | 742 throw new FileIOException("Cannot close file '$_name'"); |
| 752 } | 743 } |
| 753 _id = id; | 744 _id = id; |
| 754 } | 745 } |
| 755 | 746 |
| 756 Future<int> readByte() { | 747 Future<int> readByte() { |
| 757 _ensureFileService(); | 748 _ensureFileService(); |
| 758 Completer<int> completer = new Completer<int>(); | 749 Completer<int> completer = new Completer<int>(); |
| 750 if (_isClosed) return _completeWithClosedException(completer); |
| 759 List request = new List(2); | 751 List request = new List(2); |
| 760 request[0] = _FileUtils.kReadByteRequest; | 752 request[0] = _FileUtils.kReadByteRequest; |
| 761 request[1] = _id; | 753 request[1] = _id; |
| 762 _fileService.call(request).then((response) { | 754 _fileService.call(request).then((response) { |
| 763 if (_isErrorResponse(response)) { | 755 if (_isErrorResponse(response)) { |
| 764 var e = _exceptionFromResponse(response, | 756 var e = _exceptionFromResponse(response, |
| 765 "readByte failed for file '$_name'"); | 757 "readByte failed for file '$_name'"); |
| 766 completer.completeException(e); | 758 completer.completeException(e); |
| 767 } else { | 759 } else { |
| 768 completer.complete(response); | 760 completer.complete(response); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 786 if (buffer is !List || offset is !int || bytes is !int) { | 778 if (buffer is !List || offset is !int || bytes is !int) { |
| 787 // Complete asynchronously so the user has a chance to setup | 779 // Complete asynchronously so the user has a chance to setup |
| 788 // handlers without getting exceptions when registering the | 780 // handlers without getting exceptions when registering the |
| 789 // then handler. | 781 // then handler. |
| 790 new Timer(0, (t) { | 782 new Timer(0, (t) { |
| 791 completer.completeException(new FileIOException( | 783 completer.completeException(new FileIOException( |
| 792 "Invalid arguments to readList for file '$_name'")); | 784 "Invalid arguments to readList for file '$_name'")); |
| 793 }); | 785 }); |
| 794 return completer.future; | 786 return completer.future; |
| 795 }; | 787 }; |
| 788 if (_isClosed) return _completeWithClosedException(completer); |
| 796 List request = new List(3); | 789 List request = new List(3); |
| 797 request[0] = _FileUtils.kReadListRequest; | 790 request[0] = _FileUtils.kReadListRequest; |
| 798 request[1] = _id; | 791 request[1] = _id; |
| 799 request[2] = bytes; | 792 request[2] = bytes; |
| 800 _fileService.call(request).then((response) { | 793 _fileService.call(request).then((response) { |
| 801 if (_isErrorResponse(response)) { | 794 if (_isErrorResponse(response)) { |
| 802 var e = _exceptionFromResponse(response, | 795 var e = _exceptionFromResponse(response, |
| 803 "readList failed for file '$_name'"); | 796 "readList failed for file '$_name'"); |
| 804 completer.completeException(e); | 797 completer.completeException(e); |
| 805 } else { | 798 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 if (value is !int) { | 831 if (value is !int) { |
| 839 // Complete asynchronously so the user has a chance to setup | 832 // Complete asynchronously so the user has a chance to setup |
| 840 // handlers without getting exceptions when registering the | 833 // handlers without getting exceptions when registering the |
| 841 // then handler. | 834 // then handler. |
| 842 new Timer(0, (t) { | 835 new Timer(0, (t) { |
| 843 completer.completeException(new FileIOException( | 836 completer.completeException(new FileIOException( |
| 844 "Invalid argument to writeByte for file '$_name'")); | 837 "Invalid argument to writeByte for file '$_name'")); |
| 845 }); | 838 }); |
| 846 return completer.future; | 839 return completer.future; |
| 847 } | 840 } |
| 841 if (_isClosed) return _completeWithClosedException(completer); |
| 848 List request = new List(3); | 842 List request = new List(3); |
| 849 request[0] = _FileUtils.kWriteByteRequest; | 843 request[0] = _FileUtils.kWriteByteRequest; |
| 850 request[1] = _id; | 844 request[1] = _id; |
| 851 request[2] = value; | 845 request[2] = value; |
| 852 _fileService.call(request).then((response) { | 846 _fileService.call(request).then((response) { |
| 853 if (_isErrorResponse(response)) { | 847 if (_isErrorResponse(response)) { |
| 854 var e = _exceptionFromResponse(response, | 848 var e = _exceptionFromResponse(response, |
| 855 "writeByte failed for file '$_name'"); | 849 "writeByte failed for file '$_name'"); |
| 856 completer.completeException(e); | 850 completer.completeException(e); |
| 857 } else { | 851 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 881 if (buffer is !List || offset is !int || bytes is !int) { | 875 if (buffer is !List || offset is !int || bytes is !int) { |
| 882 // Complete asynchronously so the user has a chance to setup | 876 // Complete asynchronously so the user has a chance to setup |
| 883 // handlers without getting exceptions when registering the | 877 // handlers without getting exceptions when registering the |
| 884 // then handler. | 878 // then handler. |
| 885 new Timer(0, (t) { | 879 new Timer(0, (t) { |
| 886 completer.completeException(new FileIOException( | 880 completer.completeException(new FileIOException( |
| 887 "Invalid arguments to writeList for file '$_name'")); | 881 "Invalid arguments to writeList for file '$_name'")); |
| 888 }); | 882 }); |
| 889 return completer.future; | 883 return completer.future; |
| 890 } | 884 } |
| 885 if (_isClosed) return _completeWithClosedException(completer); |
| 891 | 886 |
| 892 List result = | 887 List result = |
| 893 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); | 888 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); |
| 894 List outBuffer = result[0]; | 889 List outBuffer = result[0]; |
| 895 int outOffset = result[1]; | 890 int outOffset = result[1]; |
| 896 | 891 |
| 897 List request = new List(5); | 892 List request = new List(5); |
| 898 request[0] = _FileUtils.kWriteListRequest; | 893 request[0] = _FileUtils.kWriteListRequest; |
| 899 request[1] = _id; | 894 request[1] = _id; |
| 900 request[2] = outBuffer; | 895 request[2] = outBuffer; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 928 if (result is OSError) { | 923 if (result is OSError) { |
| 929 throw new FileIOException("writeList failed for file '$_name'", result); | 924 throw new FileIOException("writeList failed for file '$_name'", result); |
| 930 } | 925 } |
| 931 return result; | 926 return result; |
| 932 } | 927 } |
| 933 | 928 |
| 934 Future<RandomAccessFile> writeString(String string, | 929 Future<RandomAccessFile> writeString(String string, |
| 935 [Encoding encoding = Encoding.UTF_8]) { | 930 [Encoding encoding = Encoding.UTF_8]) { |
| 936 _ensureFileService(); | 931 _ensureFileService(); |
| 937 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 932 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 933 if (_isClosed) return _completeWithClosedException(completer); |
| 938 List request = new List(3); | 934 List request = new List(3); |
| 939 request[0] = _FileUtils.kWriteStringRequest; | 935 request[0] = _FileUtils.kWriteStringRequest; |
| 940 request[1] = _id; | 936 request[1] = _id; |
| 941 request[2] = string; | 937 request[2] = string; |
| 942 _fileService.call(request).then((response) { | 938 _fileService.call(request).then((response) { |
| 943 if (_isErrorResponse(response)) { | 939 if (_isErrorResponse(response)) { |
| 944 var e = _exceptionFromResponse(response, | 940 var e = _exceptionFromResponse(response, |
| 945 "writeString failed for file '$_name'"); | 941 "writeString failed for file '$_name'"); |
| 946 completer.completeException(e); | 942 completer.completeException(e); |
| 947 } else { | 943 } else { |
| 948 completer.complete(this); | 944 completer.complete(this); |
| 949 } | 945 } |
| 950 }); | 946 }); |
| 951 return completer.future; | 947 return completer.future; |
| 952 } | 948 } |
| 953 | 949 |
| 954 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { | 950 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { |
| 955 _checkNotClosed(); | 951 _checkNotClosed(); |
| 956 var result = _FileUtils.checkedWriteString(_id, string); | 952 var result = _FileUtils.checkedWriteString(_id, string); |
| 957 if (result is OSError) { | 953 if (result is OSError) { |
| 958 throw new FileIOException("writeString failed for file '$_name'", result); | 954 throw new FileIOException("writeString failed for file '$_name'", result); |
| 959 } | 955 } |
| 960 return result; | 956 return result; |
| 961 } | 957 } |
| 962 | 958 |
| 963 Future<int> position() { | 959 Future<int> position() { |
| 964 _ensureFileService(); | 960 _ensureFileService(); |
| 965 Completer<int> completer = new Completer<int>(); | 961 Completer<int> completer = new Completer<int>(); |
| 962 if (_isClosed) return _completeWithClosedException(completer); |
| 966 List request = new List(2); | 963 List request = new List(2); |
| 967 request[0] = _FileUtils.kPositionRequest; | 964 request[0] = _FileUtils.kPositionRequest; |
| 968 request[1] = _id; | 965 request[1] = _id; |
| 969 _fileService.call(request).then((response) { | 966 _fileService.call(request).then((response) { |
| 970 if (_isErrorResponse(response)) { | 967 if (_isErrorResponse(response)) { |
| 971 var e = _exceptionFromResponse(response, | 968 var e = _exceptionFromResponse(response, |
| 972 "position failed for file '$_name'"); | 969 "position failed for file '$_name'"); |
| 973 completer.completeException(e); | 970 completer.completeException(e); |
| 974 } else { | 971 } else { |
| 975 completer.complete(response); | 972 completer.complete(response); |
| 976 } | 973 } |
| 977 }); | 974 }); |
| 978 return completer.future; | 975 return completer.future; |
| 979 } | 976 } |
| 980 | 977 |
| 981 int positionSync() { | 978 int positionSync() { |
| 982 _checkNotClosed(); | 979 _checkNotClosed(); |
| 983 var result = _FileUtils.position(_id); | 980 var result = _FileUtils.position(_id); |
| 984 if (result is OSError) { | 981 if (result is OSError) { |
| 985 throw new FileIOException("position failed for file '$_name'", result); | 982 throw new FileIOException("position failed for file '$_name'", result); |
| 986 } | 983 } |
| 987 return result; | 984 return result; |
| 988 } | 985 } |
| 989 | 986 |
| 990 Future<RandomAccessFile> setPosition(int position) { | 987 Future<RandomAccessFile> setPosition(int position) { |
| 991 _ensureFileService(); | 988 _ensureFileService(); |
| 992 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 989 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 990 if (_isClosed) return _completeWithClosedException(completer); |
| 993 List request = new List(3); | 991 List request = new List(3); |
| 994 request[0] = _FileUtils.kSetPositionRequest; | 992 request[0] = _FileUtils.kSetPositionRequest; |
| 995 request[1] = _id; | 993 request[1] = _id; |
| 996 request[2] = position; | 994 request[2] = position; |
| 997 _fileService.call(request).then((response) { | 995 _fileService.call(request).then((response) { |
| 998 if (_isErrorResponse(response)) { | 996 if (_isErrorResponse(response)) { |
| 999 var e = _exceptionFromResponse(response, | 997 var e = _exceptionFromResponse(response, |
| 1000 "setPosition failed for file '$_name'"); | 998 "setPosition failed for file '$_name'"); |
| 1001 completer.completeException(e); | 999 completer.completeException(e); |
| 1002 } else { | 1000 } else { |
| 1003 completer.complete(this); | 1001 completer.complete(this); |
| 1004 } | 1002 } |
| 1005 }); | 1003 }); |
| 1006 return completer.future; | 1004 return completer.future; |
| 1007 } | 1005 } |
| 1008 | 1006 |
| 1009 void setPositionSync(int position) { | 1007 void setPositionSync(int position) { |
| 1010 _checkNotClosed(); | 1008 _checkNotClosed(); |
| 1011 var result = _FileUtils.setPosition(_id, position); | 1009 var result = _FileUtils.setPosition(_id, position); |
| 1012 if (result is OSError) { | 1010 if (result is OSError) { |
| 1013 throw new FileIOException("setPosition failed for file '$_name'", result); | 1011 throw new FileIOException("setPosition failed for file '$_name'", result); |
| 1014 } | 1012 } |
| 1015 } | 1013 } |
| 1016 | 1014 |
| 1017 Future<RandomAccessFile> truncate(int length) { | 1015 Future<RandomAccessFile> truncate(int length) { |
| 1018 _ensureFileService(); | 1016 _ensureFileService(); |
| 1019 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 1017 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 1018 if (_isClosed) return _completeWithClosedException(completer); |
| 1020 List request = new List(3); | 1019 List request = new List(3); |
| 1021 request[0] = _FileUtils.kTruncateRequest; | 1020 request[0] = _FileUtils.kTruncateRequest; |
| 1022 request[1] = _id; | 1021 request[1] = _id; |
| 1023 request[2] = length; | 1022 request[2] = length; |
| 1024 _fileService.call(request).then((response) { | 1023 _fileService.call(request).then((response) { |
| 1025 if (_isErrorResponse(response)) { | 1024 if (_isErrorResponse(response)) { |
| 1026 var e = _exceptionFromResponse(response, | 1025 var e = _exceptionFromResponse(response, |
| 1027 "truncate failed for file '$_name'"); | 1026 "truncate failed for file '$_name'"); |
| 1028 completer.completeException(e); | 1027 completer.completeException(e); |
| 1029 } else { | 1028 } else { |
| 1030 completer.complete(this); | 1029 completer.complete(this); |
| 1031 } | 1030 } |
| 1032 }); | 1031 }); |
| 1033 return completer.future; | 1032 return completer.future; |
| 1034 } | 1033 } |
| 1035 | 1034 |
| 1036 void truncateSync(int length) { | 1035 void truncateSync(int length) { |
| 1037 _checkNotClosed(); | 1036 _checkNotClosed(); |
| 1038 var result = _FileUtils.truncate(_id, length); | 1037 var result = _FileUtils.truncate(_id, length); |
| 1039 if (result is OSError) { | 1038 if (result is OSError) { |
| 1040 throw new FileIOException("truncate failed for file '$_name'", result); | 1039 throw new FileIOException("truncate failed for file '$_name'", result); |
| 1041 } | 1040 } |
| 1042 } | 1041 } |
| 1043 | 1042 |
| 1044 Future<int> length() { | 1043 Future<int> length() { |
| 1045 _ensureFileService(); | 1044 _ensureFileService(); |
| 1046 Completer<int> completer = new Completer<int>(); | 1045 Completer<int> completer = new Completer<int>(); |
| 1046 if (_isClosed) return _completeWithClosedException(completer); |
| 1047 List request = new List(2); | 1047 List request = new List(2); |
| 1048 request[0] = _FileUtils.kLengthRequest; | 1048 request[0] = _FileUtils.kLengthRequest; |
| 1049 request[1] = _id; | 1049 request[1] = _id; |
| 1050 _fileService.call(request).then((response) { | 1050 _fileService.call(request).then((response) { |
| 1051 if (_isErrorResponse(response)) { | 1051 if (_isErrorResponse(response)) { |
| 1052 var e = _exceptionFromResponse(response, | 1052 var e = _exceptionFromResponse(response, |
| 1053 "length failed for file '$_name'"); | 1053 "length failed for file '$_name'"); |
| 1054 completer.completeException(e); | 1054 completer.completeException(e); |
| 1055 } else { | 1055 } else { |
| 1056 completer.complete(response); | 1056 completer.complete(response); |
| 1057 } | 1057 } |
| 1058 }); | 1058 }); |
| 1059 return completer.future; | 1059 return completer.future; |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 int lengthSync() { | 1062 int lengthSync() { |
| 1063 _checkNotClosed(); | 1063 _checkNotClosed(); |
| 1064 var result = _FileUtils.length(_id); | 1064 var result = _FileUtils.length(_id); |
| 1065 if (result is OSError) { | 1065 if (result is OSError) { |
| 1066 throw new FileIOException("length failed for file '$_name'", result); | 1066 throw new FileIOException("length failed for file '$_name'", result); |
| 1067 } | 1067 } |
| 1068 return result; | 1068 return result; |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 Future<RandomAccessFile> flush() { | 1071 Future<RandomAccessFile> flush() { |
| 1072 _ensureFileService(); | 1072 _ensureFileService(); |
| 1073 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 1073 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 1074 if (_isClosed) return _completeWithClosedException(completer); |
| 1074 List request = new List(2); | 1075 List request = new List(2); |
| 1075 request[0] = _FileUtils.kFlushRequest; | 1076 request[0] = _FileUtils.kFlushRequest; |
| 1076 request[1] = _id; | 1077 request[1] = _id; |
| 1077 _fileService.call(request).then((response) { | 1078 _fileService.call(request).then((response) { |
| 1078 if (_isErrorResponse(response)) { | 1079 if (_isErrorResponse(response)) { |
| 1079 var e = _exceptionFromResponse(response, | 1080 var e = _exceptionFromResponse(response, |
| 1080 "flush failed for file '$_name'"); | 1081 "flush failed for file '$_name'"); |
| 1081 completer.completeException(e); | 1082 completer.completeException(e); |
| 1082 } else { | 1083 } else { |
| 1083 completer.complete(this); | 1084 completer.complete(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 String get name() => _name; | 1098 String get name() => _name; |
| 1098 | 1099 |
| 1099 void _ensureFileService() { | 1100 void _ensureFileService() { |
| 1100 if (_fileService == null) { | 1101 if (_fileService == null) { |
| 1101 _fileService = _FileUtils.newServicePort(); | 1102 _fileService = _FileUtils.newServicePort(); |
| 1102 } | 1103 } |
| 1103 } | 1104 } |
| 1104 | 1105 |
| 1106 bool get _isClosed() => _id == 0; |
| 1107 |
| 1105 void _checkNotClosed() { | 1108 void _checkNotClosed() { |
| 1106 if (_id == 0) { | 1109 if (_isClosed) { |
| 1107 throw new FileIOException("File closed '$_name'"); | 1110 throw new FileIOException("File closed '$_name'"); |
| 1108 } | 1111 } |
| 1109 } | 1112 } |
| 1110 | 1113 |
| 1114 Future _completeWithClosedException(Completer completer) { |
| 1115 new Timer(0, (t) { |
| 1116 completer.completeException( |
| 1117 new FileIOException("File closed '$_name'")); |
| 1118 }); |
| 1119 return completer.future; |
| 1120 } |
| 1121 |
| 1111 final String _name; | 1122 final String _name; |
| 1112 int _id; | 1123 int _id; |
| 1113 | 1124 |
| 1114 SendPort _fileService; | 1125 SendPort _fileService; |
| 1115 } | 1126 } |
| OLD | NEW |