Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 11312122: Change List constructors. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload. Adapt code for List.fixedLength. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/directory_impl.dart ('k') | sdk/lib/isolate/mangler.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 : _data = const [], 7 : _data = const [],
8 _position = 0, 8 _position = 0,
9 _filePosition = 0 { 9 _filePosition = 0 {
10 var file = new File(name); 10 var file = new File(name);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 throw new ArgumentError('${Error.safeToString(_name)} ' 353 throw new ArgumentError('${Error.safeToString(_name)} '
354 'is not a String'); 354 'is not a String');
355 } 355 }
356 } 356 }
357 357
358 // Constructor from Path for file. 358 // Constructor from Path for file.
359 _File.fromPath(Path path) : this(path.toNativePath()); 359 _File.fromPath(Path path) : this(path.toNativePath());
360 360
361 Future<bool> exists() { 361 Future<bool> exists() {
362 _ensureFileService(); 362 _ensureFileService();
363 List request = new List(2); 363 List request = new List.fixedLength(2);
364 request[0] = _EXISTS_REQUEST; 364 request[0] = _EXISTS_REQUEST;
365 request[1] = _name; 365 request[1] = _name;
366 return _fileService.call(request).then((response) { 366 return _fileService.call(request).then((response) {
367 if (_isErrorResponse(response)) { 367 if (_isErrorResponse(response)) {
368 throw _exceptionFromResponse(response, "Cannot open file '$_name'"); 368 throw _exceptionFromResponse(response, "Cannot open file '$_name'");
369 } 369 }
370 return response; 370 return response;
371 }); 371 });
372 } 372 }
373 373
374 external static _exists(String name); 374 external static _exists(String name);
375 375
376 bool existsSync() { 376 bool existsSync() {
377 var result = _exists(_name); 377 var result = _exists(_name);
378 throwIfError(result, "Cannot check existence of file '$_name'"); 378 throwIfError(result, "Cannot check existence of file '$_name'");
379 return result; 379 return result;
380 } 380 }
381 381
382 Future<File> create() { 382 Future<File> create() {
383 _ensureFileService(); 383 _ensureFileService();
384 List request = new List(2); 384 List request = new List.fixedLength(2);
385 request[0] = _CREATE_REQUEST; 385 request[0] = _CREATE_REQUEST;
386 request[1] = _name; 386 request[1] = _name;
387 return _fileService.call(request).then((response) { 387 return _fileService.call(request).then((response) {
388 if (_isErrorResponse(response)) { 388 if (_isErrorResponse(response)) {
389 throw _exceptionFromResponse(response, "Cannot create file '$_name'"); 389 throw _exceptionFromResponse(response, "Cannot create file '$_name'");
390 } 390 }
391 return this; 391 return this;
392 }); 392 });
393 } 393 }
394 394
395 external static _create(String name); 395 external static _create(String name);
396 396
397 void createSync() { 397 void createSync() {
398 var result = _create(_name); 398 var result = _create(_name);
399 throwIfError(result, "Cannot create file '$_name'"); 399 throwIfError(result, "Cannot create file '$_name'");
400 } 400 }
401 401
402 Future<File> delete() { 402 Future<File> delete() {
403 _ensureFileService(); 403 _ensureFileService();
404 List request = new List(2); 404 List request = new List.fixedLength(2);
405 request[0] = _DELETE_REQUEST; 405 request[0] = _DELETE_REQUEST;
406 request[1] = _name; 406 request[1] = _name;
407 return _fileService.call(request).then((response) { 407 return _fileService.call(request).then((response) {
408 if (_isErrorResponse(response)) { 408 if (_isErrorResponse(response)) {
409 throw _exceptionFromResponse(response, "Cannot delete file '$_name'"); 409 throw _exceptionFromResponse(response, "Cannot delete file '$_name'");
410 } 410 }
411 return this; 411 return this;
412 }); 412 });
413 } 413 }
414 414
415 external static _delete(String name); 415 external static _delete(String name);
416 416
417 void deleteSync() { 417 void deleteSync() {
418 var result = _delete(_name); 418 var result = _delete(_name);
419 throwIfError(result, "Cannot delete file '$_name'"); 419 throwIfError(result, "Cannot delete file '$_name'");
420 } 420 }
421 421
422 Future<Directory> directory() { 422 Future<Directory> directory() {
423 _ensureFileService(); 423 _ensureFileService();
424 List request = new List(2); 424 List request = new List.fixedLength(2);
425 request[0] = _DIRECTORY_REQUEST; 425 request[0] = _DIRECTORY_REQUEST;
426 request[1] = _name; 426 request[1] = _name;
427 return _fileService.call(request).then((response) { 427 return _fileService.call(request).then((response) {
428 if (_isErrorResponse(response)) { 428 if (_isErrorResponse(response)) {
429 throw _exceptionFromResponse(response, 429 throw _exceptionFromResponse(response,
430 "Cannot retrieve directory for " 430 "Cannot retrieve directory for "
431 "file '$_name'"); 431 "file '$_name'");
432 } 432 }
433 return new Directory(response); 433 return new Directory(response);
434 }); 434 });
(...skipping 11 matching lines...) Expand all
446 _ensureFileService(); 446 _ensureFileService();
447 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 447 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
448 if (mode != FileMode.READ && 448 if (mode != FileMode.READ &&
449 mode != FileMode.WRITE && 449 mode != FileMode.WRITE &&
450 mode != FileMode.APPEND) { 450 mode != FileMode.APPEND) {
451 new Timer(0, (t) { 451 new Timer(0, (t) {
452 completer.completeError(new ArgumentError()); 452 completer.completeError(new ArgumentError());
453 }); 453 });
454 return completer.future; 454 return completer.future;
455 } 455 }
456 List request = new List(3); 456 List request = new List.fixedLength(3);
457 request[0] = _OPEN_REQUEST; 457 request[0] = _OPEN_REQUEST;
458 request[1] = _name; 458 request[1] = _name;
459 request[2] = mode._mode; // Direct int value for serialization. 459 request[2] = mode._mode; // Direct int value for serialization.
460 return _fileService.call(request).then((response) { 460 return _fileService.call(request).then((response) {
461 if (_isErrorResponse(response)) { 461 if (_isErrorResponse(response)) {
462 throw _exceptionFromResponse(response, "Cannot open file '$_name'"); 462 throw _exceptionFromResponse(response, "Cannot open file '$_name'");
463 } 463 }
464 return new _RandomAccessFile(response, _name); 464 return new _RandomAccessFile(response, _name);
465 }); 465 });
466 } 466 }
467 467
468 Future<int> length() { 468 Future<int> length() {
469 _ensureFileService(); 469 _ensureFileService();
470 List request = new List(2); 470 List request = new List.fixedLength(2);
471 request[0] = _LENGTH_FROM_NAME_REQUEST; 471 request[0] = _LENGTH_FROM_NAME_REQUEST;
472 request[1] = _name; 472 request[1] = _name;
473 return _fileService.call(request).then((response) { 473 return _fileService.call(request).then((response) {
474 if (_isErrorResponse(response)) { 474 if (_isErrorResponse(response)) {
475 throw _exceptionFromResponse(response, 475 throw _exceptionFromResponse(response,
476 "Cannot retrieve length of " 476 "Cannot retrieve length of "
477 "file '$_name'"); 477 "file '$_name'");
478 } 478 }
479 return response; 479 return response;
480 }); 480 });
481 } 481 }
482 482
483 483
484 external static _lengthFromName(String name); 484 external static _lengthFromName(String name);
485 485
486 int lengthSync() { 486 int lengthSync() {
487 var result = _lengthFromName(_name); 487 var result = _lengthFromName(_name);
488 throwIfError(result, "Cannot retrieve length of file '$_name'"); 488 throwIfError(result, "Cannot retrieve length of file '$_name'");
489 return result; 489 return result;
490 } 490 }
491 491
492 Future<Date> lastModified() { 492 Future<Date> lastModified() {
493 _ensureFileService(); 493 _ensureFileService();
494 List request = new List(2); 494 List request = new List.fixedLength(2);
495 request[0] = _LAST_MODIFIED_REQUEST; 495 request[0] = _LAST_MODIFIED_REQUEST;
496 request[1] = _name; 496 request[1] = _name;
497 return _fileService.call(request).then((response) { 497 return _fileService.call(request).then((response) {
498 if (_isErrorResponse(response)) { 498 if (_isErrorResponse(response)) {
499 throw _exceptionFromResponse(response, 499 throw _exceptionFromResponse(response,
500 "Cannot retrieve modification time " 500 "Cannot retrieve modification time "
501 "for file '$_name'"); 501 "for file '$_name'");
502 } 502 }
503 return new Date.fromMillisecondsSinceEpoch(response); 503 return new Date.fromMillisecondsSinceEpoch(response);
504 }); 504 });
(...skipping 26 matching lines...) Expand all
531 static RandomAccessFile _openStdioSync(int fd) { 531 static RandomAccessFile _openStdioSync(int fd) {
532 var id = _openStdio(fd); 532 var id = _openStdio(fd);
533 if (id == 0) { 533 if (id == 0) {
534 throw new FileIOException("Cannot open stdio file for: $fd"); 534 throw new FileIOException("Cannot open stdio file for: $fd");
535 } 535 }
536 return new _RandomAccessFile(id, ""); 536 return new _RandomAccessFile(id, "");
537 } 537 }
538 538
539 Future<String> fullPath() { 539 Future<String> fullPath() {
540 _ensureFileService(); 540 _ensureFileService();
541 List request = new List(2); 541 List request = new List.fixedLength(2);
542 request[0] = _FULL_PATH_REQUEST; 542 request[0] = _FULL_PATH_REQUEST;
543 request[1] = _name; 543 request[1] = _name;
544 return _fileService.call(request).then((response) { 544 return _fileService.call(request).then((response) {
545 if (_isErrorResponse(response)) { 545 if (_isErrorResponse(response)) {
546 throw _exceptionFromResponse(response, 546 throw _exceptionFromResponse(response,
547 "Cannot retrieve full path" 547 "Cannot retrieve full path"
548 " for '$_name'"); 548 " for '$_name'");
549 } 549 }
550 return response; 550 return response;
551 }); 551 });
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 } 740 }
741 741
742 742
743 class _RandomAccessFile extends _FileBase implements RandomAccessFile { 743 class _RandomAccessFile extends _FileBase implements RandomAccessFile {
744 _RandomAccessFile(int this._id, String this._name); 744 _RandomAccessFile(int this._id, String this._name);
745 745
746 Future<RandomAccessFile> close() { 746 Future<RandomAccessFile> close() {
747 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 747 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
748 if (closed) return _completeWithClosedException(completer); 748 if (closed) return _completeWithClosedException(completer);
749 _ensureFileService(); 749 _ensureFileService();
750 List request = new List(2); 750 List request = new List.fixedLength(2);
751 request[0] = _CLOSE_REQUEST; 751 request[0] = _CLOSE_REQUEST;
752 request[1] = _id; 752 request[1] = _id;
753 // Set the id_ to 0 (NULL) to ensure the no more async requests 753 // Set the id_ to 0 (NULL) to ensure the no more async requests
754 // can be issued for this file. 754 // can be issued for this file.
755 _id = 0; 755 _id = 0;
756 return _fileService.call(request).then((result) { 756 return _fileService.call(request).then((result) {
757 if (result != -1) { 757 if (result != -1) {
758 _id = result; 758 _id = result;
759 return this; 759 return this;
760 } else { 760 } else {
(...skipping 10 matching lines...) Expand all
771 if (id == -1) { 771 if (id == -1) {
772 throw new FileIOException("Cannot close file '$_name'"); 772 throw new FileIOException("Cannot close file '$_name'");
773 } 773 }
774 _id = id; 774 _id = id;
775 } 775 }
776 776
777 Future<int> readByte() { 777 Future<int> readByte() {
778 _ensureFileService(); 778 _ensureFileService();
779 Completer<int> completer = new Completer<int>(); 779 Completer<int> completer = new Completer<int>();
780 if (closed) return _completeWithClosedException(completer); 780 if (closed) return _completeWithClosedException(completer);
781 List request = new List(2); 781 List request = new List.fixedLength(2);
782 request[0] = _READ_BYTE_REQUEST; 782 request[0] = _READ_BYTE_REQUEST;
783 request[1] = _id; 783 request[1] = _id;
784 return _fileService.call(request).then((response) { 784 return _fileService.call(request).then((response) {
785 if (_isErrorResponse(response)) { 785 if (_isErrorResponse(response)) {
786 throw _exceptionFromResponse(response, 786 throw _exceptionFromResponse(response,
787 "readByte failed for file '$_name'"); 787 "readByte failed for file '$_name'");
788 } 788 }
789 return response; 789 return response;
790 }); 790 });
791 } 791 }
(...skipping 16 matching lines...) Expand all
808 // Complete asynchronously so the user has a chance to setup 808 // Complete asynchronously so the user has a chance to setup
809 // handlers without getting exceptions when registering the 809 // handlers without getting exceptions when registering the
810 // then handler. 810 // then handler.
811 new Timer(0, (t) { 811 new Timer(0, (t) {
812 completer.completeError(new FileIOException( 812 completer.completeError(new FileIOException(
813 "Invalid arguments to readList for file '$_name'")); 813 "Invalid arguments to readList for file '$_name'"));
814 }); 814 });
815 return completer.future; 815 return completer.future;
816 }; 816 };
817 if (closed) return _completeWithClosedException(completer); 817 if (closed) return _completeWithClosedException(completer);
818 List request = new List(3); 818 List request = new List.fixedLength(3);
819 request[0] = _READ_LIST_REQUEST; 819 request[0] = _READ_LIST_REQUEST;
820 request[1] = _id; 820 request[1] = _id;
821 request[2] = bytes; 821 request[2] = bytes;
822 return _fileService.call(request).then((response) { 822 return _fileService.call(request).then((response) {
823 if (_isErrorResponse(response)) { 823 if (_isErrorResponse(response)) {
824 throw _exceptionFromResponse(response, 824 throw _exceptionFromResponse(response,
825 "readList failed for file '$_name'"); 825 "readList failed for file '$_name'");
826 } 826 }
827 var read = response[1]; 827 var read = response[1];
828 var data = response[2]; 828 var data = response[2];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // Complete asynchronously so the user has a chance to setup 864 // Complete asynchronously so the user has a chance to setup
865 // handlers without getting exceptions when registering the 865 // handlers without getting exceptions when registering the
866 // then handler. 866 // then handler.
867 new Timer(0, (t) { 867 new Timer(0, (t) {
868 completer.completeError(new FileIOException( 868 completer.completeError(new FileIOException(
869 "Invalid argument to writeByte for file '$_name'")); 869 "Invalid argument to writeByte for file '$_name'"));
870 }); 870 });
871 return completer.future; 871 return completer.future;
872 } 872 }
873 if (closed) return _completeWithClosedException(completer); 873 if (closed) return _completeWithClosedException(completer);
874 List request = new List(3); 874 List request = new List.fixedLength(3);
875 request[0] = _WRITE_BYTE_REQUEST; 875 request[0] = _WRITE_BYTE_REQUEST;
876 request[1] = _id; 876 request[1] = _id;
877 request[2] = value; 877 request[2] = value;
878 return _fileService.call(request).then((response) { 878 return _fileService.call(request).then((response) {
879 if (_isErrorResponse(response)) { 879 if (_isErrorResponse(response)) {
880 throw _exceptionFromResponse(response, 880 throw _exceptionFromResponse(response,
881 "writeByte failed for file '$_name'"); 881 "writeByte failed for file '$_name'");
882 } 882 }
883 return this; 883 return this;
884 }); 884 });
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 try { 919 try {
920 result = _ensureFastAndSerializableBuffer(buffer, offset, bytes); 920 result = _ensureFastAndSerializableBuffer(buffer, offset, bytes);
921 } catch (e) { 921 } catch (e) {
922 // Complete asynchronously so the user has a chance to setup 922 // Complete asynchronously so the user has a chance to setup
923 // handlers without getting exceptions when registering the 923 // handlers without getting exceptions when registering the
924 // then handler. 924 // then handler.
925 new Timer(0, (t) => completer.completeError(e)); 925 new Timer(0, (t) => completer.completeError(e));
926 return completer.future; 926 return completer.future;
927 } 927 }
928 928
929 List request = new List(5); 929 List request = new List.fixedLength(5);
930 request[0] = _WRITE_LIST_REQUEST; 930 request[0] = _WRITE_LIST_REQUEST;
931 request[1] = _id; 931 request[1] = _id;
932 request[2] = result.buffer; 932 request[2] = result.buffer;
933 request[3] = result.offset; 933 request[3] = result.offset;
934 request[4] = bytes; 934 request[4] = bytes;
935 return _fileService.call(request).then((response) { 935 return _fileService.call(request).then((response) {
936 if (_isErrorResponse(response)) { 936 if (_isErrorResponse(response)) {
937 throw _exceptionFromResponse(response, 937 throw _exceptionFromResponse(response,
938 "writeList failed for file '$_name'"); 938 "writeList failed for file '$_name'");
939 } 939 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 "Invalid encoding in writeStringSync: $encoding"); 981 "Invalid encoding in writeStringSync: $encoding");
982 } 982 }
983 var data = _StringEncoders.encoder(encoding).encodeString(string); 983 var data = _StringEncoders.encoder(encoding).encodeString(string);
984 return writeListSync(data, 0, data.length); 984 return writeListSync(data, 0, data.length);
985 } 985 }
986 986
987 Future<int> position() { 987 Future<int> position() {
988 _ensureFileService(); 988 _ensureFileService();
989 Completer<int> completer = new Completer<int>(); 989 Completer<int> completer = new Completer<int>();
990 if (closed) return _completeWithClosedException(completer); 990 if (closed) return _completeWithClosedException(completer);
991 List request = new List(2); 991 List request = new List.fixedLength(2);
992 request[0] = _POSITION_REQUEST; 992 request[0] = _POSITION_REQUEST;
993 request[1] = _id; 993 request[1] = _id;
994 return _fileService.call(request).then((response) { 994 return _fileService.call(request).then((response) {
995 if (_isErrorResponse(response)) { 995 if (_isErrorResponse(response)) {
996 throw _exceptionFromResponse(response, 996 throw _exceptionFromResponse(response,
997 "position failed for file '$_name'"); 997 "position failed for file '$_name'");
998 } 998 }
999 return response; 999 return response;
1000 }); 1000 });
1001 } 1001 }
1002 1002
1003 external static _position(int id); 1003 external static _position(int id);
1004 1004
1005 int positionSync() { 1005 int positionSync() {
1006 _checkNotClosed(); 1006 _checkNotClosed();
1007 var result = _position(_id); 1007 var result = _position(_id);
1008 if (result is OSError) { 1008 if (result is OSError) {
1009 throw new FileIOException("position failed for file '$_name'", result); 1009 throw new FileIOException("position failed for file '$_name'", result);
1010 } 1010 }
1011 return result; 1011 return result;
1012 } 1012 }
1013 1013
1014 Future<RandomAccessFile> setPosition(int position) { 1014 Future<RandomAccessFile> setPosition(int position) {
1015 _ensureFileService(); 1015 _ensureFileService();
1016 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 1016 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
1017 if (closed) return _completeWithClosedException(completer); 1017 if (closed) return _completeWithClosedException(completer);
1018 List request = new List(3); 1018 List request = new List.fixedLength(3);
1019 request[0] = _SET_POSITION_REQUEST; 1019 request[0] = _SET_POSITION_REQUEST;
1020 request[1] = _id; 1020 request[1] = _id;
1021 request[2] = position; 1021 request[2] = position;
1022 return _fileService.call(request).then((response) { 1022 return _fileService.call(request).then((response) {
1023 if (_isErrorResponse(response)) { 1023 if (_isErrorResponse(response)) {
1024 throw _exceptionFromResponse(response, 1024 throw _exceptionFromResponse(response,
1025 "setPosition failed for file '$_name'"); 1025 "setPosition failed for file '$_name'");
1026 } 1026 }
1027 return this; 1027 return this;
1028 }); 1028 });
1029 } 1029 }
1030 1030
1031 external static _setPosition(int id, int position); 1031 external static _setPosition(int id, int position);
1032 1032
1033 void setPositionSync(int position) { 1033 void setPositionSync(int position) {
1034 _checkNotClosed(); 1034 _checkNotClosed();
1035 var result = _setPosition(_id, position); 1035 var result = _setPosition(_id, position);
1036 if (result is OSError) { 1036 if (result is OSError) {
1037 throw new FileIOException("setPosition failed for file '$_name'", result); 1037 throw new FileIOException("setPosition failed for file '$_name'", result);
1038 } 1038 }
1039 } 1039 }
1040 1040
1041 Future<RandomAccessFile> truncate(int length) { 1041 Future<RandomAccessFile> truncate(int length) {
1042 _ensureFileService(); 1042 _ensureFileService();
1043 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 1043 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
1044 if (closed) return _completeWithClosedException(completer); 1044 if (closed) return _completeWithClosedException(completer);
1045 List request = new List(3); 1045 List request = new List.fixedLength(3);
1046 request[0] = _TRUNCATE_REQUEST; 1046 request[0] = _TRUNCATE_REQUEST;
1047 request[1] = _id; 1047 request[1] = _id;
1048 request[2] = length; 1048 request[2] = length;
1049 return _fileService.call(request).then((response) { 1049 return _fileService.call(request).then((response) {
1050 if (_isErrorResponse(response)) { 1050 if (_isErrorResponse(response)) {
1051 throw _exceptionFromResponse(response, 1051 throw _exceptionFromResponse(response,
1052 "truncate failed for file '$_name'"); 1052 "truncate failed for file '$_name'");
1053 } 1053 }
1054 return this; 1054 return this;
1055 }); 1055 });
1056 } 1056 }
1057 1057
1058 external static _truncate(int id, int length); 1058 external static _truncate(int id, int length);
1059 1059
1060 void truncateSync(int length) { 1060 void truncateSync(int length) {
1061 _checkNotClosed(); 1061 _checkNotClosed();
1062 var result = _truncate(_id, length); 1062 var result = _truncate(_id, length);
1063 if (result is OSError) { 1063 if (result is OSError) {
1064 throw new FileIOException("truncate failed for file '$_name'", result); 1064 throw new FileIOException("truncate failed for file '$_name'", result);
1065 } 1065 }
1066 } 1066 }
1067 1067
1068 Future<int> length() { 1068 Future<int> length() {
1069 _ensureFileService(); 1069 _ensureFileService();
1070 Completer<int> completer = new Completer<int>(); 1070 Completer<int> completer = new Completer<int>();
1071 if (closed) return _completeWithClosedException(completer); 1071 if (closed) return _completeWithClosedException(completer);
1072 List request = new List(2); 1072 List request = new List.fixedLength(2);
1073 request[0] = _LENGTH_REQUEST; 1073 request[0] = _LENGTH_REQUEST;
1074 request[1] = _id; 1074 request[1] = _id;
1075 return _fileService.call(request).then((response) { 1075 return _fileService.call(request).then((response) {
1076 if (_isErrorResponse(response)) { 1076 if (_isErrorResponse(response)) {
1077 throw _exceptionFromResponse(response, 1077 throw _exceptionFromResponse(response,
1078 "length failed for file '$_name'"); 1078 "length failed for file '$_name'");
1079 } 1079 }
1080 return response; 1080 return response;
1081 }); 1081 });
1082 } 1082 }
1083 1083
1084 external static _length(int id); 1084 external static _length(int id);
1085 1085
1086 int lengthSync() { 1086 int lengthSync() {
1087 _checkNotClosed(); 1087 _checkNotClosed();
1088 var result = _length(_id); 1088 var result = _length(_id);
1089 if (result is OSError) { 1089 if (result is OSError) {
1090 throw new FileIOException("length failed for file '$_name'", result); 1090 throw new FileIOException("length failed for file '$_name'", result);
1091 } 1091 }
1092 return result; 1092 return result;
1093 } 1093 }
1094 1094
1095 Future<RandomAccessFile> flush() { 1095 Future<RandomAccessFile> flush() {
1096 _ensureFileService(); 1096 _ensureFileService();
1097 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 1097 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
1098 if (closed) return _completeWithClosedException(completer); 1098 if (closed) return _completeWithClosedException(completer);
1099 List request = new List(2); 1099 List request = new List.fixedLength(2);
1100 request[0] = _FLUSH_REQUEST; 1100 request[0] = _FLUSH_REQUEST;
1101 request[1] = _id; 1101 request[1] = _id;
1102 return _fileService.call(request).then((response) { 1102 return _fileService.call(request).then((response) {
1103 if (_isErrorResponse(response)) { 1103 if (_isErrorResponse(response)) {
1104 throw _exceptionFromResponse(response, 1104 throw _exceptionFromResponse(response,
1105 "flush failed for file '$_name'"); 1105 "flush failed for file '$_name'");
1106 } 1106 }
1107 return this; 1107 return this;
1108 }); 1108 });
1109 } 1109 }
(...skipping 30 matching lines...) Expand all
1140 new FileIOException("File closed '$_name'")); 1140 new FileIOException("File closed '$_name'"));
1141 }); 1141 });
1142 return completer.future; 1142 return completer.future;
1143 } 1143 }
1144 1144
1145 final String _name; 1145 final String _name;
1146 int _id; 1146 int _id;
1147 1147
1148 SendPort _fileService; 1148 SendPort _fileService;
1149 } 1149 }
OLDNEW
« no previous file with comments | « sdk/lib/io/directory_impl.dart ('k') | sdk/lib/isolate/mangler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698