| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 _FlushOperation(int this._id); | 294 _FlushOperation(int this._id); |
| 295 | 295 |
| 296 void execute(ReceivePort port) { | 296 void execute(ReceivePort port) { |
| 297 _replyPort.send(_File._flush(_id), port.toSendPort()); | 297 _replyPort.send(_File._flush(_id), port.toSendPort()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 int _id; | 300 int _id; |
| 301 } | 301 } |
| 302 | 302 |
| 303 | 303 |
| 304 class _FullPathOperation extends _FileOperation { |
| 305 _FullPathOperation(String this._name); |
| 306 |
| 307 void execute(ReceivePort port) { |
| 308 _replyPort.send(_File._fullPath(_name), port.toSendPort()); |
| 309 } |
| 310 |
| 311 String _name; |
| 312 } |
| 313 |
| 314 |
| 304 class _CreateOperation extends _FileOperation { | 315 class _CreateOperation extends _FileOperation { |
| 305 _CreateOperation(String this._name); | 316 _CreateOperation(String this._name); |
| 306 | 317 |
| 307 void execute(ReceivePort port) { | 318 void execute(ReceivePort port) { |
| 308 _replyPort.send(_File._create(_name), port.toSendPort()); | 319 _replyPort.send(_File._create(_name), port.toSendPort()); |
| 309 } | 320 } |
| 310 | 321 |
| 311 String _name; | 322 String _name; |
| 312 } | 323 } |
| 313 | 324 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 static int _readList(int id, List<int> buffer, int offset, int bytes) | 406 static int _readList(int id, List<int> buffer, int offset, int bytes) |
| 396 native "File_ReadList"; | 407 native "File_ReadList"; |
| 397 static int _writeByte(int id, int value) native "File_WriteByte"; | 408 static int _writeByte(int id, int value) native "File_WriteByte"; |
| 398 static int _writeList(int id, List<int> buffer, int offset, int bytes) | 409 static int _writeList(int id, List<int> buffer, int offset, int bytes) |
| 399 native "File_WriteList"; | 410 native "File_WriteList"; |
| 400 static int _writeString(int id, String string) native "File_WriteString"; | 411 static int _writeString(int id, String string) native "File_WriteString"; |
| 401 static int _position(int id) native "File_Position"; | 412 static int _position(int id) native "File_Position"; |
| 402 static int _length(int id) native "File_Length"; | 413 static int _length(int id) native "File_Length"; |
| 403 static int _flush(int id) native "File_Flush"; | 414 static int _flush(int id) native "File_Flush"; |
| 404 static bool _create(String name) native "File_Create"; | 415 static bool _create(String name) native "File_Create"; |
| 416 static int _fullPath(String name) native "File_FullPath"; |
| 405 | 417 |
| 406 static int _checkReadWriteListArguments(int length, int offset, int bytes) { | 418 static int _checkReadWriteListArguments(int length, int offset, int bytes) { |
| 407 if (offset < 0) return offset; | 419 if (offset < 0) return offset; |
| 408 if (bytes < 0) return bytes; | 420 if (bytes < 0) return bytes; |
| 409 if ((offset + bytes) > length) return offset + bytes; | 421 if ((offset + bytes) > length) return offset + bytes; |
| 410 return 0; | 422 return 0; |
| 411 } | 423 } |
| 412 | 424 |
| 413 void exists() { | 425 void exists() { |
| 414 _asyncUsed = true; | 426 _asyncUsed = true; |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 if (_asyncUsed) { | 744 if (_asyncUsed) { |
| 733 throw new FileIOException( | 745 throw new FileIOException( |
| 734 "Mixed use of synchronous and asynchronous API"); | 746 "Mixed use of synchronous and asynchronous API"); |
| 735 } | 747 } |
| 736 int result = _flush(_id); | 748 int result = _flush(_id); |
| 737 if (result == -1) { | 749 if (result == -1) { |
| 738 throw new FileIOException("flush failed"); | 750 throw new FileIOException("flush failed"); |
| 739 } | 751 } |
| 740 } | 752 } |
| 741 | 753 |
| 754 void fullPath() { |
| 755 _asyncUsed = true; |
| 756 var handler = _fullPathHandler; |
| 757 if (handler == null) handler = (path) => null; |
| 758 var handleFullPathResult = (result, ignored) { |
| 759 if (result != null) { |
| 760 handler(result); |
| 761 } else if (_errorHandler != null) { |
| 762 _errorHandler("canonicalPath failed"); |
| 763 } |
| 764 }; |
| 765 var operation = new _FullPathOperation(_name); |
| 766 _scheduler.enqueue(operation, handleFullPathResult); |
| 767 } |
| 768 |
| 769 String fullPathSync() { |
| 770 if (_asyncUsed) { |
| 771 throw new FileIOException( |
| 772 "Mixed use of synchronous and asynchronous API"); |
| 773 } |
| 774 String result = _fullPath(_name); |
| 775 if (result == null) { |
| 776 throw new FileIOException("fullPath failed"); |
| 777 } |
| 778 return result; |
| 779 } |
| 780 |
| 742 InputStream openInputStream() { | 781 InputStream openInputStream() { |
| 743 return new _FileInputStream(this); | 782 return new _FileInputStream(this); |
| 744 } | 783 } |
| 745 | 784 |
| 746 OutputStream openOutputStream() { | 785 OutputStream openOutputStream() { |
| 747 return new _FileOutputStream(this); | 786 return new _FileOutputStream(this); |
| 748 } | 787 } |
| 749 | 788 |
| 750 String get name() { | 789 String get name() { |
| 751 return _name; | 790 return _name; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 823 } |
| 785 | 824 |
| 786 void set lengthHandler(void handler(int length)) { | 825 void set lengthHandler(void handler(int length)) { |
| 787 _lengthHandler = handler; | 826 _lengthHandler = handler; |
| 788 } | 827 } |
| 789 | 828 |
| 790 void set flushHandler(void handler()) { | 829 void set flushHandler(void handler()) { |
| 791 _flushHandler = handler; | 830 _flushHandler = handler; |
| 792 } | 831 } |
| 793 | 832 |
| 833 void set fullPathHandler(void handler(String)) { |
| 834 _fullPathHandler = handler; |
| 835 } |
| 836 |
| 794 void set errorHandler(void handler(String error)) { | 837 void set errorHandler(void handler(String error)) { |
| 795 _errorHandler = handler; | 838 _errorHandler = handler; |
| 796 } | 839 } |
| 797 | 840 |
| 798 String _name; | 841 String _name; |
| 799 int _id; | 842 int _id; |
| 800 bool _asyncUsed; | 843 bool _asyncUsed; |
| 801 | 844 |
| 802 _FileOperationScheduler _scheduler; | 845 _FileOperationScheduler _scheduler; |
| 803 | 846 |
| 804 var _existsHandler; | 847 var _existsHandler; |
| 805 var _createHandler; | 848 var _createHandler; |
| 806 var _openHandler; | 849 var _openHandler; |
| 807 var _closeHandler; | 850 var _closeHandler; |
| 808 var _readByteHandler; | 851 var _readByteHandler; |
| 809 var _readListHandler; | 852 var _readListHandler; |
| 810 var _noPendingWriteHandler; | 853 var _noPendingWriteHandler; |
| 811 var _positionHandler; | 854 var _positionHandler; |
| 812 var _lengthHandler; | 855 var _lengthHandler; |
| 813 var _flushHandler; | 856 var _flushHandler; |
| 857 var _fullPathHandler; |
| 814 var _errorHandler; | 858 var _errorHandler; |
| 815 } | 859 } |
| OLD | NEW |