Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 implements FileInputStream { | 5 class _FileInputStream implements FileInputStream { |
| 6 _FileInputStream(File file) { | 6 _FileInputStream(File file) { |
| 7 _file = new File(file.name); | 7 _file = new File(file.name); |
| 8 _file.openSync(); | 8 _file.openSync(); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 _PositionOperation(int this._id); | 273 _PositionOperation(int this._id); |
| 274 | 274 |
| 275 void execute(ReceivePort port) { | 275 void execute(ReceivePort port) { |
| 276 _replyPort.send(_File._position(_id), port.toSendPort()); | 276 _replyPort.send(_File._position(_id), port.toSendPort()); |
| 277 } | 277 } |
| 278 | 278 |
| 279 int _id; | 279 int _id; |
| 280 } | 280 } |
| 281 | 281 |
| 282 | 282 |
| 283 class _SetPositionOperation extends _FileOperation { | |
| 284 _SetPositionOperation(int this._id, int this._position); | |
| 285 | |
| 286 void execute(ReceivePort port) { | |
| 287 _replyPort.send(_File._setPosition(_id, _position), port.toSendPort()); | |
| 288 } | |
| 289 | |
| 290 int _id; | |
| 291 int _position; | |
| 292 } | |
| 293 | |
| 294 | |
| 283 class _LengthOperation extends _FileOperation { | 295 class _LengthOperation extends _FileOperation { |
| 284 _LengthOperation(int this._id); | 296 _LengthOperation(int this._id); |
| 285 | 297 |
| 286 void execute(ReceivePort port) { | 298 void execute(ReceivePort port) { |
| 287 _replyPort.send(_File._length(_id), port.toSendPort()); | 299 _replyPort.send(_File._length(_id), port.toSendPort()); |
| 288 } | 300 } |
| 289 | 301 |
| 290 int _id; | 302 int _id; |
| 291 } | 303 } |
| 292 | 304 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 static int _open(String name, bool writable) native "File_Open"; | 417 static int _open(String name, bool writable) native "File_Open"; |
| 406 static int _close(int id) native "File_Close"; | 418 static int _close(int id) native "File_Close"; |
| 407 static int _readByte(int id) native "File_ReadByte"; | 419 static int _readByte(int id) native "File_ReadByte"; |
| 408 static int _readList(int id, List<int> buffer, int offset, int bytes) | 420 static int _readList(int id, List<int> buffer, int offset, int bytes) |
| 409 native "File_ReadList"; | 421 native "File_ReadList"; |
| 410 static int _writeByte(int id, int value) native "File_WriteByte"; | 422 static int _writeByte(int id, int value) native "File_WriteByte"; |
| 411 static int _writeList(int id, List<int> buffer, int offset, int bytes) | 423 static int _writeList(int id, List<int> buffer, int offset, int bytes) |
| 412 native "File_WriteList"; | 424 native "File_WriteList"; |
| 413 static int _writeString(int id, String string) native "File_WriteString"; | 425 static int _writeString(int id, String string) native "File_WriteString"; |
| 414 static int _position(int id) native "File_Position"; | 426 static int _position(int id) native "File_Position"; |
| 427 static int _setPosition(int id, int position) native "File_SetPosition"; | |
| 415 static int _length(int id) native "File_Length"; | 428 static int _length(int id) native "File_Length"; |
| 416 static int _flush(int id) native "File_Flush"; | 429 static int _flush(int id) native "File_Flush"; |
| 417 static bool _create(String name) native "File_Create"; | 430 static bool _create(String name) native "File_Create"; |
| 418 static String _fullPath(String name) native "File_FullPath"; | 431 static String _fullPath(String name) native "File_FullPath"; |
| 419 | 432 |
| 420 static int _checkReadWriteListArguments(int length, int offset, int bytes) { | 433 static int _checkReadWriteListArguments(int length, int offset, int bytes) { |
| 421 if (offset < 0) return offset; | 434 if (offset < 0) return offset; |
| 422 if (bytes < 0) return bytes; | 435 if (bytes < 0) return bytes; |
| 423 if ((offset + bytes) > length) return offset + bytes; | 436 if ((offset + bytes) > length) return offset + bytes; |
| 424 return 0; | 437 return 0; |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 throw new FileIOException( | 765 throw new FileIOException( |
| 753 "Mixed use of synchronous and asynchronous API"); | 766 "Mixed use of synchronous and asynchronous API"); |
| 754 } | 767 } |
| 755 int result = _position(_id); | 768 int result = _position(_id); |
| 756 if (result == -1) { | 769 if (result == -1) { |
| 757 throw new FileIOException("position failed"); | 770 throw new FileIOException("position failed"); |
| 758 } | 771 } |
| 759 return result; | 772 return result; |
| 760 } | 773 } |
| 761 | 774 |
| 775 void setPosition(int position) { | |
| 776 _asyncUsed = true; | |
| 777 var handler = (_setPositionHandler != null) ? _setPositionHandler : () => nu ll; | |
|
Søren Gjesse
2011/11/16 15:24:11
Long line.
Mads Ager (google)
2011/11/16 15:49:17
Done.
| |
| 778 var handleSetPositionResult = (result, ignored) { | |
| 779 if (result == -1 && _errorHandler != null) { | |
| 780 _errorHandler("setPosition failed"); | |
| 781 return; | |
| 782 } | |
| 783 handler(result); | |
| 784 }; | |
| 785 var operation = new _SetPositionOperation(_id, position); | |
| 786 _scheduler.enqueue(operation, handleSetPositionResult); | |
| 787 } | |
| 788 | |
| 789 void setPositionSync(int position) { | |
| 790 if (_asyncUsed) { | |
| 791 throw new FileIOException( | |
| 792 "Mixed use of synchronous and asynchronous API"); | |
| 793 } | |
| 794 int result = _setPosition(_id, position); | |
| 795 if (result == -1) { | |
| 796 throw new FileIOException("setPosition failed"); | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 | |
| 762 void length() { | 801 void length() { |
| 763 _asyncUsed = true; | 802 _asyncUsed = true; |
| 764 var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null; | 803 var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null; |
| 765 var handleLengthResult = (result, ignored) { | 804 var handleLengthResult = (result, ignored) { |
| 766 if (result == -1 && _errorHandler != null) { | 805 if (result == -1 && _errorHandler != null) { |
| 767 _errorHandler("length failed"); | 806 _errorHandler("length failed"); |
| 768 return; | 807 return; |
| 769 } | 808 } |
| 770 handler(result); | 809 handler(result); |
| 771 }; | 810 }; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 874 } | 913 } |
| 875 | 914 |
| 876 void set noPendingWriteHandler(void handler()) { | 915 void set noPendingWriteHandler(void handler()) { |
| 877 _noPendingWriteHandler = handler; | 916 _noPendingWriteHandler = handler; |
| 878 } | 917 } |
| 879 | 918 |
| 880 void set positionHandler(void handler(int pos)) { | 919 void set positionHandler(void handler(int pos)) { |
| 881 _positionHandler = handler; | 920 _positionHandler = handler; |
| 882 } | 921 } |
| 883 | 922 |
| 923 void set setPositionHandler(void handler()) { | |
| 924 _setPositionHandler = handler; | |
| 925 } | |
| 926 | |
| 884 void set lengthHandler(void handler(int length)) { | 927 void set lengthHandler(void handler(int length)) { |
| 885 _lengthHandler = handler; | 928 _lengthHandler = handler; |
| 886 } | 929 } |
| 887 | 930 |
| 888 void set flushHandler(void handler()) { | 931 void set flushHandler(void handler()) { |
| 889 _flushHandler = handler; | 932 _flushHandler = handler; |
| 890 } | 933 } |
| 891 | 934 |
| 892 void set fullPathHandler(void handler(String)) { | 935 void set fullPathHandler(void handler(String)) { |
| 893 _fullPathHandler = handler; | 936 _fullPathHandler = handler; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 904 _FileOperationScheduler _scheduler; | 947 _FileOperationScheduler _scheduler; |
| 905 | 948 |
| 906 var _existsHandler; | 949 var _existsHandler; |
| 907 var _createHandler; | 950 var _createHandler; |
| 908 var _openHandler; | 951 var _openHandler; |
| 909 var _closeHandler; | 952 var _closeHandler; |
| 910 var _readByteHandler; | 953 var _readByteHandler; |
| 911 var _readListHandler; | 954 var _readListHandler; |
| 912 var _noPendingWriteHandler; | 955 var _noPendingWriteHandler; |
| 913 var _positionHandler; | 956 var _positionHandler; |
| 957 var _setPositionHandler; | |
| 914 var _lengthHandler; | 958 var _lengthHandler; |
| 915 var _flushHandler; | 959 var _flushHandler; |
| 916 var _fullPathHandler; | 960 var _fullPathHandler; |
| 917 var _errorHandler; | 961 var _errorHandler; |
| 918 } | 962 } |
| OLD | NEW |