Chromium Code Reviews| 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 = (e) { | 10 _file.onError = (e) { |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 request[2] = mode._mode; // Direct int value for serialization. | 482 request[2] = mode._mode; // Direct int value for serialization. |
| 483 _fileService.call(request).then((response) { | 483 _fileService.call(request).then((response) { |
| 484 if (_isErrorResponse(response)) { | 484 if (_isErrorResponse(response)) { |
| 485 _reportError(response, "Cannot open file"); | 485 _reportError(response, "Cannot open file"); |
| 486 } else { | 486 } else { |
| 487 callback(new _RandomAccessFile(response, _name)); | 487 callback(new _RandomAccessFile(response, _name)); |
| 488 } | 488 } |
| 489 }); | 489 }); |
| 490 } | 490 } |
| 491 | 491 |
| 492 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { | 492 RandomAccessFile openSync(FileMode mode) { |
|
Bill Hesse
2012/03/14 15:32:42
Removed.
The openSync() method is called with no
| |
| 493 if (_asyncUsed) { | 493 if (_asyncUsed) { |
| 494 throw new FileIOException( | 494 throw new FileIOException( |
| 495 "Mixed use of synchronous and asynchronous API"); | 495 "Mixed use of synchronous and asynchronous API"); |
| 496 } | 496 } |
| 497 if (mode != FileMode.READ && | 497 if (mode != FileMode.READ && |
| 498 mode != FileMode.WRITE && | 498 mode != FileMode.WRITE && |
| 499 mode != FileMode.APPEND) { | 499 mode != FileMode.APPEND) { |
| 500 throw new FileIOException("Unknown file mode. Use FileMode.READ, " + | 500 throw new FileIOException("Unknown file mode. Use FileMode.READ, " + |
| 501 "FileMode.WRITE or FileMode.APPEND."); | 501 "FileMode.WRITE or FileMode.APPEND."); |
| 502 } | 502 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 _onError("Failed to read file"); | 565 _onError("Failed to read file"); |
| 566 } | 566 } |
| 567 }; | 567 }; |
| 568 } | 568 } |
| 569 | 569 |
| 570 List<int> readAsBytesSync() { | 570 List<int> readAsBytesSync() { |
| 571 if (_asyncUsed) { | 571 if (_asyncUsed) { |
| 572 throw new FileIOException( | 572 throw new FileIOException( |
| 573 "Mixed use of synchronous and asynchronous API"); | 573 "Mixed use of synchronous and asynchronous API"); |
| 574 } | 574 } |
| 575 var opened = openSync(); | 575 var opened = openSync(FileMode.READ); |
| 576 var length = opened.lengthSync(); | 576 var length = opened.lengthSync(); |
| 577 var result = new ByteArray(length); | 577 var result = new ByteArray(length); |
| 578 var read = opened.readListSync(result, 0, length); | 578 var read = opened.readListSync(result, 0, length); |
| 579 if (read != length) { | 579 if (read != length) { |
| 580 throw new FileIOException("Failed to read file"); | 580 throw new FileIOException("Failed to read file"); |
| 581 } | 581 } |
| 582 opened.closeSync(); | 582 opened.closeSync(); |
| 583 return result; | 583 return result; |
| 584 } | 584 } |
| 585 | 585 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 "Mixed use of synchronous and asynchronous API"); | 648 "Mixed use of synchronous and asynchronous API"); |
| 649 } | 649 } |
| 650 var decoder = _StringDecoders.decoder(encoding); | 650 var decoder = _StringDecoders.decoder(encoding); |
| 651 List<int> bytes = readAsBytesSync(); | 651 List<int> bytes = readAsBytesSync(); |
| 652 decoder.write(bytes); | 652 decoder.write(bytes); |
| 653 return _getDecodedLines(decoder); | 653 return _getDecodedLines(decoder); |
| 654 } | 654 } |
| 655 | 655 |
| 656 String get name() => _name; | 656 String get name() => _name; |
| 657 | 657 |
| 658 void set onError(void handler(String error)) { | 658 void set onError(void handler(Exception error)) { |
| 659 _onError = handler; | 659 _onError = handler; |
| 660 } | 660 } |
| 661 | 661 |
| 662 void _ensureFileService() { | 662 void _ensureFileService() { |
| 663 if (_fileService == null) { | 663 if (_fileService == null) { |
| 664 _fileService = _FileUtils.newServicePort(); | 664 _fileService = _FileUtils.newServicePort(); |
| 665 } | 665 } |
| 666 } | 666 } |
| 667 | 667 |
| 668 bool _isErrorResponse(response) { | 668 bool _isErrorResponse(response) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1098 bool _asyncUsed; | 1098 bool _asyncUsed; |
| 1099 int _pendingWrites = 0; | 1099 int _pendingWrites = 0; |
| 1100 | 1100 |
| 1101 SendPort _fileService; | 1101 SendPort _fileService; |
| 1102 | 1102 |
| 1103 Timer _noPendingWriteTimer; | 1103 Timer _noPendingWriteTimer; |
| 1104 | 1104 |
| 1105 Function _onNoPendingWrites; | 1105 Function _onNoPendingWrites; |
| 1106 Function _onError; | 1106 Function _onError; |
| 1107 } | 1107 } |
| OLD | NEW |