| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 285 |
| 286 void execute(ReceivePort port) { | 286 void execute(ReceivePort port) { |
| 287 _replyPort.send(_File._setPosition(_id, _position), port.toSendPort()); | 287 _replyPort.send(_File._setPosition(_id, _position), port.toSendPort()); |
| 288 } | 288 } |
| 289 | 289 |
| 290 int _id; | 290 int _id; |
| 291 int _position; | 291 int _position; |
| 292 } | 292 } |
| 293 | 293 |
| 294 | 294 |
| 295 class _TruncateOperation extends _FileOperation { |
| 296 _TruncateOperation(int this._id, int this._length); |
| 297 |
| 298 void execute(ReceivePort port) { |
| 299 _replyPort.send(_File._truncate(_id, _length), port.toSendPort()); |
| 300 } |
| 301 |
| 302 int _id; |
| 303 int _length; |
| 304 } |
| 305 |
| 306 |
| 295 class _LengthOperation extends _FileOperation { | 307 class _LengthOperation extends _FileOperation { |
| 296 _LengthOperation(int this._id); | 308 _LengthOperation(int this._id); |
| 297 | 309 |
| 298 void execute(ReceivePort port) { | 310 void execute(ReceivePort port) { |
| 299 _replyPort.send(_File._length(_id), port.toSendPort()); | 311 _replyPort.send(_File._length(_id), port.toSendPort()); |
| 300 } | 312 } |
| 301 | 313 |
| 302 int _id; | 314 int _id; |
| 303 } | 315 } |
| 304 | 316 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 static int _open(String name, bool writable) native "File_Open"; | 440 static int _open(String name, bool writable) native "File_Open"; |
| 429 static int _close(int id) native "File_Close"; | 441 static int _close(int id) native "File_Close"; |
| 430 static int _readByte(int id) native "File_ReadByte"; | 442 static int _readByte(int id) native "File_ReadByte"; |
| 431 static int _readList(int id, List<int> buffer, int offset, int bytes) | 443 static int _readList(int id, List<int> buffer, int offset, int bytes) |
| 432 native "File_ReadList"; | 444 native "File_ReadList"; |
| 433 static int _writeByte(int id, int value) native "File_WriteByte"; | 445 static int _writeByte(int id, int value) native "File_WriteByte"; |
| 434 static int _writeList(int id, List<int> buffer, int offset, int bytes) | 446 static int _writeList(int id, List<int> buffer, int offset, int bytes) |
| 435 native "File_WriteList"; | 447 native "File_WriteList"; |
| 436 static int _writeString(int id, String string) native "File_WriteString"; | 448 static int _writeString(int id, String string) native "File_WriteString"; |
| 437 static int _position(int id) native "File_Position"; | 449 static int _position(int id) native "File_Position"; |
| 438 static int _setPosition(int id, int position) native "File_SetPosition"; | 450 static bool _setPosition(int id, int position) native "File_SetPosition"; |
| 451 static bool _truncate(int id, int length) native "File_Truncate"; |
| 439 static int _length(int id) native "File_Length"; | 452 static int _length(int id) native "File_Length"; |
| 440 static int _flush(int id) native "File_Flush"; | 453 static int _flush(int id) native "File_Flush"; |
| 441 static bool _create(String name) native "File_Create"; | 454 static bool _create(String name) native "File_Create"; |
| 442 static bool _delete(String name) native "File_Delete"; | 455 static bool _delete(String name) native "File_Delete"; |
| 443 static String _fullPath(String name) native "File_FullPath"; | 456 static String _fullPath(String name) native "File_FullPath"; |
| 444 | 457 |
| 445 static int _checkReadWriteListArguments(int length, int offset, int bytes) { | 458 static int _checkReadWriteListArguments(int length, int offset, int bytes) { |
| 446 if (offset < 0) return offset; | 459 if (offset < 0) return offset; |
| 447 if (bytes < 0) return bytes; | 460 if (bytes < 0) return bytes; |
| 448 if ((offset + bytes) > length) return offset + bytes; | 461 if ((offset + bytes) > length) return offset + bytes; |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 throw new FileIOException("position failed"); | 825 throw new FileIOException("position failed"); |
| 813 } | 826 } |
| 814 return result; | 827 return result; |
| 815 } | 828 } |
| 816 | 829 |
| 817 void setPosition(int position) { | 830 void setPosition(int position) { |
| 818 _asyncUsed = true; | 831 _asyncUsed = true; |
| 819 var handler = | 832 var handler = |
| 820 (_setPositionHandler != null) ? _setPositionHandler : () => null; | 833 (_setPositionHandler != null) ? _setPositionHandler : () => null; |
| 821 var handleSetPositionResult = (result, ignored) { | 834 var handleSetPositionResult = (result, ignored) { |
| 822 if (result == -1 && _errorHandler != null) { | 835 if (result == false && _errorHandler != null) { |
| 823 _errorHandler("setPosition failed"); | 836 _errorHandler("setPosition failed"); |
| 824 return; | 837 return; |
| 825 } | 838 } |
| 826 handler(result); | 839 handler(); |
| 827 }; | 840 }; |
| 828 var operation = new _SetPositionOperation(_id, position); | 841 var operation = new _SetPositionOperation(_id, position); |
| 829 _scheduler.enqueue(operation, handleSetPositionResult); | 842 _scheduler.enqueue(operation, handleSetPositionResult); |
| 830 } | 843 } |
| 831 | 844 |
| 832 void setPositionSync(int position) { | 845 void setPositionSync(int position) { |
| 833 if (_asyncUsed) { | 846 if (_asyncUsed) { |
| 834 throw new FileIOException( | 847 throw new FileIOException( |
| 835 "Mixed use of synchronous and asynchronous API"); | 848 "Mixed use of synchronous and asynchronous API"); |
| 836 } | 849 } |
| 837 int result = _setPosition(_id, position); | 850 bool result = _setPosition(_id, position); |
| 838 if (result == -1) { | 851 if (result == false) { |
| 839 throw new FileIOException("setPosition failed"); | 852 throw new FileIOException("setPosition failed"); |
| 840 } | 853 } |
| 841 } | 854 } |
| 842 | 855 |
| 856 void truncate(int length) { |
| 857 _asyncUsed = true; |
| 858 var handler = (_truncateHandler != null) ? _truncateHandler : () => null; |
| 859 var handleTruncateResult = (result, ignored) { |
| 860 if (result == false && _errorHandler != null) { |
| 861 _errorHandler("truncate failed"); |
| 862 return; |
| 863 } |
| 864 handler(); |
| 865 }; |
| 866 var operation = new _TruncateOperation(_id, length); |
| 867 _scheduler.enqueue(operation, handleTruncateResult); |
| 868 } |
| 869 |
| 870 void truncateSync(int length) { |
| 871 if (_asyncUsed) { |
| 872 throw new FileIOException( |
| 873 "Mixed use of synchronous and asynchronous API"); |
| 874 } |
| 875 bool result = _truncate(_id, length); |
| 876 if (result == false) { |
| 877 throw new FileIOException("truncate failed"); |
| 878 } |
| 879 } |
| 843 | 880 |
| 844 void length() { | 881 void length() { |
| 845 _asyncUsed = true; | 882 _asyncUsed = true; |
| 846 var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null; | 883 var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null; |
| 847 var handleLengthResult = (result, ignored) { | 884 var handleLengthResult = (result, ignored) { |
| 848 if (result == -1 && _errorHandler != null) { | 885 if (result == -1 && _errorHandler != null) { |
| 849 _errorHandler("length failed"); | 886 _errorHandler("length failed"); |
| 850 return; | 887 return; |
| 851 } | 888 } |
| 852 handler(result); | 889 handler(result); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 } | 1001 } |
| 965 | 1002 |
| 966 void set positionHandler(void handler(int pos)) { | 1003 void set positionHandler(void handler(int pos)) { |
| 967 _positionHandler = handler; | 1004 _positionHandler = handler; |
| 968 } | 1005 } |
| 969 | 1006 |
| 970 void set setPositionHandler(void handler()) { | 1007 void set setPositionHandler(void handler()) { |
| 971 _setPositionHandler = handler; | 1008 _setPositionHandler = handler; |
| 972 } | 1009 } |
| 973 | 1010 |
| 1011 void set truncateHandler(void handler()) { |
| 1012 _truncateHandler = handler; |
| 1013 } |
| 1014 |
| 974 void set lengthHandler(void handler(int length)) { | 1015 void set lengthHandler(void handler(int length)) { |
| 975 _lengthHandler = handler; | 1016 _lengthHandler = handler; |
| 976 } | 1017 } |
| 977 | 1018 |
| 978 void set flushHandler(void handler()) { | 1019 void set flushHandler(void handler()) { |
| 979 _flushHandler = handler; | 1020 _flushHandler = handler; |
| 980 } | 1021 } |
| 981 | 1022 |
| 982 void set fullPathHandler(void handler(String)) { | 1023 void set fullPathHandler(void handler(String)) { |
| 983 _fullPathHandler = handler; | 1024 _fullPathHandler = handler; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 996 var _existsHandler; | 1037 var _existsHandler; |
| 997 var _createHandler; | 1038 var _createHandler; |
| 998 var _deleteHandler; | 1039 var _deleteHandler; |
| 999 var _openHandler; | 1040 var _openHandler; |
| 1000 var _closeHandler; | 1041 var _closeHandler; |
| 1001 var _readByteHandler; | 1042 var _readByteHandler; |
| 1002 var _readListHandler; | 1043 var _readListHandler; |
| 1003 var _noPendingWriteHandler; | 1044 var _noPendingWriteHandler; |
| 1004 var _positionHandler; | 1045 var _positionHandler; |
| 1005 var _setPositionHandler; | 1046 var _setPositionHandler; |
| 1047 var _truncateHandler; |
| 1006 var _lengthHandler; | 1048 var _lengthHandler; |
| 1007 var _flushHandler; | 1049 var _flushHandler; |
| 1008 var _fullPathHandler; | 1050 var _fullPathHandler; |
| 1009 var _errorHandler; | 1051 var _errorHandler; |
| 1010 } | 1052 } |
| OLD | NEW |