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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 return new Directory(_FileUtils.directory(_name)); | 424 return new Directory(_FileUtils.directory(_name)); |
425 } | 425 } |
426 | 426 |
427 void open(FileMode mode, void callback(RandomAccessFile file)) { | 427 void open(FileMode mode, void callback(RandomAccessFile file)) { |
428 _ensureFileService(); | 428 _ensureFileService(); |
429 _asyncUsed = true; | 429 _asyncUsed = true; |
430 if (mode != FileMode.READ && | 430 if (mode != FileMode.READ && |
431 mode != FileMode.WRITE && | 431 mode != FileMode.WRITE && |
432 mode != FileMode.APPEND) { | 432 mode != FileMode.APPEND) { |
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).receive((id, replyTo) { |
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) { |
454 throw new FileIOException( | 454 throw new FileIOException( |
455 "Mixed use of synchronous and asynchronous API"); | 455 "Mixed use of synchronous and asynchronous API"); |
456 } | 456 } |
457 if (mode != FileMode.READ && | 457 if (mode != FileMode.READ && |
458 mode != FileMode.WRITE && | 458 mode != FileMode.WRITE && |
459 mode != FileMode.APPEND) { | 459 mode != FileMode.APPEND) { |
460 throw new FileIOException("Unknown file mode. Use FileMode.READ, " + | 460 throw new FileIOException("Unknown file mode. Use FileMode.READ, " |
461 "FileMode.WRITE or FileMode.APPEND."); | 461 "FileMode.WRITE or FileMode.APPEND."); |
462 } | 462 } |
463 var id = _FileUtils.checkedOpen(_name, mode._mode); | 463 var id = _FileUtils.checkedOpen(_name, mode._mode); |
464 if (id == 0) { | 464 if (id == 0) { |
465 throw new FileIOException("Cannot open file: $_name"); | 465 throw new FileIOException("Cannot open file: $_name"); |
466 } | 466 } |
467 return new _RandomAccessFile(id, _name); | 467 return new _RandomAccessFile(id, _name); |
468 } | 468 } |
469 | 469 |
470 static RandomAccessFile _openStdioSync(int fd) { | 470 static RandomAccessFile _openStdioSync(int fd) { |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 bool _asyncUsed; | 1043 bool _asyncUsed; |
1044 int _pendingWrites = 0; | 1044 int _pendingWrites = 0; |
1045 | 1045 |
1046 SendPort _fileService; | 1046 SendPort _fileService; |
1047 | 1047 |
1048 Timer _noPendingWriteTimer; | 1048 Timer _noPendingWriteTimer; |
1049 | 1049 |
1050 Function _onNoPendingWrites; | 1050 Function _onNoPendingWrites; |
1051 Function _onError; | 1051 Function _onError; |
1052 } | 1052 } |
OLD | NEW |