| 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 _file = new File(name); | 7 _file = new File(name); |
| 8 _data = []; | 8 _data = []; |
| 9 _position = 0; | 9 _position = 0; |
| 10 _file.onError = (e) { | 10 _file.onError = (e) { |
| (...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 String _name; | 696 String _name; |
| 697 | 697 |
| 698 SendPort _fileService; | 698 SendPort _fileService; |
| 699 } | 699 } |
| 700 | 700 |
| 701 | 701 |
| 702 class _RandomAccessFile extends _FileBase implements RandomAccessFile { | 702 class _RandomAccessFile extends _FileBase implements RandomAccessFile { |
| 703 _RandomAccessFile(int this._id, String this._name); | 703 _RandomAccessFile(int this._id, String this._name); |
| 704 | 704 |
| 705 void close(void callback()) { | 705 void close(void callback()) { |
| 706 if (_id == 0) return; | 706 if (_id == 0) { |
| 707 if (_onError != null) { |
| 708 _onError(new FileIOException("Cannot close file: $_name")); |
| 709 } |
| 710 return; |
| 711 } |
| 707 _ensureFileService(); | 712 _ensureFileService(); |
| 708 List request = new List(2); | 713 List request = new List(2); |
| 709 request[0] = _FileUtils.kCloseRequest; | 714 request[0] = _FileUtils.kCloseRequest; |
| 710 request[1] = _id; | 715 request[1] = _id; |
| 711 // Set the id_ to 0 (NULL) to ensure the no more async requests | 716 // Set the id_ to 0 (NULL) to ensure the no more async requests |
| 712 // can be issues for this file. | 717 // can be issues for this file. |
| 713 _id = 0; | 718 _id = 0; |
| 714 _fileService.call(request).then((result) { | 719 _fileService.call(request).then((result) { |
| 715 if (result != -1) { | 720 if (result != -1) { |
| 716 _id = result; | 721 _id = result; |
| 717 callback(); | 722 callback(); |
| 718 } else if (_onError != null) { | 723 } else if (_onError != null) { |
| 719 _onError("Cannot close file: $_name"); | 724 _onError(new FileIOException("Cannot close file: $_name")); |
| 720 } | 725 } |
| 721 }); | 726 }); |
| 722 } | 727 } |
| 723 | 728 |
| 724 void closeSync() { | 729 void closeSync() { |
| 725 var id = _FileUtils.close(_id); | 730 var id = _FileUtils.close(_id); |
| 726 if (id == -1) { | 731 if (id == -1) { |
| 727 throw new FileIOException("Cannot close file: $_name"); | 732 throw new FileIOException("Cannot close file: $_name"); |
| 728 } | 733 } |
| 729 _id = id; | 734 _id = id; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 750 throw new FileIOException("readByte failed", result); | 755 throw new FileIOException("readByte failed", result); |
| 751 } | 756 } |
| 752 return result; | 757 return result; |
| 753 } | 758 } |
| 754 | 759 |
| 755 void readList(List<int> buffer, int offset, int bytes, | 760 void readList(List<int> buffer, int offset, int bytes, |
| 756 void callback(int read)) { | 761 void callback(int read)) { |
| 757 _ensureFileService(); | 762 _ensureFileService(); |
| 758 if (buffer is !List || offset is !int || bytes is !int) { | 763 if (buffer is !List || offset is !int || bytes is !int) { |
| 759 if (_onError != null) { | 764 if (_onError != null) { |
| 760 _onError("Invalid arguments to readList"); | 765 _onError(new FileIOException("Invalid arguments to readList")); |
| 761 } | 766 } |
| 762 return; | 767 return; |
| 763 }; | 768 }; |
| 764 List request = new List(3); | 769 List request = new List(3); |
| 765 request[0] = _FileUtils.kReadListRequest; | 770 request[0] = _FileUtils.kReadListRequest; |
| 766 request[1] = _id; | 771 request[1] = _id; |
| 767 request[2] = bytes; | 772 request[2] = bytes; |
| 768 _fileService.call(request).then((response) { | 773 _fileService.call(request).then((response) { |
| 769 if (_isErrorResponse(response)) { | 774 if (_isErrorResponse(response)) { |
| 770 _reportError(response, "readList failed"); | 775 _reportError(response, "readList failed"); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 792 if (result is OSError) { | 797 if (result is OSError) { |
| 793 throw new FileIOException("readList failed", result); | 798 throw new FileIOException("readList failed", result); |
| 794 } | 799 } |
| 795 return result; | 800 return result; |
| 796 } | 801 } |
| 797 | 802 |
| 798 void writeByte(int value) { | 803 void writeByte(int value) { |
| 799 _ensureFileService(); | 804 _ensureFileService(); |
| 800 if (value is !int) { | 805 if (value is !int) { |
| 801 if (_onError != null) { | 806 if (_onError != null) { |
| 802 _onError("Invalid argument to writeByte"); | 807 _onError(new FileIOException("Invalid argument to writeByte")); |
| 803 } | 808 } |
| 804 return; | 809 return; |
| 805 } | 810 } |
| 806 List request = new List(3); | 811 List request = new List(3); |
| 807 request[0] = _FileUtils.kWriteByteRequest; | 812 request[0] = _FileUtils.kWriteByteRequest; |
| 808 request[1] = _id; | 813 request[1] = _id; |
| 809 request[2] = value; | 814 request[2] = value; |
| 810 _writeEnqueued(); | 815 _writeEnqueued(); |
| 811 _fileService.call(request).then((response) { | 816 _fileService.call(request).then((response) { |
| 812 _writeCompleted(); | 817 _writeCompleted(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 825 if (result is OSError) { | 830 if (result is OSError) { |
| 826 throw new FileIOException("writeByte failed", result); | 831 throw new FileIOException("writeByte failed", result); |
| 827 } | 832 } |
| 828 return result; | 833 return result; |
| 829 } | 834 } |
| 830 | 835 |
| 831 void writeList(List<int> buffer, int offset, int bytes) { | 836 void writeList(List<int> buffer, int offset, int bytes) { |
| 832 _ensureFileService(); | 837 _ensureFileService(); |
| 833 if (buffer is !List || offset is !int || bytes is !int) { | 838 if (buffer is !List || offset is !int || bytes is !int) { |
| 834 if (_onError != null) { | 839 if (_onError != null) { |
| 835 _onError("Invalid arguments to writeList"); | 840 _onError(new FileIOException("Invalid arguments to writeList")); |
| 836 } | 841 } |
| 837 return; | 842 return; |
| 838 } | 843 } |
| 839 | 844 |
| 840 List result = | 845 List result = |
| 841 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); | 846 _FileUtils.ensureFastAndSerializableBuffer(buffer, offset, bytes); |
| 842 List outBuffer = result[0]; | 847 List outBuffer = result[0]; |
| 843 int outOffset = result[1]; | 848 int outOffset = result[1]; |
| 844 | 849 |
| 845 List request = new List(5); | 850 List request = new List(5); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 String _name; | 1059 String _name; |
| 1055 int _id; | 1060 int _id; |
| 1056 int _pendingWrites = 0; | 1061 int _pendingWrites = 0; |
| 1057 | 1062 |
| 1058 SendPort _fileService; | 1063 SendPort _fileService; |
| 1059 | 1064 |
| 1060 Timer _noPendingWriteTimer; | 1065 Timer _noPendingWriteTimer; |
| 1061 | 1066 |
| 1062 Function _onNoPendingWrites; | 1067 Function _onNoPendingWrites; |
| 1063 } | 1068 } |
| OLD | NEW |