| 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 extends _BaseDataInputStream implements InputStream { | 5 class _FileInputStream extends _BaseDataInputStream implements InputStream { |
| 6 _FileInputStream(File file) { | 6 _FileInputStream(File file) { |
| 7 _file = file.openSync(); | 7 _file = file.openSync(); |
| 8 _length = _file.lengthSync(); | 8 _length = _file.lengthSync(); |
| 9 _streamMarkedClosed = true; | 9 _streamMarkedClosed = true; |
| 10 _checkScheduleCallbacks(); | 10 _checkScheduleCallbacks(); |
| 11 } | 11 } |
| 12 | 12 |
| 13 int available() { | 13 int available() { |
| 14 return _length - _file.positionSync(); | 14 return _closed ? 0 : _length - _file.positionSync(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 void pipe(OutputStream output, [bool close = true]) { | 17 void pipe(OutputStream output, [bool close = true]) { |
| 18 _pipe(this, output, close: close); | 18 _pipe(this, output, close: close); |
| 19 } | 19 } |
| 20 | 20 |
| 21 List<int> _read(int bytesToRead) { | 21 List<int> _read(int bytesToRead) { |
| 22 List<int> result = new List<int>(bytesToRead); | 22 List<int> result = new List<int>(bytesToRead); |
| 23 int bytesRead = _file.readListSync(result, 0, bytesToRead); | 23 int bytesRead = _file.readListSync(result, 0, bytesToRead); |
| 24 if (bytesRead < bytesToRead) { | 24 if (bytesRead < bytesToRead) { |
| 25 List<int> buffer = new List<int>(bytesRead); | 25 List<int> buffer = new List<int>(bytesRead); |
| 26 buffer.copyFrom(result, 0, 0, bytesRead); | 26 buffer.copyFrom(result, 0, 0, bytesRead); |
| 27 result = buffer; | 27 result = buffer; |
| 28 } | 28 } |
| 29 _checkScheduleCallbacks(); | 29 _checkScheduleCallbacks(); |
| 30 return result; | 30 return result; |
| 31 } | 31 } |
| 32 | 32 |
| 33 int _readInto(List<int> buffer, int offset, int len) { | 33 int _readInto(List<int> buffer, int offset, int len) { |
| 34 int result = _file.readListSync(buffer, offset, len); | 34 int result = _file.readListSync(buffer, offset, len); |
| 35 _checkScheduleCallbacks(); | 35 _checkScheduleCallbacks(); |
| 36 return result; | 36 return result; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void close() { | 39 void _close() { |
| 40 if (_closed) return; |
| 40 _file.closeSync(); | 41 _file.closeSync(); |
| 41 _closeCallbackCalled = true; | 42 _closed = true; |
| 42 } | 43 } |
| 43 | 44 |
| 44 RandomAccessFile _file; | 45 RandomAccessFile _file; |
| 45 int _length; | 46 int _length; |
| 47 bool _closed = false; |
| 46 } | 48 } |
| 47 | 49 |
| 48 | 50 |
| 49 class _FileOutputStream implements OutputStream { | 51 class _FileOutputStream implements OutputStream { |
| 50 _FileOutputStream(File file) { | 52 _FileOutputStream(File file) { |
| 51 _file = file.openSync(true); | 53 _file = file.openSync(true); |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool write(List<int> buffer, [bool copyBuffer = false]) { | 56 bool write(List<int> buffer, [bool copyBuffer = false]) { |
| 55 return _write(buffer, 0, buffer.length); | 57 return _write(buffer, 0, buffer.length); |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 var _readByteHandler; | 1048 var _readByteHandler; |
| 1047 var _readListHandler; | 1049 var _readListHandler; |
| 1048 var _noPendingWriteHandler; | 1050 var _noPendingWriteHandler; |
| 1049 var _positionHandler; | 1051 var _positionHandler; |
| 1050 var _setPositionHandler; | 1052 var _setPositionHandler; |
| 1051 var _truncateHandler; | 1053 var _truncateHandler; |
| 1052 var _lengthHandler; | 1054 var _lengthHandler; |
| 1053 var _flushHandler; | 1055 var _flushHandler; |
| 1054 var _errorHandler; | 1056 var _errorHandler; |
| 1055 } | 1057 } |
| OLD | NEW |