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

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

Issue 12328104: Change new List(n) to return fixed length list. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Merge to head. Created 7 years, 9 months 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 7
8 class _FileStream extends Stream<List<int>> { 8 class _FileStream extends Stream<List<int>> {
9 // Stream controller. 9 // Stream controller.
10 StreamController<List<int>> _controller; 10 StreamController<List<int>> _controller;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 throw new ArgumentError('${Error.safeToString(_name)} ' 258 throw new ArgumentError('${Error.safeToString(_name)} '
259 'is not a String'); 259 'is not a String');
260 } 260 }
261 } 261 }
262 262
263 // Constructor from Path for file. 263 // Constructor from Path for file.
264 _File.fromPath(Path path) : this(path.toNativePath()); 264 _File.fromPath(Path path) : this(path.toNativePath());
265 265
266 Future<bool> exists() { 266 Future<bool> exists() {
267 _ensureFileService(); 267 _ensureFileService();
268 List request = new List.fixedLength(2); 268 List request = new List(2);
269 request[0] = _EXISTS_REQUEST; 269 request[0] = _EXISTS_REQUEST;
270 request[1] = _name; 270 request[1] = _name;
271 return _fileService.call(request).then((response) { 271 return _fileService.call(request).then((response) {
272 if (_isErrorResponse(response)) { 272 if (_isErrorResponse(response)) {
273 throw _exceptionFromResponse(response, "Cannot open file '$_name'"); 273 throw _exceptionFromResponse(response, "Cannot open file '$_name'");
274 } 274 }
275 return response; 275 return response;
276 }); 276 });
277 } 277 }
278 278
279 external static _exists(String name); 279 external static _exists(String name);
280 280
281 bool existsSync() { 281 bool existsSync() {
282 var result = _exists(_name); 282 var result = _exists(_name);
283 throwIfError(result, "Cannot check existence of file '$_name'"); 283 throwIfError(result, "Cannot check existence of file '$_name'");
284 return result; 284 return result;
285 } 285 }
286 286
287 Future<File> create() { 287 Future<File> create() {
288 _ensureFileService(); 288 _ensureFileService();
289 List request = new List.fixedLength(2); 289 List request = new List(2);
290 request[0] = _CREATE_REQUEST; 290 request[0] = _CREATE_REQUEST;
291 request[1] = _name; 291 request[1] = _name;
292 return _fileService.call(request).then((response) { 292 return _fileService.call(request).then((response) {
293 if (_isErrorResponse(response)) { 293 if (_isErrorResponse(response)) {
294 throw _exceptionFromResponse(response, "Cannot create file '$_name'"); 294 throw _exceptionFromResponse(response, "Cannot create file '$_name'");
295 } 295 }
296 return this; 296 return this;
297 }); 297 });
298 } 298 }
299 299
300 external static _create(String name); 300 external static _create(String name);
301 301
302 void createSync() { 302 void createSync() {
303 var result = _create(_name); 303 var result = _create(_name);
304 throwIfError(result, "Cannot create file '$_name'"); 304 throwIfError(result, "Cannot create file '$_name'");
305 } 305 }
306 306
307 Future<File> delete() { 307 Future<File> delete() {
308 _ensureFileService(); 308 _ensureFileService();
309 List request = new List.fixedLength(2); 309 List request = new List(2);
310 request[0] = _DELETE_REQUEST; 310 request[0] = _DELETE_REQUEST;
311 request[1] = _name; 311 request[1] = _name;
312 return _fileService.call(request).then((response) { 312 return _fileService.call(request).then((response) {
313 if (_isErrorResponse(response)) { 313 if (_isErrorResponse(response)) {
314 throw _exceptionFromResponse(response, "Cannot delete file '$_name'"); 314 throw _exceptionFromResponse(response, "Cannot delete file '$_name'");
315 } 315 }
316 return this; 316 return this;
317 }); 317 });
318 } 318 }
319 319
320 external static _delete(String name); 320 external static _delete(String name);
321 321
322 void deleteSync() { 322 void deleteSync() {
323 var result = _delete(_name); 323 var result = _delete(_name);
324 throwIfError(result, "Cannot delete file '$_name'"); 324 throwIfError(result, "Cannot delete file '$_name'");
325 } 325 }
326 326
327 Future<Directory> directory() { 327 Future<Directory> directory() {
328 _ensureFileService(); 328 _ensureFileService();
329 List request = new List.fixedLength(2); 329 List request = new List(2);
330 request[0] = _DIRECTORY_REQUEST; 330 request[0] = _DIRECTORY_REQUEST;
331 request[1] = _name; 331 request[1] = _name;
332 return _fileService.call(request).then((response) { 332 return _fileService.call(request).then((response) {
333 if (_isErrorResponse(response)) { 333 if (_isErrorResponse(response)) {
334 throw _exceptionFromResponse(response, 334 throw _exceptionFromResponse(response,
335 "Cannot retrieve directory for " 335 "Cannot retrieve directory for "
336 "file '$_name'"); 336 "file '$_name'");
337 } 337 }
338 return new Directory(response); 338 return new Directory(response);
339 }); 339 });
(...skipping 11 matching lines...) Expand all
351 _ensureFileService(); 351 _ensureFileService();
352 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 352 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
353 if (mode != FileMode.READ && 353 if (mode != FileMode.READ &&
354 mode != FileMode.WRITE && 354 mode != FileMode.WRITE &&
355 mode != FileMode.APPEND) { 355 mode != FileMode.APPEND) {
356 Timer.run(() { 356 Timer.run(() {
357 completer.completeError(new ArgumentError()); 357 completer.completeError(new ArgumentError());
358 }); 358 });
359 return completer.future; 359 return completer.future;
360 } 360 }
361 List request = new List.fixedLength(3); 361 List request = new List(3);
362 request[0] = _OPEN_REQUEST; 362 request[0] = _OPEN_REQUEST;
363 request[1] = _name; 363 request[1] = _name;
364 request[2] = mode._mode; // Direct int value for serialization. 364 request[2] = mode._mode; // Direct int value for serialization.
365 return _fileService.call(request).then((response) { 365 return _fileService.call(request).then((response) {
366 if (_isErrorResponse(response)) { 366 if (_isErrorResponse(response)) {
367 throw _exceptionFromResponse(response, "Cannot open file '$_name'"); 367 throw _exceptionFromResponse(response, "Cannot open file '$_name'");
368 } 368 }
369 return new _RandomAccessFile(response, _name); 369 return new _RandomAccessFile(response, _name);
370 }); 370 });
371 } 371 }
372 372
373 Future<int> length() { 373 Future<int> length() {
374 _ensureFileService(); 374 _ensureFileService();
375 List request = new List.fixedLength(2); 375 List request = new List(2);
376 request[0] = _LENGTH_FROM_NAME_REQUEST; 376 request[0] = _LENGTH_FROM_NAME_REQUEST;
377 request[1] = _name; 377 request[1] = _name;
378 return _fileService.call(request).then((response) { 378 return _fileService.call(request).then((response) {
379 if (_isErrorResponse(response)) { 379 if (_isErrorResponse(response)) {
380 throw _exceptionFromResponse(response, 380 throw _exceptionFromResponse(response,
381 "Cannot retrieve length of " 381 "Cannot retrieve length of "
382 "file '$_name'"); 382 "file '$_name'");
383 } 383 }
384 return response; 384 return response;
385 }); 385 });
386 } 386 }
387 387
388 388
389 external static _lengthFromName(String name); 389 external static _lengthFromName(String name);
390 390
391 int lengthSync() { 391 int lengthSync() {
392 var result = _lengthFromName(_name); 392 var result = _lengthFromName(_name);
393 throwIfError(result, "Cannot retrieve length of file '$_name'"); 393 throwIfError(result, "Cannot retrieve length of file '$_name'");
394 return result; 394 return result;
395 } 395 }
396 396
397 Future<DateTime> lastModified() { 397 Future<DateTime> lastModified() {
398 _ensureFileService(); 398 _ensureFileService();
399 List request = new List.fixedLength(2); 399 List request = new List(2);
400 request[0] = _LAST_MODIFIED_REQUEST; 400 request[0] = _LAST_MODIFIED_REQUEST;
401 request[1] = _name; 401 request[1] = _name;
402 return _fileService.call(request).then((response) { 402 return _fileService.call(request).then((response) {
403 if (_isErrorResponse(response)) { 403 if (_isErrorResponse(response)) {
404 throw _exceptionFromResponse(response, 404 throw _exceptionFromResponse(response,
405 "Cannot retrieve modification time " 405 "Cannot retrieve modification time "
406 "for file '$_name'"); 406 "for file '$_name'");
407 } 407 }
408 return new DateTime.fromMillisecondsSinceEpoch(response); 408 return new DateTime.fromMillisecondsSinceEpoch(response);
409 }); 409 });
(...skipping 26 matching lines...) Expand all
436 static RandomAccessFile _openStdioSync(int fd) { 436 static RandomAccessFile _openStdioSync(int fd) {
437 var id = _openStdio(fd); 437 var id = _openStdio(fd);
438 if (id == 0) { 438 if (id == 0) {
439 throw new FileIOException("Cannot open stdio file for: $fd"); 439 throw new FileIOException("Cannot open stdio file for: $fd");
440 } 440 }
441 return new _RandomAccessFile(id, ""); 441 return new _RandomAccessFile(id, "");
442 } 442 }
443 443
444 Future<String> fullPath() { 444 Future<String> fullPath() {
445 _ensureFileService(); 445 _ensureFileService();
446 List request = new List.fixedLength(2); 446 List request = new List(2);
447 request[0] = _FULL_PATH_REQUEST; 447 request[0] = _FULL_PATH_REQUEST;
448 request[1] = _name; 448 request[1] = _name;
449 return _fileService.call(request).then((response) { 449 return _fileService.call(request).then((response) {
450 if (_isErrorResponse(response)) { 450 if (_isErrorResponse(response)) {
451 throw _exceptionFromResponse(response, 451 throw _exceptionFromResponse(response,
452 "Cannot retrieve full path" 452 "Cannot retrieve full path"
453 " for '$_name'"); 453 " for '$_name'");
454 } 454 }
455 return response; 455 return response;
456 }); 456 });
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 } 612 }
613 613
614 614
615 class _RandomAccessFile extends _FileBase implements RandomAccessFile { 615 class _RandomAccessFile extends _FileBase implements RandomAccessFile {
616 _RandomAccessFile(int this._id, String this._name); 616 _RandomAccessFile(int this._id, String this._name);
617 617
618 Future<RandomAccessFile> close() { 618 Future<RandomAccessFile> close() {
619 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 619 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
620 if (closed) return _completeWithClosedException(completer); 620 if (closed) return _completeWithClosedException(completer);
621 _ensureFileService(); 621 _ensureFileService();
622 List request = new List.fixedLength(2); 622 List request = new List(2);
623 request[0] = _CLOSE_REQUEST; 623 request[0] = _CLOSE_REQUEST;
624 request[1] = _id; 624 request[1] = _id;
625 // Set the id_ to 0 (NULL) to ensure the no more async requests 625 // Set the id_ to 0 (NULL) to ensure the no more async requests
626 // can be issued for this file. 626 // can be issued for this file.
627 _id = 0; 627 _id = 0;
628 return _fileService.call(request).then((result) { 628 return _fileService.call(request).then((result) {
629 if (result != -1) { 629 if (result != -1) {
630 _id = result; 630 _id = result;
631 return this; 631 return this;
632 } else { 632 } else {
(...skipping 10 matching lines...) Expand all
643 if (id == -1) { 643 if (id == -1) {
644 throw new FileIOException("Cannot close file '$_name'"); 644 throw new FileIOException("Cannot close file '$_name'");
645 } 645 }
646 _id = id; 646 _id = id;
647 } 647 }
648 648
649 Future<int> readByte() { 649 Future<int> readByte() {
650 _ensureFileService(); 650 _ensureFileService();
651 Completer<int> completer = new Completer<int>(); 651 Completer<int> completer = new Completer<int>();
652 if (closed) return _completeWithClosedException(completer); 652 if (closed) return _completeWithClosedException(completer);
653 List request = new List.fixedLength(2); 653 List request = new List(2);
654 request[0] = _READ_BYTE_REQUEST; 654 request[0] = _READ_BYTE_REQUEST;
655 request[1] = _id; 655 request[1] = _id;
656 return _fileService.call(request).then((response) { 656 return _fileService.call(request).then((response) {
657 if (_isErrorResponse(response)) { 657 if (_isErrorResponse(response)) {
658 throw _exceptionFromResponse(response, 658 throw _exceptionFromResponse(response,
659 "readByte failed for file '$_name'"); 659 "readByte failed for file '$_name'");
660 } 660 }
661 return response; 661 return response;
662 }); 662 });
663 } 663 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 // Complete asynchronously so the user has a chance to setup 717 // Complete asynchronously so the user has a chance to setup
718 // handlers without getting exceptions when registering the 718 // handlers without getting exceptions when registering the
719 // then handler. 719 // then handler.
720 Timer.run(() { 720 Timer.run(() {
721 completer.completeError(new FileIOException( 721 completer.completeError(new FileIOException(
722 "Invalid arguments to readList for file '$_name'")); 722 "Invalid arguments to readList for file '$_name'"));
723 }); 723 });
724 return completer.future; 724 return completer.future;
725 }; 725 };
726 if (closed) return _completeWithClosedException(completer); 726 if (closed) return _completeWithClosedException(completer);
727 List request = new List.fixedLength(3); 727 List request = new List(3);
728 request[0] = _READ_LIST_REQUEST; 728 request[0] = _READ_LIST_REQUEST;
729 request[1] = _id; 729 request[1] = _id;
730 request[2] = bytes; 730 request[2] = bytes;
731 return _fileService.call(request).then((response) { 731 return _fileService.call(request).then((response) {
732 if (_isErrorResponse(response)) { 732 if (_isErrorResponse(response)) {
733 throw _exceptionFromResponse(response, 733 throw _exceptionFromResponse(response,
734 "readList failed for file '$_name'"); 734 "readList failed for file '$_name'");
735 } 735 }
736 var read = response[1]; 736 var read = response[1];
737 var data = response[2]; 737 var data = response[2];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 // Complete asynchronously so the user has a chance to setup 773 // Complete asynchronously so the user has a chance to setup
774 // handlers without getting exceptions when registering the 774 // handlers without getting exceptions when registering the
775 // then handler. 775 // then handler.
776 Timer.run(() { 776 Timer.run(() {
777 completer.completeError(new FileIOException( 777 completer.completeError(new FileIOException(
778 "Invalid argument to writeByte for file '$_name'")); 778 "Invalid argument to writeByte for file '$_name'"));
779 }); 779 });
780 return completer.future; 780 return completer.future;
781 } 781 }
782 if (closed) return _completeWithClosedException(completer); 782 if (closed) return _completeWithClosedException(completer);
783 List request = new List.fixedLength(3); 783 List request = new List(3);
784 request[0] = _WRITE_BYTE_REQUEST; 784 request[0] = _WRITE_BYTE_REQUEST;
785 request[1] = _id; 785 request[1] = _id;
786 request[2] = value; 786 request[2] = value;
787 return _fileService.call(request).then((response) { 787 return _fileService.call(request).then((response) {
788 if (_isErrorResponse(response)) { 788 if (_isErrorResponse(response)) {
789 throw _exceptionFromResponse(response, 789 throw _exceptionFromResponse(response,
790 "writeByte failed for file '$_name'"); 790 "writeByte failed for file '$_name'");
791 } 791 }
792 return this; 792 return this;
793 }); 793 });
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 try { 828 try {
829 result = _ensureFastAndSerializableBuffer(buffer, offset, bytes); 829 result = _ensureFastAndSerializableBuffer(buffer, offset, bytes);
830 } catch (e) { 830 } catch (e) {
831 // Complete asynchronously so the user has a chance to setup 831 // Complete asynchronously so the user has a chance to setup
832 // handlers without getting exceptions when registering the 832 // handlers without getting exceptions when registering the
833 // then handler. 833 // then handler.
834 Timer.run(() => completer.completeError(e)); 834 Timer.run(() => completer.completeError(e));
835 return completer.future; 835 return completer.future;
836 } 836 }
837 837
838 List request = new List.fixedLength(5); 838 List request = new List(5);
839 request[0] = _WRITE_LIST_REQUEST; 839 request[0] = _WRITE_LIST_REQUEST;
840 request[1] = _id; 840 request[1] = _id;
841 request[2] = result.buffer; 841 request[2] = result.buffer;
842 request[3] = result.offset; 842 request[3] = result.offset;
843 request[4] = bytes; 843 request[4] = bytes;
844 return _fileService.call(request).then((response) { 844 return _fileService.call(request).then((response) {
845 if (_isErrorResponse(response)) { 845 if (_isErrorResponse(response)) {
846 throw _exceptionFromResponse(response, 846 throw _exceptionFromResponse(response,
847 "writeList failed for file '$_name'"); 847 "writeList failed for file '$_name'");
848 } 848 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 "Invalid encoding in writeStringSync: $encoding"); 890 "Invalid encoding in writeStringSync: $encoding");
891 } 891 }
892 var data = _encodeString(string, encoding); 892 var data = _encodeString(string, encoding);
893 return writeListSync(data, 0, data.length); 893 return writeListSync(data, 0, data.length);
894 } 894 }
895 895
896 Future<int> position() { 896 Future<int> position() {
897 _ensureFileService(); 897 _ensureFileService();
898 Completer<int> completer = new Completer<int>(); 898 Completer<int> completer = new Completer<int>();
899 if (closed) return _completeWithClosedException(completer); 899 if (closed) return _completeWithClosedException(completer);
900 List request = new List.fixedLength(2); 900 List request = new List(2);
901 request[0] = _POSITION_REQUEST; 901 request[0] = _POSITION_REQUEST;
902 request[1] = _id; 902 request[1] = _id;
903 return _fileService.call(request).then((response) { 903 return _fileService.call(request).then((response) {
904 if (_isErrorResponse(response)) { 904 if (_isErrorResponse(response)) {
905 throw _exceptionFromResponse(response, 905 throw _exceptionFromResponse(response,
906 "position failed for file '$_name'"); 906 "position failed for file '$_name'");
907 } 907 }
908 return response; 908 return response;
909 }); 909 });
910 } 910 }
911 911
912 external static _position(int id); 912 external static _position(int id);
913 913
914 int positionSync() { 914 int positionSync() {
915 _checkNotClosed(); 915 _checkNotClosed();
916 var result = _position(_id); 916 var result = _position(_id);
917 if (result is OSError) { 917 if (result is OSError) {
918 throw new FileIOException("position failed for file '$_name'", result); 918 throw new FileIOException("position failed for file '$_name'", result);
919 } 919 }
920 return result; 920 return result;
921 } 921 }
922 922
923 Future<RandomAccessFile> setPosition(int position) { 923 Future<RandomAccessFile> setPosition(int position) {
924 _ensureFileService(); 924 _ensureFileService();
925 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 925 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
926 if (closed) return _completeWithClosedException(completer); 926 if (closed) return _completeWithClosedException(completer);
927 List request = new List.fixedLength(3); 927 List request = new List(3);
928 request[0] = _SET_POSITION_REQUEST; 928 request[0] = _SET_POSITION_REQUEST;
929 request[1] = _id; 929 request[1] = _id;
930 request[2] = position; 930 request[2] = position;
931 return _fileService.call(request).then((response) { 931 return _fileService.call(request).then((response) {
932 if (_isErrorResponse(response)) { 932 if (_isErrorResponse(response)) {
933 throw _exceptionFromResponse(response, 933 throw _exceptionFromResponse(response,
934 "setPosition failed for file '$_name'"); 934 "setPosition failed for file '$_name'");
935 } 935 }
936 return this; 936 return this;
937 }); 937 });
938 } 938 }
939 939
940 external static _setPosition(int id, int position); 940 external static _setPosition(int id, int position);
941 941
942 void setPositionSync(int position) { 942 void setPositionSync(int position) {
943 _checkNotClosed(); 943 _checkNotClosed();
944 var result = _setPosition(_id, position); 944 var result = _setPosition(_id, position);
945 if (result is OSError) { 945 if (result is OSError) {
946 throw new FileIOException("setPosition failed for file '$_name'", result); 946 throw new FileIOException("setPosition failed for file '$_name'", result);
947 } 947 }
948 } 948 }
949 949
950 Future<RandomAccessFile> truncate(int length) { 950 Future<RandomAccessFile> truncate(int length) {
951 _ensureFileService(); 951 _ensureFileService();
952 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 952 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
953 if (closed) return _completeWithClosedException(completer); 953 if (closed) return _completeWithClosedException(completer);
954 List request = new List.fixedLength(3); 954 List request = new List(3);
955 request[0] = _TRUNCATE_REQUEST; 955 request[0] = _TRUNCATE_REQUEST;
956 request[1] = _id; 956 request[1] = _id;
957 request[2] = length; 957 request[2] = length;
958 return _fileService.call(request).then((response) { 958 return _fileService.call(request).then((response) {
959 if (_isErrorResponse(response)) { 959 if (_isErrorResponse(response)) {
960 throw _exceptionFromResponse(response, 960 throw _exceptionFromResponse(response,
961 "truncate failed for file '$_name'"); 961 "truncate failed for file '$_name'");
962 } 962 }
963 return this; 963 return this;
964 }); 964 });
965 } 965 }
966 966
967 external static _truncate(int id, int length); 967 external static _truncate(int id, int length);
968 968
969 void truncateSync(int length) { 969 void truncateSync(int length) {
970 _checkNotClosed(); 970 _checkNotClosed();
971 var result = _truncate(_id, length); 971 var result = _truncate(_id, length);
972 if (result is OSError) { 972 if (result is OSError) {
973 throw new FileIOException("truncate failed for file '$_name'", result); 973 throw new FileIOException("truncate failed for file '$_name'", result);
974 } 974 }
975 } 975 }
976 976
977 Future<int> length() { 977 Future<int> length() {
978 _ensureFileService(); 978 _ensureFileService();
979 Completer<int> completer = new Completer<int>(); 979 Completer<int> completer = new Completer<int>();
980 if (closed) return _completeWithClosedException(completer); 980 if (closed) return _completeWithClosedException(completer);
981 List request = new List.fixedLength(2); 981 List request = new List(2);
982 request[0] = _LENGTH_REQUEST; 982 request[0] = _LENGTH_REQUEST;
983 request[1] = _id; 983 request[1] = _id;
984 return _fileService.call(request).then((response) { 984 return _fileService.call(request).then((response) {
985 if (_isErrorResponse(response)) { 985 if (_isErrorResponse(response)) {
986 throw _exceptionFromResponse(response, 986 throw _exceptionFromResponse(response,
987 "length failed for file '$_name'"); 987 "length failed for file '$_name'");
988 } 988 }
989 return response; 989 return response;
990 }); 990 });
991 } 991 }
992 992
993 external static _length(int id); 993 external static _length(int id);
994 994
995 int lengthSync() { 995 int lengthSync() {
996 _checkNotClosed(); 996 _checkNotClosed();
997 var result = _length(_id); 997 var result = _length(_id);
998 if (result is OSError) { 998 if (result is OSError) {
999 throw new FileIOException("length failed for file '$_name'", result); 999 throw new FileIOException("length failed for file '$_name'", result);
1000 } 1000 }
1001 return result; 1001 return result;
1002 } 1002 }
1003 1003
1004 Future<RandomAccessFile> flush() { 1004 Future<RandomAccessFile> flush() {
1005 _ensureFileService(); 1005 _ensureFileService();
1006 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>(); 1006 Completer<RandomAccessFile> completer = new Completer<RandomAccessFile>();
1007 if (closed) return _completeWithClosedException(completer); 1007 if (closed) return _completeWithClosedException(completer);
1008 List request = new List.fixedLength(2); 1008 List request = new List(2);
1009 request[0] = _FLUSH_REQUEST; 1009 request[0] = _FLUSH_REQUEST;
1010 request[1] = _id; 1010 request[1] = _id;
1011 return _fileService.call(request).then((response) { 1011 return _fileService.call(request).then((response) {
1012 if (_isErrorResponse(response)) { 1012 if (_isErrorResponse(response)) {
1013 throw _exceptionFromResponse(response, 1013 throw _exceptionFromResponse(response,
1014 "flush failed for file '$_name'"); 1014 "flush failed for file '$_name'");
1015 } 1015 }
1016 return this; 1016 return this;
1017 }); 1017 });
1018 } 1018 }
(...skipping 30 matching lines...) Expand all
1049 new FileIOException("File closed '$_name'")); 1049 new FileIOException("File closed '$_name'"));
1050 }); 1050 });
1051 return completer.future; 1051 return completer.future;
1052 } 1052 }
1053 1053
1054 final String _name; 1054 final String _name;
1055 int _id; 1055 int _id;
1056 1056
1057 SendPort _fileService; 1057 SendPort _fileService;
1058 } 1058 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698