| 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 var file = new File(name); |
| 8 _data = []; | 8 _data = []; |
| 9 _position = 0; | 9 _position = 0; |
| 10 _file.onError = _reportError; | 10 file.onError = _reportError; |
| 11 _file.open(FileMode.READ, (openedFile) { | 11 file.open(FileMode.READ, (openedFile) { |
| 12 _readDataFromFile(openedFile); | 12 _readDataFromFile(openedFile); |
| 13 }); | 13 }); |
| 14 } | 14 } |
| 15 | 15 |
| 16 _FileInputStream.fromStdio(int fd) { | 16 _FileInputStream.fromStdio(int fd) { |
| 17 assert(fd == 0); | 17 assert(fd == 0); |
| 18 _file = _File._openStdioSync(fd); | 18 var file = _File._openStdioSync(fd); |
| 19 _data = []; | 19 _data = []; |
| 20 _position = 0; | 20 _position = 0; |
| 21 _readDataFromFile(_file); | 21 _readDataFromFile(file); |
| 22 } | 22 } |
| 23 | 23 |
| 24 void _readDataFromFile(RandomAccessFile openedFile) { | 24 void _readDataFromFile(RandomAccessFile openedFile) { |
| 25 openedFile.onError = _reportError; | 25 openedFile.onError = _reportError; |
| 26 openedFile.length((length) { | 26 openedFile.length((length) { |
| 27 var contents = new ByteArray(length); | 27 var contents = new ByteArray(length); |
| 28 if (length != 0) { | 28 if (length != 0) { |
| 29 openedFile.readList(contents, 0, length, (read) { | 29 openedFile.readList(contents, 0, length, (read) { |
| 30 if (read != length) { | 30 if (read != length) { |
| 31 _reportError(new FileIOException( | 31 _reportError(new FileIOException( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 _position += len; | 68 _position += len; |
| 69 _checkScheduleCallbacks(); | 69 _checkScheduleCallbacks(); |
| 70 return len; | 70 return len; |
| 71 } | 71 } |
| 72 | 72 |
| 73 void _close() { | 73 void _close() { |
| 74 if (_closed) return; | 74 if (_closed) return; |
| 75 _closed = true; | 75 _closed = true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 File _file; | |
| 79 List<int> _data; | 78 List<int> _data; |
| 80 int _position; | 79 int _position; |
| 81 bool _closed = false; | 80 bool _closed = false; |
| 82 } | 81 } |
| 83 | 82 |
| 84 | 83 |
| 85 class _FileOutputStream extends _BaseOutputStream implements OutputStream { | 84 class _FileOutputStream extends _BaseOutputStream implements OutputStream { |
| 86 _FileOutputStream(String name, FileMode mode) { | 85 _FileOutputStream(String name, FileMode mode) { |
| 87 _pendingOperations = new List<List<int>>(); | 86 _pendingOperations = new List<List<int>>(); |
| 88 var f = new File(name); | 87 var f = new File(name); |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 String _name; | 1042 String _name; |
| 1044 int _id; | 1043 int _id; |
| 1045 int _pendingWrites = 0; | 1044 int _pendingWrites = 0; |
| 1046 | 1045 |
| 1047 SendPort _fileService; | 1046 SendPort _fileService; |
| 1048 | 1047 |
| 1049 Timer _noPendingWriteTimer; | 1048 Timer _noPendingWriteTimer; |
| 1050 | 1049 |
| 1051 Function _onNoPendingWrites; | 1050 Function _onNoPendingWrites; |
| 1052 } | 1051 } |
| OLD | NEW |