| 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 = (String s) { | 10 _file.onError = (String s) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 _asyncUsed = true; | 323 _asyncUsed = true; |
| 324 if (_name is !String) { | 324 if (_name is !String) { |
| 325 if (_onError != null) { | 325 if (_onError != null) { |
| 326 _onError('File name is not a string: $_name'); | 326 _onError('File name is not a string: $_name'); |
| 327 } | 327 } |
| 328 return; | 328 return; |
| 329 } | 329 } |
| 330 List request = new List(2); | 330 List request = new List(2); |
| 331 request[0] = _FileUtils.kExistsRequest; | 331 request[0] = _FileUtils.kExistsRequest; |
| 332 request[1] = _name; | 332 request[1] = _name; |
| 333 _fileService.call(request).receive((exists, replyTo) { | 333 _fileService.call(request).then((exists) { |
| 334 callback(exists); | 334 callback(exists); |
| 335 }); | 335 }); |
| 336 } | 336 } |
| 337 | 337 |
| 338 bool existsSync() { | 338 bool existsSync() { |
| 339 if (_asyncUsed) { | 339 if (_asyncUsed) { |
| 340 throw new FileIOException( | 340 throw new FileIOException( |
| 341 "Mixed use of synchronous and asynchronous API"); | 341 "Mixed use of synchronous and asynchronous API"); |
| 342 } | 342 } |
| 343 if (_name is !String) { | 343 if (_name is !String) { |
| 344 throw new FileIOException('File name is not a string: $_name'); | 344 throw new FileIOException('File name is not a string: $_name'); |
| 345 } | 345 } |
| 346 return _FileUtils.exists(_name); | 346 return _FileUtils.exists(_name); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void create(void callback()) { | 349 void create(void callback()) { |
| 350 _ensureFileService(); | 350 _ensureFileService(); |
| 351 _asyncUsed = true; | 351 _asyncUsed = true; |
| 352 List request = new List(2); | 352 List request = new List(2); |
| 353 request[0] = _FileUtils.kCreateRequest; | 353 request[0] = _FileUtils.kCreateRequest; |
| 354 request[1] = _name; | 354 request[1] = _name; |
| 355 _fileService.call(request).receive((created, replyTo) { | 355 _fileService.call(request).then((created) { |
| 356 if (created) { | 356 if (created) { |
| 357 callback(); | 357 callback(); |
| 358 } else if (_onError != null) { | 358 } else if (_onError != null) { |
| 359 _onError("Cannot create file: $_name"); | 359 _onError("Cannot create file: $_name"); |
| 360 } | 360 } |
| 361 }); | 361 }); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void createSync() { | 364 void createSync() { |
| 365 if (_asyncUsed) { | 365 if (_asyncUsed) { |
| 366 throw new FileIOException( | 366 throw new FileIOException( |
| 367 "Mixed use of synchronous and asynchronous API"); | 367 "Mixed use of synchronous and asynchronous API"); |
| 368 } | 368 } |
| 369 bool created = _FileUtils.checkedCreate(_name); | 369 bool created = _FileUtils.checkedCreate(_name); |
| 370 if (!created) { | 370 if (!created) { |
| 371 throw new FileIOException("Cannot create file: $_name"); | 371 throw new FileIOException("Cannot create file: $_name"); |
| 372 } | 372 } |
| 373 } | 373 } |
| 374 | 374 |
| 375 void delete(void callback()) { | 375 void delete(void callback()) { |
| 376 _ensureFileService(); | 376 _ensureFileService(); |
| 377 _asyncUsed = true; | 377 _asyncUsed = true; |
| 378 List request = new List(2); | 378 List request = new List(2); |
| 379 request[0] = _FileUtils.kDeleteRequest; | 379 request[0] = _FileUtils.kDeleteRequest; |
| 380 request[1] = _name; | 380 request[1] = _name; |
| 381 _fileService.call(request).receive((deleted, replyTo) { | 381 _fileService.call(request).then((deleted) { |
| 382 if (deleted) { | 382 if (deleted) { |
| 383 callback(); | 383 callback(); |
| 384 } else if (_onError != null) { | 384 } else if (_onError != null) { |
| 385 _onError("Cannot delete file: $_name"); | 385 _onError("Cannot delete file: $_name"); |
| 386 } | 386 } |
| 387 }); | 387 }); |
| 388 } | 388 } |
| 389 | 389 |
| 390 void deleteSync() { | 390 void deleteSync() { |
| 391 if (_asyncUsed) { | 391 if (_asyncUsed) { |
| 392 throw new FileIOException( | 392 throw new FileIOException( |
| 393 "Mixed use of synchronous and asynchronous API"); | 393 "Mixed use of synchronous and asynchronous API"); |
| 394 } | 394 } |
| 395 bool deleted = _FileUtils.checkedDelete(_name); | 395 bool deleted = _FileUtils.checkedDelete(_name); |
| 396 if (!deleted) { | 396 if (!deleted) { |
| 397 throw new FileIOException("Cannot delete file: $_name"); | 397 throw new FileIOException("Cannot delete file: $_name"); |
| 398 } | 398 } |
| 399 } | 399 } |
| 400 | 400 |
| 401 void directory(void callback(Directory dir)) { | 401 void directory(void callback(Directory dir)) { |
| 402 _ensureFileService(); | 402 _ensureFileService(); |
| 403 _asyncUsed = true; | 403 _asyncUsed = true; |
| 404 List request = new List(2); | 404 List request = new List(2); |
| 405 request[0] = _FileUtils.kDirectoryRequest; | 405 request[0] = _FileUtils.kDirectoryRequest; |
| 406 request[1] = _name; | 406 request[1] = _name; |
| 407 _fileService.call(request).receive((path, replyTo) { | 407 _fileService.call(request).then((path) { |
| 408 if (path != null) { | 408 if (path != null) { |
| 409 callback(new Directory(path)); | 409 callback(new Directory(path)); |
| 410 } else if (_onError != null) { | 410 } else if (_onError != null) { |
| 411 _onError("Cannot get directory for: ${_name}"); | 411 _onError("Cannot get directory for: ${_name}"); |
| 412 } | 412 } |
| 413 }); | 413 }); |
| 414 } | 414 } |
| 415 | 415 |
| 416 Directory directorySync() { | 416 Directory directorySync() { |
| 417 if (_asyncUsed) { | 417 if (_asyncUsed) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 433 if (_onError != null) { | 433 if (_onError != null) { |
| 434 _onError("Unknown file mode. Use FileMode.READ, FileMode.WRITE " + | 434 _onError("Unknown file mode. Use FileMode.READ, FileMode.WRITE " + |
| 435 "or FileMode.APPEND."); | 435 "or FileMode.APPEND."); |
| 436 return; | 436 return; |
| 437 } | 437 } |
| 438 } | 438 } |
| 439 List request = new List(3); | 439 List request = new List(3); |
| 440 request[0] = _FileUtils.kOpenRequest; | 440 request[0] = _FileUtils.kOpenRequest; |
| 441 request[1] = _name; | 441 request[1] = _name; |
| 442 request[2] = mode._mode; // Direct int value for serialization. | 442 request[2] = mode._mode; // Direct int value for serialization. |
| 443 _fileService.call(request).receive((id, replyTo) { | 443 _fileService.call(request).then((id) { |
| 444 if (id != 0) { | 444 if (id != 0) { |
| 445 callback(new _RandomAccessFile(id, _name)); | 445 callback(new _RandomAccessFile(id, _name)); |
| 446 } else if (_onError != null) { | 446 } else if (_onError != null) { |
| 447 _onError("Cannot open file: $_name"); | 447 _onError("Cannot open file: $_name"); |
| 448 } | 448 } |
| 449 }); | 449 }); |
| 450 } | 450 } |
| 451 | 451 |
| 452 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { | 452 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { |
| 453 if (_asyncUsed) { | 453 if (_asyncUsed) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 474 } | 474 } |
| 475 return new _RandomAccessFile(id, ""); | 475 return new _RandomAccessFile(id, ""); |
| 476 } | 476 } |
| 477 | 477 |
| 478 void fullPath(void callback(String result)) { | 478 void fullPath(void callback(String result)) { |
| 479 _ensureFileService(); | 479 _ensureFileService(); |
| 480 _asyncUsed = true; | 480 _asyncUsed = true; |
| 481 List request = new List(2); | 481 List request = new List(2); |
| 482 request[0] = _FileUtils.kFullPathRequest; | 482 request[0] = _FileUtils.kFullPathRequest; |
| 483 request[1] = _name; | 483 request[1] = _name; |
| 484 _fileService.call(request).receive((result, replyTo) { | 484 _fileService.call(request).then((result) { |
| 485 if (result != null) { | 485 if (result != null) { |
| 486 callback(result); | 486 callback(result); |
| 487 } else if (_onError != null) { | 487 } else if (_onError != null) { |
| 488 _onError("fullPath failed"); | 488 _onError("fullPath failed"); |
| 489 } | 489 } |
| 490 }); | 490 }); |
| 491 } | 491 } |
| 492 | 492 |
| 493 String fullPathSync() { | 493 String fullPathSync() { |
| 494 if (_asyncUsed) { | 494 if (_asyncUsed) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 void close(void callback()) { | 657 void close(void callback()) { |
| 658 if (_id == 0) return; | 658 if (_id == 0) return; |
| 659 _ensureFileService(); | 659 _ensureFileService(); |
| 660 _asyncUsed = true; | 660 _asyncUsed = true; |
| 661 List request = new List(2); | 661 List request = new List(2); |
| 662 request[0] = _FileUtils.kCloseRequest; | 662 request[0] = _FileUtils.kCloseRequest; |
| 663 request[1] = _id; | 663 request[1] = _id; |
| 664 // Set the id_ to 0 (NULL) to ensure the no more async requests | 664 // Set the id_ to 0 (NULL) to ensure the no more async requests |
| 665 // can be issues for this file. | 665 // can be issues for this file. |
| 666 _id = 0; | 666 _id = 0; |
| 667 _fileService.call(request).receive((result, replyTo) { | 667 _fileService.call(request).then((result) { |
| 668 if (result != -1) { | 668 if (result != -1) { |
| 669 _id = result; | 669 _id = result; |
| 670 callback(); | 670 callback(); |
| 671 } else if (_onError != null) { | 671 } else if (_onError != null) { |
| 672 _onError("Cannot close file: $_name"); | 672 _onError("Cannot close file: $_name"); |
| 673 } | 673 } |
| 674 }); | 674 }); |
| 675 } | 675 } |
| 676 | 676 |
| 677 void closeSync() { | 677 void closeSync() { |
| 678 if (_asyncUsed) { | 678 if (_asyncUsed) { |
| 679 throw new FileIOException( | 679 throw new FileIOException( |
| 680 "Mixed use of synchronous and asynchronous API"); | 680 "Mixed use of synchronous and asynchronous API"); |
| 681 } | 681 } |
| 682 var id = _FileUtils.close(_id); | 682 var id = _FileUtils.close(_id); |
| 683 if (id == -1) { | 683 if (id == -1) { |
| 684 throw new FileIOException("Cannot close file: $_name"); | 684 throw new FileIOException("Cannot close file: $_name"); |
| 685 } | 685 } |
| 686 _id = id; | 686 _id = id; |
| 687 } | 687 } |
| 688 | 688 |
| 689 void readByte(void callback(int byte)) { | 689 void readByte(void callback(int byte)) { |
| 690 _ensureFileService(); | 690 _ensureFileService(); |
| 691 _asyncUsed = true; | 691 _asyncUsed = true; |
| 692 List request = new List(2); | 692 List request = new List(2); |
| 693 request[0] = _FileUtils.kReadByteRequest; | 693 request[0] = _FileUtils.kReadByteRequest; |
| 694 request[1] = _id; | 694 request[1] = _id; |
| 695 _fileService.call(request).receive((result, replyTo) { | 695 _fileService.call(request).then((result) { |
| 696 if (result != -1) { | 696 if (result != -1) { |
| 697 callback(result); | 697 callback(result); |
| 698 } else if (_onError != null) { | 698 } else if (_onError != null) { |
| 699 _onError("readByte failed"); | 699 _onError("readByte failed"); |
| 700 } | 700 } |
| 701 }); | 701 }); |
| 702 } | 702 } |
| 703 | 703 |
| 704 int readByteSync() { | 704 int readByteSync() { |
| 705 if (_asyncUsed) { | 705 if (_asyncUsed) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 720 if (buffer is !List || offset is !int || bytes is !int) { | 720 if (buffer is !List || offset is !int || bytes is !int) { |
| 721 if (_onError != null) { | 721 if (_onError != null) { |
| 722 _onError("Invalid arguments to readList"); | 722 _onError("Invalid arguments to readList"); |
| 723 } | 723 } |
| 724 return; | 724 return; |
| 725 }; | 725 }; |
| 726 List request = new List(3); | 726 List request = new List(3); |
| 727 request[0] = _FileUtils.kReadListRequest; | 727 request[0] = _FileUtils.kReadListRequest; |
| 728 request[1] = _id; | 728 request[1] = _id; |
| 729 request[2] = bytes; | 729 request[2] = bytes; |
| 730 _fileService.call(request).receive((result, replyTo) { | 730 _fileService.call(request).then((result) { |
| 731 if (result is List && result.length == 2 && result[0] != -1) { | 731 if (result is List && result.length == 2 && result[0] != -1) { |
| 732 var read = result[0]; | 732 var read = result[0]; |
| 733 var data = result[1]; | 733 var data = result[1]; |
| 734 buffer.setRange(offset, read, data); | 734 buffer.setRange(offset, read, data); |
| 735 callback(read); | 735 callback(read); |
| 736 return; | 736 return; |
| 737 } else if (_onError != null) { | 737 } else if (_onError != null) { |
| 738 _onError(result is String ? result : "readList failed"); | 738 _onError(result is String ? result : "readList failed"); |
| 739 } | 739 } |
| 740 }); | 740 }); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 768 if (_onError != null) { | 768 if (_onError != null) { |
| 769 _onError("Invalid argument to writeByte"); | 769 _onError("Invalid argument to writeByte"); |
| 770 } | 770 } |
| 771 return; | 771 return; |
| 772 } | 772 } |
| 773 List request = new List(3); | 773 List request = new List(3); |
| 774 request[0] = _FileUtils.kWriteByteRequest; | 774 request[0] = _FileUtils.kWriteByteRequest; |
| 775 request[1] = _id; | 775 request[1] = _id; |
| 776 request[2] = value; | 776 request[2] = value; |
| 777 _writeEnqueued(); | 777 _writeEnqueued(); |
| 778 _fileService.call(request).receive((result, replyTo) { | 778 _fileService.call(request).then((result) { |
| 779 _writeCompleted(); | 779 _writeCompleted(); |
| 780 if (result == -1 && _onError !== null) { | 780 if (result == -1 && _onError !== null) { |
| 781 _onError("writeByte failed"); | 781 _onError("writeByte failed"); |
| 782 } | 782 } |
| 783 }); | 783 }); |
| 784 } | 784 } |
| 785 | 785 |
| 786 int writeByteSync(int value) { | 786 int writeByteSync(int value) { |
| 787 if (_asyncUsed) { | 787 if (_asyncUsed) { |
| 788 throw new FileIOException( | 788 throw new FileIOException( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 813 List outBuffer = result[0]; | 813 List outBuffer = result[0]; |
| 814 int outOffset = result[1]; | 814 int outOffset = result[1]; |
| 815 | 815 |
| 816 List request = new List(5); | 816 List request = new List(5); |
| 817 request[0] = _FileUtils.kWriteListRequest; | 817 request[0] = _FileUtils.kWriteListRequest; |
| 818 request[1] = _id; | 818 request[1] = _id; |
| 819 request[2] = outBuffer; | 819 request[2] = outBuffer; |
| 820 request[3] = outOffset; | 820 request[3] = outOffset; |
| 821 request[4] = bytes; | 821 request[4] = bytes; |
| 822 _writeEnqueued(); | 822 _writeEnqueued(); |
| 823 _fileService.call(request).receive((result, replyTo) { | 823 _fileService.call(request).then((result) { |
| 824 _writeCompleted(); | 824 _writeCompleted(); |
| 825 if (result == -1 && _onError !== null) { | 825 if (result == -1 && _onError !== null) { |
| 826 _onError("writeList failed"); | 826 _onError("writeList failed"); |
| 827 } | 827 } |
| 828 }); | 828 }); |
| 829 } | 829 } |
| 830 | 830 |
| 831 int writeListSync(List<int> buffer, int offset, int bytes) { | 831 int writeListSync(List<int> buffer, int offset, int bytes) { |
| 832 if (_asyncUsed) { | 832 if (_asyncUsed) { |
| 833 throw new FileIOException( | 833 throw new FileIOException( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 850 } | 850 } |
| 851 | 851 |
| 852 void writeString(String string) { | 852 void writeString(String string) { |
| 853 _ensureFileService(); | 853 _ensureFileService(); |
| 854 _asyncUsed = true; | 854 _asyncUsed = true; |
| 855 List request = new List(3); | 855 List request = new List(3); |
| 856 request[0] = _FileUtils.kWriteStringRequest; | 856 request[0] = _FileUtils.kWriteStringRequest; |
| 857 request[1] = _id; | 857 request[1] = _id; |
| 858 request[2] = string; | 858 request[2] = string; |
| 859 _writeEnqueued(); | 859 _writeEnqueued(); |
| 860 _fileService.call(request).receive((result, replyTo) { | 860 _fileService.call(request).then((result) { |
| 861 _writeCompleted(); | 861 _writeCompleted(); |
| 862 if (result == -1 && _onError !== null) { | 862 if (result == -1 && _onError !== null) { |
| 863 _onError("writeString failed"); | 863 _onError("writeString failed"); |
| 864 } | 864 } |
| 865 }); | 865 }); |
| 866 } | 866 } |
| 867 | 867 |
| 868 int writeStringSync(String string) { | 868 int writeStringSync(String string) { |
| 869 if (_asyncUsed) { | 869 if (_asyncUsed) { |
| 870 throw new FileIOException( | 870 throw new FileIOException( |
| 871 "Mixed use of synchronous and asynchronous API"); | 871 "Mixed use of synchronous and asynchronous API"); |
| 872 } | 872 } |
| 873 int result = _FileUtils.checkedWriteString(_id, string); | 873 int result = _FileUtils.checkedWriteString(_id, string); |
| 874 if (result == -1) { | 874 if (result == -1) { |
| 875 throw new FileIOException("writeString failed"); | 875 throw new FileIOException("writeString failed"); |
| 876 } | 876 } |
| 877 return result; | 877 return result; |
| 878 } | 878 } |
| 879 | 879 |
| 880 void position(void callback(int position)) { | 880 void position(void callback(int position)) { |
| 881 _ensureFileService(); | 881 _ensureFileService(); |
| 882 _asyncUsed = true; | 882 _asyncUsed = true; |
| 883 List request = new List(2); | 883 List request = new List(2); |
| 884 request[0] = _FileUtils.kPositionRequest; | 884 request[0] = _FileUtils.kPositionRequest; |
| 885 request[1] = _id; | 885 request[1] = _id; |
| 886 _fileService.call(request).receive((result, replyTo) { | 886 _fileService.call(request).then((result) { |
| 887 if (result != -1) { | 887 if (result != -1) { |
| 888 callback(result); | 888 callback(result); |
| 889 } else if (_onError != null) { | 889 } else if (_onError != null) { |
| 890 _onError("position failed"); | 890 _onError("position failed"); |
| 891 } | 891 } |
| 892 }); | 892 }); |
| 893 } | 893 } |
| 894 | 894 |
| 895 int positionSync() { | 895 int positionSync() { |
| 896 if (_asyncUsed) { | 896 if (_asyncUsed) { |
| 897 throw new FileIOException( | 897 throw new FileIOException( |
| 898 "Mixed use of synchronous and asynchronous API"); | 898 "Mixed use of synchronous and asynchronous API"); |
| 899 } | 899 } |
| 900 int result = _FileUtils.position(_id); | 900 int result = _FileUtils.position(_id); |
| 901 if (result == -1) { | 901 if (result == -1) { |
| 902 throw new FileIOException("position failed"); | 902 throw new FileIOException("position failed"); |
| 903 } | 903 } |
| 904 return result; | 904 return result; |
| 905 } | 905 } |
| 906 | 906 |
| 907 void setPosition(int position, void callback()) { | 907 void setPosition(int position, void callback()) { |
| 908 _ensureFileService(); | 908 _ensureFileService(); |
| 909 _asyncUsed = true; | 909 _asyncUsed = true; |
| 910 List request = new List(3); | 910 List request = new List(3); |
| 911 request[0] = _FileUtils.kSetPositionRequest; | 911 request[0] = _FileUtils.kSetPositionRequest; |
| 912 request[1] = _id; | 912 request[1] = _id; |
| 913 request[2] = position; | 913 request[2] = position; |
| 914 _fileService.call(request).receive((result, replyTo) { | 914 _fileService.call(request).then((result) { |
| 915 if (result) { | 915 if (result) { |
| 916 callback(); | 916 callback(); |
| 917 } else if (_onError != null) { | 917 } else if (_onError != null) { |
| 918 _onError("setPosition failed"); | 918 _onError("setPosition failed"); |
| 919 } | 919 } |
| 920 }); | 920 }); |
| 921 } | 921 } |
| 922 | 922 |
| 923 void setPositionSync(int position) { | 923 void setPositionSync(int position) { |
| 924 _ensureFileService(); | 924 _ensureFileService(); |
| 925 if (_asyncUsed) { | 925 if (_asyncUsed) { |
| 926 throw new FileIOException( | 926 throw new FileIOException( |
| 927 "Mixed use of synchronous and asynchronous API"); | 927 "Mixed use of synchronous and asynchronous API"); |
| 928 } | 928 } |
| 929 bool result = _FileUtils.setPosition(_id, position); | 929 bool result = _FileUtils.setPosition(_id, position); |
| 930 if (result == false) { | 930 if (result == false) { |
| 931 throw new FileIOException("setPosition failed"); | 931 throw new FileIOException("setPosition failed"); |
| 932 } | 932 } |
| 933 } | 933 } |
| 934 | 934 |
| 935 void truncate(int length, void callback()) { | 935 void truncate(int length, void callback()) { |
| 936 _ensureFileService(); | 936 _ensureFileService(); |
| 937 _asyncUsed = true; | 937 _asyncUsed = true; |
| 938 List request = new List(3); | 938 List request = new List(3); |
| 939 request[0] = _FileUtils.kTruncateRequest; | 939 request[0] = _FileUtils.kTruncateRequest; |
| 940 request[1] = _id; | 940 request[1] = _id; |
| 941 request[2] = length; | 941 request[2] = length; |
| 942 _fileService.call(request).receive((result, replyTo) { | 942 _fileService.call(request).then((result) { |
| 943 if (result) { | 943 if (result) { |
| 944 callback(); | 944 callback(); |
| 945 } else if (_onError != null) { | 945 } else if (_onError != null) { |
| 946 _onError("truncate failed"); | 946 _onError("truncate failed"); |
| 947 } | 947 } |
| 948 }); | 948 }); |
| 949 } | 949 } |
| 950 | 950 |
| 951 void truncateSync(int length) { | 951 void truncateSync(int length) { |
| 952 if (_asyncUsed) { | 952 if (_asyncUsed) { |
| 953 throw new FileIOException( | 953 throw new FileIOException( |
| 954 "Mixed use of synchronous and asynchronous API"); | 954 "Mixed use of synchronous and asynchronous API"); |
| 955 } | 955 } |
| 956 bool result = _FileUtils.truncate(_id, length); | 956 bool result = _FileUtils.truncate(_id, length); |
| 957 if (result == false) { | 957 if (result == false) { |
| 958 throw new FileIOException("truncate failed"); | 958 throw new FileIOException("truncate failed"); |
| 959 } | 959 } |
| 960 } | 960 } |
| 961 | 961 |
| 962 void length(void callback(int length)) { | 962 void length(void callback(int length)) { |
| 963 _ensureFileService(); | 963 _ensureFileService(); |
| 964 _asyncUsed = true; | 964 _asyncUsed = true; |
| 965 List request = new List(2); | 965 List request = new List(2); |
| 966 request[0] = _FileUtils.kLengthRequest; | 966 request[0] = _FileUtils.kLengthRequest; |
| 967 request[1] = _id; | 967 request[1] = _id; |
| 968 _fileService.call(request).receive((result, replyTo) { | 968 _fileService.call(request).then((result) { |
| 969 if (result != -1) { | 969 if (result != -1) { |
| 970 callback(result); | 970 callback(result); |
| 971 } else if (_onError != null) { | 971 } else if (_onError != null) { |
| 972 _onError("length failed"); | 972 _onError("length failed"); |
| 973 } | 973 } |
| 974 }); | 974 }); |
| 975 } | 975 } |
| 976 | 976 |
| 977 int lengthSync() { | 977 int lengthSync() { |
| 978 if (_asyncUsed) { | 978 if (_asyncUsed) { |
| 979 throw new FileIOException( | 979 throw new FileIOException( |
| 980 "Mixed use of synchronous and asynchronous API"); | 980 "Mixed use of synchronous and asynchronous API"); |
| 981 } | 981 } |
| 982 int result = _FileUtils.length(_id); | 982 int result = _FileUtils.length(_id); |
| 983 if (result == -1) { | 983 if (result == -1) { |
| 984 throw new FileIOException("length failed"); | 984 throw new FileIOException("length failed"); |
| 985 } | 985 } |
| 986 return result; | 986 return result; |
| 987 } | 987 } |
| 988 | 988 |
| 989 void flush(void callback()) { | 989 void flush(void callback()) { |
| 990 _ensureFileService(); | 990 _ensureFileService(); |
| 991 _asyncUsed = true; | 991 _asyncUsed = true; |
| 992 List request = new List(2); | 992 List request = new List(2); |
| 993 request[0] = _FileUtils.kFlushRequest; | 993 request[0] = _FileUtils.kFlushRequest; |
| 994 request[1] = _id; | 994 request[1] = _id; |
| 995 _fileService.call(request).receive((result, replyTo) { | 995 _fileService.call(request).then((result) { |
| 996 if (result != -1) { | 996 if (result != -1) { |
| 997 callback(); | 997 callback(); |
| 998 } else if (_onError != null) { | 998 } else if (_onError != null) { |
| 999 _onError("flush failed"); | 999 _onError("flush failed"); |
| 1000 } | 1000 } |
| 1001 }); | 1001 }); |
| 1002 } | 1002 } |
| 1003 | 1003 |
| 1004 void flushSync() { | 1004 void flushSync() { |
| 1005 if (_asyncUsed) { | 1005 if (_asyncUsed) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 bool _asyncUsed; | 1054 bool _asyncUsed; |
| 1055 int _pendingWrites = 0; | 1055 int _pendingWrites = 0; |
| 1056 | 1056 |
| 1057 SendPort _fileService; | 1057 SendPort _fileService; |
| 1058 | 1058 |
| 1059 Timer _noPendingWriteTimer; | 1059 Timer _noPendingWriteTimer; |
| 1060 | 1060 |
| 1061 Function _onNoPendingWrites; | 1061 Function _onNoPendingWrites; |
| 1062 Function _onError; | 1062 Function _onError; |
| 1063 } | 1063 } |
| OLD | NEW |