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

Side by Side Diff: runtime/bin/file_impl.dart

Issue 9487005: Move back to having File.open{Input,Output}Stream return the stream directly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
« no previous file with comments | « runtime/bin/file.dart ('k') | samples/actors/samples/sssp/sssp-util.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 _file = new File(name); 7 _file = new File(name);
8 _data = []; 8 _data = [];
9 _position = 0; 9 _position = 0;
10 _file.errorHandler = (String s) { 10 _file.errorHandler = (String s) {
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 throw new FileIOException( 507 throw new FileIOException(
508 "Mixed use of synchronous and asynchronous API"); 508 "Mixed use of synchronous and asynchronous API");
509 } 509 }
510 String result = _FileUtils.checkedFullPath(_name); 510 String result = _FileUtils.checkedFullPath(_name);
511 if (result == null) { 511 if (result == null) {
512 throw new FileIOException("fullPath failed"); 512 throw new FileIOException("fullPath failed");
513 } 513 }
514 return result; 514 return result;
515 } 515 }
516 516
517 void openInputStream() { 517 InputStream openInputStream() {
518 _asyncUsed = true;
519 // Create a new file object to handle the opening of the file for
520 // creating an input stream. Currently the file input stream uses
521 // synchronous calls on the opened file so we need to open it
522 // synchronously.
523 new Timer((t) {
524 if (_inputStreamHandler != null) {
525 _inputStreamHandler(new _FileInputStream(_name));
526 }
527 }, 0);
528 }
529
530 InputStream openInputStreamSync() {
531 return new _FileInputStream(_name); 518 return new _FileInputStream(_name);
532 } 519 }
533 520
534 void openOutputStream([FileMode mode = FileMode.WRITE]) { 521 OutputStream openOutputStream([FileMode mode = FileMode.WRITE]) {
535 _asyncUsed = true;
536 if (mode != FileMode.WRITE && 522 if (mode != FileMode.WRITE &&
537 mode != FileMode.APPEND) { 523 mode != FileMode.APPEND) {
538 throw new FileIOException( 524 throw new FileIOException(
539 "Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND");
540 }
541 OutputStream stream = new _FileOutputStream(_name, mode);
542 new Timer(
543 (Timer ignore) {
544 if (_outputStreamHandler != null) _outputStreamHandler(stream);
545 }, 0);
546 }
547
548 OutputStream openOutputStreamSync([FileMode mode = FileMode.WRITE]) {
549 if (_asyncUsed) {
550 throw new FileIOException(
551 "Mixed use of synchronous and asynchronous API");
552 }
553 if (mode != FileMode.WRITE &&
554 mode != FileMode.APPEND) {
555 throw new FileIOException(
556 "Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND"); 525 "Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND");
557 } 526 }
558 return new _FileOutputStream(_name, mode); 527 return new _FileOutputStream(_name, mode);
559 } 528 }
560 529
561 void readAsBytes() { 530 void readAsBytes() {
562 _asyncUsed = true; 531 _asyncUsed = true;
563 var chunks = new _BufferList(); 532 var chunks = new _BufferList();
564 var stream = openInputStreamSync(); 533 var stream = openInputStream();
565 stream.closeHandler = () { 534 stream.closeHandler = () {
566 if (_readAsBytesHandler != null) { 535 if (_readAsBytesHandler != null) {
567 _readAsBytesHandler(chunks.readBytes(chunks.length)); 536 _readAsBytesHandler(chunks.readBytes(chunks.length));
568 } 537 }
569 }; 538 };
570 stream.dataHandler = () { 539 stream.dataHandler = () {
571 var chunk = stream.read(); 540 var chunk = stream.read();
572 chunks.add(chunk); 541 chunks.add(chunk);
573 }; 542 };
574 stream.errorHandler = () { 543 stream.errorHandler = () {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 } 665 }
697 666
698 void set directoryHandler(void handler(Directory directory)) { 667 void set directoryHandler(void handler(Directory directory)) {
699 _directoryHandler = handler; 668 _directoryHandler = handler;
700 } 669 }
701 670
702 void set openHandler(void handler(RandomAccessFile file)) { 671 void set openHandler(void handler(RandomAccessFile file)) {
703 _openHandler = handler; 672 _openHandler = handler;
704 } 673 }
705 674
706 void set inputStreamHandler(void handler(InputStream stream)) {
707 _inputStreamHandler = handler;
708 }
709
710 void set outputStreamHandler(void handler(OutputStream stream)) {
711 _outputStreamHandler = handler;
712 }
713
714 void set readAsBytesHandler(void handler(List<int> bytes)) { 675 void set readAsBytesHandler(void handler(List<int> bytes)) {
715 _readAsBytesHandler = handler; 676 _readAsBytesHandler = handler;
716 } 677 }
717 678
718 void set readAsTextHandler(void handler(String text)) { 679 void set readAsTextHandler(void handler(String text)) {
719 _readAsTextHandler = handler; 680 _readAsTextHandler = handler;
720 } 681 }
721 682
722 void set readAsLinesHandler(void handler(List<String> lines)) { 683 void set readAsLinesHandler(void handler(List<String> lines)) {
723 _readAsLinesHandler = handler; 684 _readAsLinesHandler = handler;
(...skipping 16 matching lines...) Expand all
740 String _name; 701 String _name;
741 bool _asyncUsed; 702 bool _asyncUsed;
742 703
743 SendPort _fileService; 704 SendPort _fileService;
744 705
745 Function _existsHandler; 706 Function _existsHandler;
746 Function _createHandler; 707 Function _createHandler;
747 Function _deleteHandler; 708 Function _deleteHandler;
748 Function _directoryHandler; 709 Function _directoryHandler;
749 Function _openHandler; 710 Function _openHandler;
750 Function _inputStreamHandler;
751 Function _outputStreamHandler;
752 Function _readAsBytesHandler; 711 Function _readAsBytesHandler;
753 Function _readAsTextHandler; 712 Function _readAsTextHandler;
754 Function _readAsLinesHandler; 713 Function _readAsLinesHandler;
755 Function _fullPathHandler; 714 Function _fullPathHandler;
756 Function _errorHandler; 715 Function _errorHandler;
757 } 716 }
758 717
759 718
760 class _RandomAccessFile implements RandomAccessFile { 719 class _RandomAccessFile implements RandomAccessFile {
761 _RandomAccessFile(int this._id, String this._name) : _asyncUsed = false; 720 _RandomAccessFile(int this._id, String this._name) : _asyncUsed = false;
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 Function _readByteHandler; 1158 Function _readByteHandler;
1200 Function _readListHandler; 1159 Function _readListHandler;
1201 Function _noPendingWriteHandler; 1160 Function _noPendingWriteHandler;
1202 Function _positionHandler; 1161 Function _positionHandler;
1203 Function _setPositionHandler; 1162 Function _setPositionHandler;
1204 Function _truncateHandler; 1163 Function _truncateHandler;
1205 Function _lengthHandler; 1164 Function _lengthHandler;
1206 Function _flushHandler; 1165 Function _flushHandler;
1207 Function _errorHandler; 1166 Function _errorHandler;
1208 } 1167 }
OLDNEW
« no previous file with comments | « runtime/bin/file.dart ('k') | samples/actors/samples/sssp/sssp-util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698