| 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); |
| 653 return readAsBytes().transform((bytes) { | 654 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); |
| 686 return readAsBytes().transform((bytes) { | 687 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 (_isClosed) return _completeWithClosedException(completer); | 719 if (_id == 0) { |
| 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 } |
| 720 _ensureFileService(); | 729 _ensureFileService(); |
| 721 List request = new List(2); | 730 List request = new List(2); |
| 722 request[0] = _FileUtils.kCloseRequest; | 731 request[0] = _FileUtils.kCloseRequest; |
| 723 request[1] = _id; | 732 request[1] = _id; |
| 724 // Set the id_ to 0 (NULL) to ensure the no more async requests | 733 // Set the id_ to 0 (NULL) to ensure the no more async requests |
| 725 // can be issues for this file. | 734 // can be issues for this file. |
| 726 _id = 0; | 735 _id = 0; |
| 727 _fileService.call(request).then((result) { | 736 _fileService.call(request).then((result) { |
| 728 if (result != -1) { | 737 if (result != -1) { |
| 729 _id = result; | 738 _id = result; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 740 var id = _FileUtils.close(_id); | 749 var id = _FileUtils.close(_id); |
| 741 if (id == -1) { | 750 if (id == -1) { |
| 742 throw new FileIOException("Cannot close file '$_name'"); | 751 throw new FileIOException("Cannot close file '$_name'"); |
| 743 } | 752 } |
| 744 _id = id; | 753 _id = id; |
| 745 } | 754 } |
| 746 | 755 |
| 747 Future<int> readByte() { | 756 Future<int> readByte() { |
| 748 _ensureFileService(); | 757 _ensureFileService(); |
| 749 Completer<int> completer = new Completer<int>(); | 758 Completer<int> completer = new Completer<int>(); |
| 750 if (_isClosed) return _completeWithClosedException(completer); | |
| 751 List request = new List(2); | 759 List request = new List(2); |
| 752 request[0] = _FileUtils.kReadByteRequest; | 760 request[0] = _FileUtils.kReadByteRequest; |
| 753 request[1] = _id; | 761 request[1] = _id; |
| 754 _fileService.call(request).then((response) { | 762 _fileService.call(request).then((response) { |
| 755 if (_isErrorResponse(response)) { | 763 if (_isErrorResponse(response)) { |
| 756 var e = _exceptionFromResponse(response, | 764 var e = _exceptionFromResponse(response, |
| 757 "readByte failed for file '$_name'"); | 765 "readByte failed for file '$_name'"); |
| 758 completer.completeException(e); | 766 completer.completeException(e); |
| 759 } else { | 767 } else { |
| 760 completer.complete(response); | 768 completer.complete(response); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 778 if (buffer is !List || offset is !int || bytes is !int) { | 786 if (buffer is !List || offset is !int || bytes is !int) { |
| 779 // Complete asynchronously so the user has a chance to setup | 787 // Complete asynchronously so the user has a chance to setup |
| 780 // handlers without getting exceptions when registering the | 788 // handlers without getting exceptions when registering the |
| 781 // then handler. | 789 // then handler. |
| 782 new Timer(0, (t) { | 790 new Timer(0, (t) { |
| 783 completer.completeException(new FileIOException( | 791 completer.completeException(new FileIOException( |
| 784 "Invalid arguments to readList for file '$_name'")); | 792 "Invalid arguments to readList for file '$_name'")); |
| 785 }); | 793 }); |
| 786 return completer.future; | 794 return completer.future; |
| 787 }; | 795 }; |
| 788 if (_isClosed) return _completeWithClosedException(completer); | |
| 789 List request = new List(3); | 796 List request = new List(3); |
| 790 request[0] = _FileUtils.kReadListRequest; | 797 request[0] = _FileUtils.kReadListRequest; |
| 791 request[1] = _id; | 798 request[1] = _id; |
| 792 request[2] = bytes; | 799 request[2] = bytes; |
| 793 _fileService.call(request).then((response) { | 800 _fileService.call(request).then((response) { |
| 794 if (_isErrorResponse(response)) { | 801 if (_isErrorResponse(response)) { |
| 795 var e = _exceptionFromResponse(response, | 802 var e = _exceptionFromResponse(response, |
| 796 "readList failed for file '$_name'"); | 803 "readList failed for file '$_name'"); |
| 797 completer.completeException(e); | 804 completer.completeException(e); |
| 798 } else { | 805 } else { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 if (value is !int) { | 838 if (value is !int) { |
| 832 // Complete asynchronously so the user has a chance to setup | 839 // Complete asynchronously so the user has a chance to setup |
| 833 // handlers without getting exceptions when registering the | 840 // handlers without getting exceptions when registering the |
| 834 // then handler. | 841 // then handler. |
| 835 new Timer(0, (t) { | 842 new Timer(0, (t) { |
| 836 completer.completeException(new FileIOException( | 843 completer.completeException(new FileIOException( |
| 837 "Invalid argument to writeByte for file '$_name'")); | 844 "Invalid argument to writeByte for file '$_name'")); |
| 838 }); | 845 }); |
| 839 return completer.future; | 846 return completer.future; |
| 840 } | 847 } |
| 841 if (_isClosed) return _completeWithClosedException(completer); | |
| 842 List request = new List(3); | 848 List request = new List(3); |
| 843 request[0] = _FileUtils.kWriteByteRequest; | 849 request[0] = _FileUtils.kWriteByteRequest; |
| 844 request[1] = _id; | 850 request[1] = _id; |
| 845 request[2] = value; | 851 request[2] = value; |
| 846 _fileService.call(request).then((response) { | 852 _fileService.call(request).then((response) { |
| 847 if (_isErrorResponse(response)) { | 853 if (_isErrorResponse(response)) { |
| 848 var e = _exceptionFromResponse(response, | 854 var e = _exceptionFromResponse(response, |
| 849 "writeByte failed for file '$_name'"); | 855 "writeByte failed for file '$_name'"); |
| 850 completer.completeException(e); | 856 completer.completeException(e); |
| 851 } else { | 857 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 875 if (buffer is !List || offset is !int || bytes is !int) { | 881 if (buffer is !List || offset is !int || bytes is !int) { |
| 876 // Complete asynchronously so the user has a chance to setup | 882 // Complete asynchronously so the user has a chance to setup |
| 877 // handlers without getting exceptions when registering the | 883 // handlers without getting exceptions when registering the |
| 878 // then handler. | 884 // then handler. |
| 879 new Timer(0, (t) { | 885 new Timer(0, (t) { |
| 880 completer.completeException(new FileIOException( | 886 completer.completeException(new FileIOException( |
| 881 "Invalid arguments to writeList for file '$_name'")); | 887 "Invalid arguments to writeList for file '$_name'")); |
| 882 }); | 888 }); |
| 883 return completer.future; | 889 return completer.future; |
| 884 } | 890 } |
| 885 if (_isClosed) return _completeWithClosedException(completer); | |
| 886 | 891 |
| 887 List result = | 892 List result = |
| 888 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); | 893 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); |
| 889 List outBuffer = result[0]; | 894 List outBuffer = result[0]; |
| 890 int outOffset = result[1]; | 895 int outOffset = result[1]; |
| 891 | 896 |
| 892 List request = new List(5); | 897 List request = new List(5); |
| 893 request[0] = _FileUtils.kWriteListRequest; | 898 request[0] = _FileUtils.kWriteListRequest; |
| 894 request[1] = _id; | 899 request[1] = _id; |
| 895 request[2] = outBuffer; | 900 request[2] = outBuffer; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 923 if (result is OSError) { | 928 if (result is OSError) { |
| 924 throw new FileIOException("writeList failed for file '$_name'", result); | 929 throw new FileIOException("writeList failed for file '$_name'", result); |
| 925 } | 930 } |
| 926 return result; | 931 return result; |
| 927 } | 932 } |
| 928 | 933 |
| 929 Future<RandomAccessFile> writeString(String string, | 934 Future<RandomAccessFile> writeString(String string, |
| 930 [Encoding encoding = Encoding.UTF_8]) { | 935 [Encoding encoding = Encoding.UTF_8]) { |
| 931 _ensureFileService(); | 936 _ensureFileService(); |
| 932 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 937 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 933 if (_isClosed) return _completeWithClosedException(completer); | |
| 934 List request = new List(3); | 938 List request = new List(3); |
| 935 request[0] = _FileUtils.kWriteStringRequest; | 939 request[0] = _FileUtils.kWriteStringRequest; |
| 936 request[1] = _id; | 940 request[1] = _id; |
| 937 request[2] = string; | 941 request[2] = string; |
| 938 _fileService.call(request).then((response) { | 942 _fileService.call(request).then((response) { |
| 939 if (_isErrorResponse(response)) { | 943 if (_isErrorResponse(response)) { |
| 940 var e = _exceptionFromResponse(response, | 944 var e = _exceptionFromResponse(response, |
| 941 "writeString failed for file '$_name'"); | 945 "writeString failed for file '$_name'"); |
| 942 completer.completeException(e); | 946 completer.completeException(e); |
| 943 } else { | 947 } else { |
| 944 completer.complete(this); | 948 completer.complete(this); |
| 945 } | 949 } |
| 946 }); | 950 }); |
| 947 return completer.future; | 951 return completer.future; |
| 948 } | 952 } |
| 949 | 953 |
| 950 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { | 954 int writeStringSync(String string, [Encoding encoding = Encoding.UTF_8]) { |
| 951 _checkNotClosed(); | 955 _checkNotClosed(); |
| 952 var result = _FileUtils.checkedWriteString(_id, string); | 956 var result = _FileUtils.checkedWriteString(_id, string); |
| 953 if (result is OSError) { | 957 if (result is OSError) { |
| 954 throw new FileIOException("writeString failed for file '$_name'", result); | 958 throw new FileIOException("writeString failed for file '$_name'", result); |
| 955 } | 959 } |
| 956 return result; | 960 return result; |
| 957 } | 961 } |
| 958 | 962 |
| 959 Future<int> position() { | 963 Future<int> position() { |
| 960 _ensureFileService(); | 964 _ensureFileService(); |
| 961 Completer<int> completer = new Completer<int>(); | 965 Completer<int> completer = new Completer<int>(); |
| 962 if (_isClosed) return _completeWithClosedException(completer); | |
| 963 List request = new List(2); | 966 List request = new List(2); |
| 964 request[0] = _FileUtils.kPositionRequest; | 967 request[0] = _FileUtils.kPositionRequest; |
| 965 request[1] = _id; | 968 request[1] = _id; |
| 966 _fileService.call(request).then((response) { | 969 _fileService.call(request).then((response) { |
| 967 if (_isErrorResponse(response)) { | 970 if (_isErrorResponse(response)) { |
| 968 var e = _exceptionFromResponse(response, | 971 var e = _exceptionFromResponse(response, |
| 969 "position failed for file '$_name'"); | 972 "position failed for file '$_name'"); |
| 970 completer.completeException(e); | 973 completer.completeException(e); |
| 971 } else { | 974 } else { |
| 972 completer.complete(response); | 975 completer.complete(response); |
| 973 } | 976 } |
| 974 }); | 977 }); |
| 975 return completer.future; | 978 return completer.future; |
| 976 } | 979 } |
| 977 | 980 |
| 978 int positionSync() { | 981 int positionSync() { |
| 979 _checkNotClosed(); | 982 _checkNotClosed(); |
| 980 var result = _FileUtils.position(_id); | 983 var result = _FileUtils.position(_id); |
| 981 if (result is OSError) { | 984 if (result is OSError) { |
| 982 throw new FileIOException("position failed for file '$_name'", result); | 985 throw new FileIOException("position failed for file '$_name'", result); |
| 983 } | 986 } |
| 984 return result; | 987 return result; |
| 985 } | 988 } |
| 986 | 989 |
| 987 Future<RandomAccessFile> setPosition(int position) { | 990 Future<RandomAccessFile> setPosition(int position) { |
| 988 _ensureFileService(); | 991 _ensureFileService(); |
| 989 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 992 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 990 if (_isClosed) return _completeWithClosedException(completer); | |
| 991 List request = new List(3); | 993 List request = new List(3); |
| 992 request[0] = _FileUtils.kSetPositionRequest; | 994 request[0] = _FileUtils.kSetPositionRequest; |
| 993 request[1] = _id; | 995 request[1] = _id; |
| 994 request[2] = position; | 996 request[2] = position; |
| 995 _fileService.call(request).then((response) { | 997 _fileService.call(request).then((response) { |
| 996 if (_isErrorResponse(response)) { | 998 if (_isErrorResponse(response)) { |
| 997 var e = _exceptionFromResponse(response, | 999 var e = _exceptionFromResponse(response, |
| 998 "setPosition failed for file '$_name'"); | 1000 "setPosition failed for file '$_name'"); |
| 999 completer.completeException(e); | 1001 completer.completeException(e); |
| 1000 } else { | 1002 } else { |
| 1001 completer.complete(this); | 1003 completer.complete(this); |
| 1002 } | 1004 } |
| 1003 }); | 1005 }); |
| 1004 return completer.future; | 1006 return completer.future; |
| 1005 } | 1007 } |
| 1006 | 1008 |
| 1007 void setPositionSync(int position) { | 1009 void setPositionSync(int position) { |
| 1008 _checkNotClosed(); | 1010 _checkNotClosed(); |
| 1009 var result = _FileUtils.setPosition(_id, position); | 1011 var result = _FileUtils.setPosition(_id, position); |
| 1010 if (result is OSError) { | 1012 if (result is OSError) { |
| 1011 throw new FileIOException("setPosition failed for file '$_name'", result); | 1013 throw new FileIOException("setPosition failed for file '$_name'", result); |
| 1012 } | 1014 } |
| 1013 } | 1015 } |
| 1014 | 1016 |
| 1015 Future<RandomAccessFile> truncate(int length) { | 1017 Future<RandomAccessFile> truncate(int length) { |
| 1016 _ensureFileService(); | 1018 _ensureFileService(); |
| 1017 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); | 1019 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); |
| 1018 if (_isClosed) return _completeWithClosedException(completer); | |
| 1019 List request = new List(3); | 1020 List request = new List(3); |
| 1020 request[0] = _FileUtils.kTruncateRequest; | 1021 request[0] = _FileUtils.kTruncateRequest; |
| 1021 request[1] = _id; | 1022 request[1] = _id; |
| 1022 request[2] = length; | 1023 request[2] = length; |
| 1023 _fileService.call(request).then((response) { | 1024 _fileService.call(request).then((response) { |
| 1024 if (_isErrorResponse(response)) { | 1025 if (_isErrorResponse(response)) { |
| 1025 var e = _exceptionFromResponse(response, | 1026 var e = _exceptionFromResponse(response, |
| 1026 "truncate failed for file '$_name'"); | 1027 "truncate failed for file '$_name'"); |
| 1027 completer.completeException(e); | 1028 completer.completeException(e); |
| 1028 } else { | 1029 } else { |
| 1029 completer.complete(this); | 1030 completer.complete(this); |
| 1030 } | 1031 } |
| 1031 }); | 1032 }); |
| 1032 return completer.future; | 1033 return completer.future; |
| 1033 } | 1034 } |
| 1034 | 1035 |
| 1035 void truncateSync(int length) { | 1036 void truncateSync(int length) { |
| 1036 _checkNotClosed(); | 1037 _checkNotClosed(); |
| 1037 var result = _FileUtils.truncate(_id, length); | 1038 var result = _FileUtils.truncate(_id, length); |
| 1038 if (result is OSError) { | 1039 if (result is OSError) { |
| 1039 throw new FileIOException("truncate failed for file '$_name'", result); | 1040 throw new FileIOException("truncate failed for file '$_name'", result); |
| 1040 } | 1041 } |
| 1041 } | 1042 } |
| 1042 | 1043 |
| 1043 Future<int> length() { | 1044 Future<int> length() { |
| 1044 _ensureFileService(); | 1045 _ensureFileService(); |
| 1045 Completer<int> completer = new Completer<int>(); | 1046 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); | |
| 1075 List request = new List(2); | 1074 List request = new List(2); |
| 1076 request[0] = _FileUtils.kFlushRequest; | 1075 request[0] = _FileUtils.kFlushRequest; |
| 1077 request[1] = _id; | 1076 request[1] = _id; |
| 1078 _fileService.call(request).then((response) { | 1077 _fileService.call(request).then((response) { |
| 1079 if (_isErrorResponse(response)) { | 1078 if (_isErrorResponse(response)) { |
| 1080 var e = _exceptionFromResponse(response, | 1079 var e = _exceptionFromResponse(response, |
| 1081 "flush failed for file '$_name'"); | 1080 "flush failed for file '$_name'"); |
| 1082 completer.completeException(e); | 1081 completer.completeException(e); |
| 1083 } else { | 1082 } else { |
| 1084 completer.complete(this); | 1083 completer.complete(this); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1096 } | 1095 } |
| 1097 | 1096 |
| 1098 String get name() => _name; | 1097 String get name() => _name; |
| 1099 | 1098 |
| 1100 void _ensureFileService() { | 1099 void _ensureFileService() { |
| 1101 if (_fileService == null) { | 1100 if (_fileService == null) { |
| 1102 _fileService = _FileUtils.newServicePort(); | 1101 _fileService = _FileUtils.newServicePort(); |
| 1103 } | 1102 } |
| 1104 } | 1103 } |
| 1105 | 1104 |
| 1106 bool get _isClosed() => _id == 0; | |
| 1107 | |
| 1108 void _checkNotClosed() { | 1105 void _checkNotClosed() { |
| 1109 if (_isClosed) { | 1106 if (_id == 0) { |
| 1110 throw new FileIOException("File closed '$_name'"); | 1107 throw new FileIOException("File closed '$_name'"); |
| 1111 } | 1108 } |
| 1112 } | 1109 } |
| 1113 | 1110 |
| 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 | |
| 1122 final String _name; | 1111 final String _name; |
| 1123 int _id; | 1112 int _id; |
| 1124 | 1113 |
| 1125 SendPort _fileService; | 1114 SendPort _fileService; |
| 1126 } | 1115 } |
| OLD | NEW |