| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 implements FileInputStream { | 5 class _FileInputStream implements FileInputStream { |
| 6 _FileInputStream(File file) { | 6 _FileInputStream(File file) { |
| 7 _file = new File(file.name); | 7 _file = new File(file.name); |
| 8 _file.openSync(); | 8 _file.openSync(); |
| 9 } | 9 } |
| 10 | 10 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 | 136 |
| 137 String _name; | 137 String _name; |
| 138 } | 138 } |
| 139 | 139 |
| 140 | 140 |
| 141 class _OpenOperation extends _FileOperation { | 141 class _OpenOperation extends _FileOperation { |
| 142 _OpenOperation(String this._name, bool this._writable); | 142 _OpenOperation(String this._name, bool this._writable); |
| 143 | 143 |
| 144 void execute(ReceivePort port) { | 144 void execute(ReceivePort port) { |
| 145 _replyPort.send(_File._open(_name, _writable), port.toSendPort()); | 145 _replyPort.send(_File._checkedOpen(_name, _writable), port.toSendPort()); |
| 146 } | 146 } |
| 147 | 147 |
| 148 String _name; | 148 String _name; |
| 149 bool _writable; | 149 bool _writable; |
| 150 } | 150 } |
| 151 | 151 |
| 152 | 152 |
| 153 class _CloseOperation extends _FileOperation { | 153 class _CloseOperation extends _FileOperation { |
| 154 _CloseOperation(int this._id); | 154 _CloseOperation(int this._id); |
| 155 | 155 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 List _buffer; | 251 List _buffer; |
| 252 int _offset; | 252 int _offset; |
| 253 int _bytes; | 253 int _bytes; |
| 254 } | 254 } |
| 255 | 255 |
| 256 | 256 |
| 257 class _WriteStringOperation extends _FileOperation { | 257 class _WriteStringOperation extends _FileOperation { |
| 258 _WriteStringOperation(int this._id, String this._string); | 258 _WriteStringOperation(int this._id, String this._string); |
| 259 | 259 |
| 260 void execute(ReceivePort port) { | 260 void execute(ReceivePort port) { |
| 261 _replyPort.send(_File._writeString(_id, _string), port.toSendPort()); | 261 _replyPort.send(_File._checkedWriteString(_id, _string), port.toSendPort()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 bool isWrite() => true; | 264 bool isWrite() => true; |
| 265 | 265 |
| 266 int _id; | 266 int _id; |
| 267 String _string; | 267 String _string; |
| 268 } | 268 } |
| 269 | 269 |
| 270 | 270 |
| 271 class _PositionOperation extends _FileOperation { | 271 class _PositionOperation extends _FileOperation { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 298 } | 298 } |
| 299 | 299 |
| 300 int _id; | 300 int _id; |
| 301 } | 301 } |
| 302 | 302 |
| 303 | 303 |
| 304 class _FullPathOperation extends _FileOperation { | 304 class _FullPathOperation extends _FileOperation { |
| 305 _FullPathOperation(String this._name); | 305 _FullPathOperation(String this._name); |
| 306 | 306 |
| 307 void execute(ReceivePort port) { | 307 void execute(ReceivePort port) { |
| 308 _replyPort.send(_File._fullPath(_name), port.toSendPort()); | 308 _replyPort.send(_File._checkedFullPath(_name), port.toSendPort()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 String _name; | 311 String _name; |
| 312 } | 312 } |
| 313 | 313 |
| 314 | 314 |
| 315 class _CreateOperation extends _FileOperation { | 315 class _CreateOperation extends _FileOperation { |
| 316 _CreateOperation(String this._name); | 316 _CreateOperation(String this._name); |
| 317 | 317 |
| 318 void execute(ReceivePort port) { | 318 void execute(ReceivePort port) { |
| 319 _replyPort.send(_File._create(_name), port.toSendPort()); | 319 _replyPort.send(_File._checkedCreate(_name), port.toSendPort()); |
| 320 } | 320 } |
| 321 | 321 |
| 322 String _name; | 322 String _name; |
| 323 } | 323 } |
| 324 | 324 |
| 325 | 325 |
| 326 class _ExitOperation extends _FileOperation { | 326 class _ExitOperation extends _FileOperation { |
| 327 void execute(ReceivePort port) { | 327 void execute(ReceivePort port) { |
| 328 port.close(); | 328 port.close(); |
| 329 } | 329 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 Queue<_FileOperation> _queue; | 390 Queue<_FileOperation> _queue; |
| 391 _FileOperationIsolate _isolate; | 391 _FileOperationIsolate _isolate; |
| 392 } | 392 } |
| 393 | 393 |
| 394 | 394 |
| 395 // Class for encapsulating the native implementation of files. | 395 // Class for encapsulating the native implementation of files. |
| 396 class _File implements File { | 396 class _File implements File { |
| 397 // Constructor for file. | 397 // Constructor for file. |
| 398 _File(String this._name) | 398 _File(String this._name) |
| 399 : _scheduler = new _FileOperationScheduler(), | 399 : _scheduler = new _FileOperationScheduler(), |
| 400 _asyncUsed = false; | 400 _asyncUsed = false, |
| 401 _id = 0; |
| 401 | 402 |
| 402 static bool _exists(String name) native "File_Exists"; | 403 static bool _exists(String name) native "File_Exists"; |
| 403 static int _open(String name, bool writable) native "File_Open"; | 404 static int _open(String name, bool writable) native "File_Open"; |
| 404 static int _close(int id) native "File_Close"; | 405 static int _close(int id) native "File_Close"; |
| 405 static int _readByte(int id) native "File_ReadByte"; | 406 static int _readByte(int id) native "File_ReadByte"; |
| 406 static int _readList(int id, List<int> buffer, int offset, int bytes) | 407 static int _readList(int id, List<int> buffer, int offset, int bytes) |
| 407 native "File_ReadList"; | 408 native "File_ReadList"; |
| 408 static int _writeByte(int id, int value) native "File_WriteByte"; | 409 static int _writeByte(int id, int value) native "File_WriteByte"; |
| 409 static int _writeList(int id, List<int> buffer, int offset, int bytes) | 410 static int _writeList(int id, List<int> buffer, int offset, int bytes) |
| 410 native "File_WriteList"; | 411 native "File_WriteList"; |
| 411 static int _writeString(int id, String string) native "File_WriteString"; | 412 static int _writeString(int id, String string) native "File_WriteString"; |
| 412 static int _position(int id) native "File_Position"; | 413 static int _position(int id) native "File_Position"; |
| 413 static int _length(int id) native "File_Length"; | 414 static int _length(int id) native "File_Length"; |
| 414 static int _flush(int id) native "File_Flush"; | 415 static int _flush(int id) native "File_Flush"; |
| 415 static bool _create(String name) native "File_Create"; | 416 static bool _create(String name) native "File_Create"; |
| 416 static String _fullPath(String name) native "File_FullPath"; | 417 static String _fullPath(String name) native "File_FullPath"; |
| 417 | 418 |
| 418 static int _checkReadWriteListArguments(int length, int offset, int bytes) { | 419 static int _checkReadWriteListArguments(int length, int offset, int bytes) { |
| 419 if (offset < 0) return offset; | 420 if (offset < 0) return offset; |
| 420 if (bytes < 0) return bytes; | 421 if (bytes < 0) return bytes; |
| 421 if ((offset + bytes) > length) return offset + bytes; | 422 if ((offset + bytes) > length) return offset + bytes; |
| 422 return 0; | 423 return 0; |
| 423 } | 424 } |
| 424 | 425 |
| 426 static int _checkedOpen(String name, bool writable) { |
| 427 if (name is !String || writable is !bool) return 0; |
| 428 return _open(name, writable); |
| 429 } |
| 430 |
| 431 static bool _checkedCreate(String name) { |
| 432 if (name is !String) return false; |
| 433 return _create(name); |
| 434 } |
| 435 |
| 436 static int _checkedWriteString(int id, String string) { |
| 437 if (string is !String) return -1; |
| 438 return _writeString(id, string); |
| 439 } |
| 440 |
| 441 static String _checkedFullPath(String name) { |
| 442 if (name is !String) return null; |
| 443 return _fullPath(name); |
| 444 } |
| 445 |
| 425 void exists() { | 446 void exists() { |
| 426 _asyncUsed = true; | 447 _asyncUsed = true; |
| 448 if (_name is !String) { |
| 449 if (_errorHandler != null) { |
| 450 _errorHandler('File name is not a string: $_name'); |
| 451 } |
| 452 return; |
| 453 } |
| 427 var handler = | 454 var handler = |
| 428 (_existsHandler != null) ? _existsHandler : (result) => null; | 455 (_existsHandler != null) ? _existsHandler : (result) => null; |
| 429 var operation = new _ExistsOperation(_name); | 456 var operation = new _ExistsOperation(_name); |
| 430 _scheduler.enqueue(operation, (result, ignored) { _existsHandler(result); })
; | 457 _scheduler.enqueue(operation, (result, ignored) { _existsHandler(result); })
; |
| 431 } | 458 } |
| 432 | 459 |
| 433 bool existsSync() { | 460 bool existsSync() { |
| 434 if (_asyncUsed) { | 461 if (_asyncUsed) { |
| 435 throw new FileIOException( | 462 throw new FileIOException( |
| 436 "Mixed use of synchronous and asynchronous API"); | 463 "Mixed use of synchronous and asynchronous API"); |
| 437 } | 464 } |
| 465 if (_name is !String) { |
| 466 throw new FileIOException('File name is not a string: $_name'); |
| 467 } |
| 438 return _exists(_name); | 468 return _exists(_name); |
| 439 } | 469 } |
| 440 | 470 |
| 441 void create() { | 471 void create() { |
| 442 _asyncUsed = true; | 472 _asyncUsed = true; |
| 443 var handler = (_createHandler != null) ? _createHandler : () => null; | 473 var handler = (_createHandler != null) ? _createHandler : () => null; |
| 444 var handleCreateResult = (created, ignored) { | 474 var handleCreateResult = (created, ignored) { |
| 445 if (created) { | 475 if (created) { |
| 446 handler(); | 476 handler(); |
| 447 } else if (_errorHandler != null) { | 477 } else if (_errorHandler != null) { |
| 448 _errorHandler("Cannot create file: $_name"); | 478 _errorHandler("Cannot create file: $_name"); |
| 449 } | 479 } |
| 450 }; | 480 }; |
| 451 var operation = new _CreateOperation(_name); | 481 var operation = new _CreateOperation(_name); |
| 452 _scheduler.enqueue(operation, handleCreateResult); | 482 _scheduler.enqueue(operation, handleCreateResult); |
| 453 } | 483 } |
| 454 | 484 |
| 455 void createSync() { | 485 void createSync() { |
| 456 if (_asyncUsed) { | 486 if (_asyncUsed) { |
| 457 throw new FileIOException( | 487 throw new FileIOException( |
| 458 "Mixed use of synchronous and asynchronous API"); | 488 "Mixed use of synchronous and asynchronous API"); |
| 459 } | 489 } |
| 460 bool created = _create(_name); | 490 bool created = _checkedCreate(_name); |
| 461 if (!created) { | 491 if (!created) { |
| 462 throw new FileIOException("Cannot create file: $_name"); | 492 throw new FileIOException("Cannot create file: $_name"); |
| 463 } | 493 } |
| 464 } | 494 } |
| 465 | 495 |
| 466 void open([bool writable = false]) { | 496 void open([bool writable = false]) { |
| 467 _asyncUsed = true; | 497 _asyncUsed = true; |
| 468 var handler = (_openHandler != null) ? _openHandler : () => null; | 498 var handler = (_openHandler != null) ? _openHandler : () => null; |
| 469 var handleOpenResult = (result, ignored) { | 499 var handleOpenResult = (result, ignored) { |
| 470 if (result != 0) { | 500 if (result != 0) { |
| 471 _id = result; | 501 _id = result; |
| 472 handler(); | 502 handler(); |
| 473 } else if (_errorHandler != null) { | 503 } else if (_errorHandler != null) { |
| 474 _errorHandler("Cannot open file: $_name"); | 504 _errorHandler("Cannot open file: $_name"); |
| 475 } | 505 } |
| 476 }; | 506 }; |
| 477 var operation = new _OpenOperation(_name, writable); | 507 var operation = new _OpenOperation(_name, writable); |
| 478 _scheduler.enqueue(operation, handleOpenResult); | 508 _scheduler.enqueue(operation, handleOpenResult); |
| 479 } | 509 } |
| 480 | 510 |
| 481 void openSync([bool writable = false]) { | 511 void openSync([bool writable = false]) { |
| 482 if (_asyncUsed) { | 512 if (_asyncUsed) { |
| 483 throw new FileIOException( | 513 throw new FileIOException( |
| 484 "Mixed use of synchronous and asynchronous API"); | 514 "Mixed use of synchronous and asynchronous API"); |
| 485 } | 515 } |
| 486 _id = _open(_name, writable); | 516 _id = _checkedOpen(_name, writable); |
| 487 if (_id == 0) { | 517 if (_id == 0) { |
| 488 throw new FileIOException("Cannot open file: $_name"); | 518 throw new FileIOException("Cannot open file: $_name"); |
| 489 } | 519 } |
| 490 } | 520 } |
| 491 | 521 |
| 492 void close() { | 522 void close() { |
| 493 _asyncUsed = true; | 523 _asyncUsed = true; |
| 494 var handler = (_closeHandler != null) ? _closeHandler : () => null; | 524 var handler = (_closeHandler != null) ? _closeHandler : () => null; |
| 495 var handleOpenResult = (result, ignored) { | 525 var handleOpenResult = (result, ignored) { |
| 496 if (result != -1) { | 526 if (result != -1) { |
| 497 _id = result; | 527 _id = result; |
| 498 handler(); | 528 handler(); |
| 499 } else if (_errorHandler != null) { | 529 } else if (_errorHandler != null) { |
| 500 _errorHandler("Cannot open file: $_name"); | 530 _errorHandler("Cannot close file: $_name"); |
| 501 } | 531 } |
| 502 }; | 532 }; |
| 503 var operation = new _CloseOperation(_id); | 533 var operation = new _CloseOperation(_id); |
| 504 _scheduler.enqueue(operation, handleOpenResult); | 534 _scheduler.enqueue(operation, handleOpenResult); |
| 505 } | 535 } |
| 506 | 536 |
| 507 void closeSync() { | 537 void closeSync() { |
| 508 if (_asyncUsed) { | 538 if (_asyncUsed) { |
| 509 throw new FileIOException( | 539 throw new FileIOException( |
| 510 "Mixed use of synchronous and asynchronous API"); | 540 "Mixed use of synchronous and asynchronous API"); |
| 511 } | 541 } |
| 512 _id = _close(_id); | 542 var id = _close(_id); |
| 513 if (_id == -1) { | 543 if (id == -1) { |
| 514 throw new FileIOException("Cannot close file: $_name"); | 544 throw new FileIOException("Cannot close file: $_name"); |
| 515 } | 545 } |
| 546 _id = id; |
| 516 } | 547 } |
| 517 | 548 |
| 518 void readByte() { | 549 void readByte() { |
| 519 _asyncUsed = true; | 550 _asyncUsed = true; |
| 520 var handler = | 551 var handler = |
| 521 (_readByteHandler != null) ? _readByteHandler : (byte) => null; | 552 (_readByteHandler != null) ? _readByteHandler : (byte) => null; |
| 522 var handleReadByteResult = (result, ignored) { | 553 var handleReadByteResult = (result, ignored) { |
| 523 if (result != -1) { | 554 if (result != -1) { |
| 524 handler(result); | 555 handler(result); |
| 525 } else if (_errorHandler != null) { | 556 } else if (_errorHandler != null) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 537 } | 568 } |
| 538 int result = _readByte(_id); | 569 int result = _readByte(_id); |
| 539 if (result == -1) { | 570 if (result == -1) { |
| 540 throw new FileIOException("readByte failed"); | 571 throw new FileIOException("readByte failed"); |
| 541 } | 572 } |
| 542 return result; | 573 return result; |
| 543 } | 574 } |
| 544 | 575 |
| 545 void readList(List<int> buffer, int offset, int bytes) { | 576 void readList(List<int> buffer, int offset, int bytes) { |
| 546 _asyncUsed = true; | 577 _asyncUsed = true; |
| 578 if (buffer is !List || offset is !int || bytes is !int) { |
| 579 if (_errorHandler != null) { |
| 580 _errorHandler("Invalid arguments to readList"); |
| 581 } |
| 582 return; |
| 583 }; |
| 547 var handler = | 584 var handler = |
| 548 (_readListHandler != null) ? _readListHandler : (result) => null; | 585 (_readListHandler != null) ? _readListHandler : (result) => null; |
| 549 var handleReadListResult = (result, ignored) { | 586 var handleReadListResult = (result, ignored) { |
| 550 if (result is _ReadListResult && result.read != -1) { | 587 if (result is _ReadListResult && result.read != -1) { |
| 551 var read = result.read; | 588 var read = result.read; |
| 552 buffer.setRange(offset, read, result.buffer); | 589 buffer.setRange(offset, read, result.buffer); |
| 553 handler(read); | 590 handler(read); |
| 554 return; | 591 return; |
| 555 } | 592 } |
| 556 if (_errorHandler != null) { | 593 if (_errorHandler != null) { |
| 557 _errorHandler(result is String ? result : "readList failed"); | 594 _errorHandler(result is String ? result : "readList failed"); |
| 558 } | 595 } |
| 559 }; | 596 }; |
| 560 var operation = new _ReadListOperation(_id, buffer.length, offset, bytes); | 597 var operation = new _ReadListOperation(_id, buffer.length, offset, bytes); |
| 561 _scheduler.enqueue(operation, handleReadListResult); | 598 _scheduler.enqueue(operation, handleReadListResult); |
| 562 } | 599 } |
| 563 | 600 |
| 564 int readListSync(List<int> buffer, int offset, int bytes) { | 601 int readListSync(List<int> buffer, int offset, int bytes) { |
| 565 if (_asyncUsed) { | 602 if (_asyncUsed) { |
| 566 throw new FileIOException( | 603 throw new FileIOException( |
| 567 "Mixed use of synchronous and asynchronous API"); | 604 "Mixed use of synchronous and asynchronous API"); |
| 568 } | 605 } |
| 606 if (buffer is !List || offset is !int || bytes is !int) { |
| 607 throw new FileIOException("Invalid arguments to readList"); |
| 608 } |
| 569 if (bytes == 0) return 0; | 609 if (bytes == 0) return 0; |
| 570 int index = _checkReadWriteListArguments(buffer.length, offset, bytes); | 610 int index = _checkReadWriteListArguments(buffer.length, offset, bytes); |
| 571 if (index != 0) { | 611 if (index != 0) { |
| 572 throw new IndexOutOfRangeException(index); | 612 throw new IndexOutOfRangeException(index); |
| 573 } | 613 } |
| 574 int result = _readList(_id, buffer, offset, bytes); | 614 int result = _readList(_id, buffer, offset, bytes); |
| 575 if (result == -1) { | 615 if (result == -1) { |
| 576 throw new FileIOException("readList failed"); | 616 throw new FileIOException("readList failed"); |
| 577 } | 617 } |
| 578 return result; | 618 return result; |
| 579 } | 619 } |
| 580 | 620 |
| 581 void _checkPendingWrites() { | 621 void _checkPendingWrites() { |
| 582 if (_scheduler.noPendingWrite() && _noPendingWriteHandler != null) { | 622 if (_scheduler.noPendingWrite() && _noPendingWriteHandler != null) { |
| 583 _noPendingWriteHandler(); | 623 _noPendingWriteHandler(); |
| 584 } | 624 } |
| 585 } | 625 } |
| 586 | 626 |
| 587 void writeByte(int value) { | 627 void writeByte(int value) { |
| 588 _asyncUsed = true; | 628 _asyncUsed = true; |
| 629 if (value is !int) { |
| 630 if (_errorHandler != null) { |
| 631 _errorHandler("Invalid argument to writeByte"); |
| 632 } |
| 633 return; |
| 634 } |
| 589 var handleReadByteResult = (result, ignored) { | 635 var handleReadByteResult = (result, ignored) { |
| 590 if (result == -1 &&_errorHandler != null) { | 636 if (result == -1 &&_errorHandler != null) { |
| 591 _errorHandler("writeByte failed"); | 637 _errorHandler("writeByte failed"); |
| 592 return; | 638 return; |
| 593 } | 639 } |
| 594 _checkPendingWrites(); | 640 _checkPendingWrites(); |
| 595 }; | 641 }; |
| 596 var operation = new _WriteByteOperation(_id, value); | 642 var operation = new _WriteByteOperation(_id, value); |
| 597 _scheduler.enqueue(operation, handleReadByteResult); | 643 _scheduler.enqueue(operation, handleReadByteResult); |
| 598 } | 644 } |
| 599 | 645 |
| 600 int writeByteSync(int value) { | 646 int writeByteSync(int value) { |
| 601 if (_asyncUsed) { | 647 if (_asyncUsed) { |
| 602 throw new FileIOException( | 648 throw new FileIOException( |
| 603 "Mixed use of synchronous and asynchronous API"); | 649 "Mixed use of synchronous and asynchronous API"); |
| 604 } | 650 } |
| 651 if (value is !int) { |
| 652 throw new FileIOException("Invalid argument to writeByte"); |
| 653 } |
| 605 int result = _writeByte(_id, value); | 654 int result = _writeByte(_id, value); |
| 606 if (result == -1) { | 655 if (result == -1) { |
| 607 throw new FileIOException("writeByte failed"); | 656 throw new FileIOException("writeByte failed"); |
| 608 } | 657 } |
| 609 return result; | 658 return result; |
| 610 } | 659 } |
| 611 | 660 |
| 612 void writeList(List<int> buffer, int offset, int bytes) { | 661 void writeList(List<int> buffer, int offset, int bytes) { |
| 613 _asyncUsed = true; | 662 _asyncUsed = true; |
| 663 if (buffer is !List || offset is !int || bytes is !int) { |
| 664 if (_errorHandler != null) { |
| 665 _errorHandler("Invalid arguments to writeList"); |
| 666 } |
| 667 return; |
| 668 } |
| 614 var handleWriteListResult = (result, ignored) { | 669 var handleWriteListResult = (result, ignored) { |
| 615 if (result is !String && result != -1) { | 670 if (result is !String && result != -1) { |
| 616 if (result < bytes) { | 671 if (result < bytes) { |
| 617 writeList(buffer, offset + result, bytes - result); | 672 writeList(buffer, offset + result, bytes - result); |
| 618 } else { | 673 } else { |
| 619 _checkPendingWrites(); | 674 _checkPendingWrites(); |
| 620 } | 675 } |
| 621 return; | 676 return; |
| 622 } | 677 } |
| 623 if (_errorHandler != null) { | 678 if (_errorHandler != null) { |
| 624 _errorHandler(result is String ? result : "writeList failed"); | 679 _errorHandler(result is String ? result : "writeList failed"); |
| 625 } | 680 } |
| 626 }; | 681 }; |
| 627 var operation = new _WriteListOperation(_id, buffer, offset, bytes); | 682 var operation = new _WriteListOperation(_id, buffer, offset, bytes); |
| 628 _scheduler.enqueue(operation, handleWriteListResult); | 683 _scheduler.enqueue(operation, handleWriteListResult); |
| 629 } | 684 } |
| 630 | 685 |
| 631 int writeListSync(List<int> buffer, int offset, int bytes) { | 686 int writeListSync(List<int> buffer, int offset, int bytes) { |
| 632 if (_asyncUsed) { | 687 if (_asyncUsed) { |
| 633 throw new FileIOException( | 688 throw new FileIOException( |
| 634 "Mixed use of synchronous and asynchronous API"); | 689 "Mixed use of synchronous and asynchronous API"); |
| 635 } | 690 } |
| 691 if (buffer is !List || offset is !int || bytes is !int) { |
| 692 throw new FileIOException("Invalid arguments to writeList"); |
| 693 } |
| 636 if (bytes == 0) return 0; | 694 if (bytes == 0) return 0; |
| 637 int index = _checkReadWriteListArguments(buffer.length, offset, bytes); | 695 int index = _checkReadWriteListArguments(buffer.length, offset, bytes); |
| 638 if (index != 0) { | 696 if (index != 0) { |
| 639 throw new IndexOutOfRangeException(index); | 697 throw new IndexOutOfRangeException(index); |
| 640 } | 698 } |
| 641 int result = _writeList(_id, buffer, offset, bytes); | 699 int result = _writeList(_id, buffer, offset, bytes); |
| 642 if (result == -1) { | 700 if (result == -1) { |
| 643 throw new FileIOException("writeList failed"); | 701 throw new FileIOException("writeList failed"); |
| 644 } | 702 } |
| 645 return result; | 703 return result; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 660 }; | 718 }; |
| 661 var operation = new _WriteStringOperation(_id, string); | 719 var operation = new _WriteStringOperation(_id, string); |
| 662 _scheduler.enqueue(operation, handleWriteStringResult); | 720 _scheduler.enqueue(operation, handleWriteStringResult); |
| 663 } | 721 } |
| 664 | 722 |
| 665 int writeStringSync(String string) { | 723 int writeStringSync(String string) { |
| 666 if (_asyncUsed) { | 724 if (_asyncUsed) { |
| 667 throw new FileIOException( | 725 throw new FileIOException( |
| 668 "Mixed use of synchronous and asynchronous API"); | 726 "Mixed use of synchronous and asynchronous API"); |
| 669 } | 727 } |
| 670 int result = _writeString(_id, string); | 728 int result = _checkedWriteString(_id, string); |
| 671 if (result == -1) { | 729 if (result == -1) { |
| 672 throw new FileIOException("Error: writeString failed"); | 730 throw new FileIOException("writeString failed"); |
| 673 } | 731 } |
| 674 return result; | 732 return result; |
| 675 } | 733 } |
| 676 | 734 |
| 677 void position() { | 735 void position() { |
| 678 _asyncUsed = true; | 736 _asyncUsed = true; |
| 679 var handler = (_positionHandler != null) ? _positionHandler : (pos) => null; | 737 var handler = (_positionHandler != null) ? _positionHandler : (pos) => null; |
| 680 var handlePositionResult = (result, ignored) { | 738 var handlePositionResult = (result, ignored) { |
| 681 if (result == -1 && _errorHandler != null) { | 739 if (result == -1 && _errorHandler != null) { |
| 682 _errorHandler("position failed"); | 740 _errorHandler("position failed"); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 } | 810 } |
| 753 | 811 |
| 754 void fullPath() { | 812 void fullPath() { |
| 755 _asyncUsed = true; | 813 _asyncUsed = true; |
| 756 var handler = _fullPathHandler; | 814 var handler = _fullPathHandler; |
| 757 if (handler == null) handler = (path) => null; | 815 if (handler == null) handler = (path) => null; |
| 758 var handleFullPathResult = (result, ignored) { | 816 var handleFullPathResult = (result, ignored) { |
| 759 if (result != null) { | 817 if (result != null) { |
| 760 handler(result); | 818 handler(result); |
| 761 } else if (_errorHandler != null) { | 819 } else if (_errorHandler != null) { |
| 762 _errorHandler("canonicalPath failed"); | 820 _errorHandler("fullPath failed"); |
| 763 } | 821 } |
| 764 }; | 822 }; |
| 765 var operation = new _FullPathOperation(_name); | 823 var operation = new _FullPathOperation(_name); |
| 766 _scheduler.enqueue(operation, handleFullPathResult); | 824 _scheduler.enqueue(operation, handleFullPathResult); |
| 767 } | 825 } |
| 768 | 826 |
| 769 String fullPathSync() { | 827 String fullPathSync() { |
| 770 if (_asyncUsed) { | 828 if (_asyncUsed) { |
| 771 throw new FileIOException( | 829 throw new FileIOException( |
| 772 "Mixed use of synchronous and asynchronous API"); | 830 "Mixed use of synchronous and asynchronous API"); |
| 773 } | 831 } |
| 774 String result = _fullPath(_name); | 832 String result = _checkedFullPath(_name); |
| 775 if (result == null) { | 833 if (result == null) { |
| 776 throw new FileIOException("fullPath failed"); | 834 throw new FileIOException("fullPath failed"); |
| 777 } | 835 } |
| 778 return result; | 836 return result; |
| 779 } | 837 } |
| 780 | 838 |
| 781 InputStream openInputStream() { | 839 InputStream openInputStream() { |
| 782 return new _FileInputStream(this); | 840 return new _FileInputStream(this); |
| 783 } | 841 } |
| 784 | 842 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 var _closeHandler; | 908 var _closeHandler; |
| 851 var _readByteHandler; | 909 var _readByteHandler; |
| 852 var _readListHandler; | 910 var _readListHandler; |
| 853 var _noPendingWriteHandler; | 911 var _noPendingWriteHandler; |
| 854 var _positionHandler; | 912 var _positionHandler; |
| 855 var _lengthHandler; | 913 var _lengthHandler; |
| 856 var _flushHandler; | 914 var _flushHandler; |
| 857 var _fullPathHandler; | 915 var _fullPathHandler; |
| 858 var _errorHandler; | 916 var _errorHandler; |
| 859 } | 917 } |
| OLD | NEW |