| Index: runtime/bin/file_impl.dart
|
| diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
|
| index d37ad893c94b15082f8636ad892c1b0ef89b61df..98f35d07ba8715cb0e1a306ef1a57530e5815b76 100644
|
| --- a/runtime/bin/file_impl.dart
|
| +++ b/runtime/bin/file_impl.dart
|
| @@ -7,15 +7,14 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
|
| _file = new File(name);
|
| _data = [];
|
| _position = 0;
|
| - _file.errorHandler = (String s) {
|
| + _file.onError = (String s) {
|
| if (_clientErrorHandler != null) {
|
| _clientErrorHandler();
|
| }
|
| };
|
| - _file.open();
|
| - _file.openHandler = (openedFile) {
|
| + _file.open(FileMode.READ, (openedFile) {
|
| _readDataFromFile(openedFile);
|
| - };
|
| + });
|
| }
|
|
|
| _FileInputStream.fromStdio(int fd) {
|
| @@ -27,17 +26,15 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
|
| }
|
|
|
| void _readDataFromFile(RandomAccessFile openedFile) {
|
| - openedFile.errorHandler = (String s) {
|
| + openedFile.onError = (String s) {
|
| if (_clientErrorHandler != null) {
|
| _clientErrorHandler();
|
| }
|
| };
|
| - openedFile.length();
|
| - openedFile.lengthHandler = (length) {
|
| + openedFile.length((length) {
|
| var contents = new ByteArray(length);
|
| if (length != 0) {
|
| - openedFile.readList(contents, 0, length);
|
| - openedFile.readListHandler = (read) {
|
| + openedFile.readList(contents, 0, length, (read) {
|
| if (read != length) {
|
| if (_clientErrorHandler != null) {
|
| _clientErrorHandler();
|
| @@ -45,20 +42,18 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
|
| } else {
|
| _data = contents;
|
| }
|
| - openedFile.close();
|
| - openedFile.closeHandler = () {
|
| + openedFile.close(() {
|
| _streamMarkedClosed = true;
|
| _checkScheduleCallbacks();
|
| - };
|
| - };
|
| + });
|
| + });
|
| } else {
|
| - openedFile.close();
|
| - openedFile.closeHandler = () {
|
| + openedFile.close(() {
|
| _streamMarkedClosed = true;
|
| _checkScheduleCallbacks();
|
| - };
|
| - };
|
| - };
|
| + });
|
| + }
|
| + });
|
| }
|
|
|
| int available() {
|
| @@ -100,14 +95,13 @@ class _FileOutputStream implements OutputStream {
|
| _FileOutputStream(String name, FileMode mode) {
|
| _pendingOperations = new List<List<int>>();
|
| var f = new File(name);
|
| - f.open(mode);
|
| - f.openHandler = (openedFile) {
|
| + f.open(mode, (openedFile) {
|
| _file = openedFile;
|
| _setupFileHandlers();
|
| _processPendingOperations();
|
| - };
|
| - f.errorHandler = (e) {
|
| - if (_errorHandler != null) _errorHandler();
|
| + });
|
| + f.onError = (e) {
|
| + if (_onError != null) _onError();
|
| };
|
| }
|
|
|
| @@ -119,17 +113,14 @@ class _FileOutputStream implements OutputStream {
|
|
|
|
|
| void _setupFileHandlers() {
|
| - _file.errorHandler = (e) {
|
| - if (_errorHandler != null) _errorHandler();
|
| + _file.onError = (e) {
|
| + if (_onError != null) _onError();
|
| };
|
| - _file.noPendingWriteHandler = () {
|
| - if (!_streamMarkedClosed && _noPendingWriteHandler != null) {
|
| - _noPendingWriteHandler();
|
| + _file.onNoPendingWrites = () {
|
| + if (!_streamMarkedClosed && _onNoPendingWrites != null) {
|
| + _onNoPendingWrites();
|
| }
|
| };
|
| - _file.closeHandler = () {
|
| - if (_closeHandler != null) _closeHandler();
|
| - };
|
| }
|
|
|
| bool write(List<int> buffer, [bool copyBuffer = false]) {
|
| @@ -163,21 +154,23 @@ class _FileOutputStream implements OutputStream {
|
| if (_file == null) {
|
| _pendingOperations.add(null);
|
| } else if (!_streamMarkedClosed) {
|
| - _file.close();
|
| + _file.close(() {
|
| + if (_onClosed != null) _onClosed();
|
| + });
|
| _streamMarkedClosed = true;
|
| }
|
| }
|
|
|
| - void set noPendingWriteHandler(void callback()) {
|
| - _noPendingWriteHandler = callback;
|
| + void set onNoPendingWrites(void callback()) {
|
| + _onNoPendingWrites = callback;
|
| }
|
|
|
| - void set closeHandler(void callback()) {
|
| - _closeHandler = callback;
|
| + void set onClosed(void callback()) {
|
| + _onClosed = callback;
|
| }
|
|
|
| - void set errorHandler(void callback()) {
|
| - _errorHandler = callback;
|
| + void set onError(void callback()) {
|
| + _onError = callback;
|
| }
|
|
|
| void _processPendingOperations() {
|
| @@ -205,9 +198,9 @@ class _FileOutputStream implements OutputStream {
|
| // file was successfully opened.
|
| List<List<int>> _pendingOperations;
|
|
|
| - Function _noPendingWriteHandler;
|
| - Function _closeHandler;
|
| - Function _errorHandler;
|
| + Function _onNoPendingWrites;
|
| + Function _onClosed;
|
| + Function _onError;
|
| }
|
|
|
|
|
| @@ -325,12 +318,12 @@ class _File implements File {
|
| // Constructor for file.
|
| _File(String this._name) : _asyncUsed = false;
|
|
|
| - void exists() {
|
| + void exists(void callback(bool exists)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| if (_name is !String) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler('File name is not a string: $_name');
|
| + if (_onError != null) {
|
| + _onError('File name is not a string: $_name');
|
| }
|
| return;
|
| }
|
| @@ -338,7 +331,7 @@ class _File implements File {
|
| request[0] = _FileUtils.kExistsRequest;
|
| request[1] = _name;
|
| _fileService.call(request).receive((exists, replyTo) {
|
| - if (_existsHandler != null) _existsHandler(exists);
|
| + callback(exists);
|
| });
|
| }
|
|
|
| @@ -353,7 +346,7 @@ class _File implements File {
|
| return _FileUtils.exists(_name);
|
| }
|
|
|
| - void create() {
|
| + void create(void callback()) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -361,9 +354,9 @@ class _File implements File {
|
| request[1] = _name;
|
| _fileService.call(request).receive((created, replyTo) {
|
| if (created) {
|
| - if (_createHandler != null) _createHandler();
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("Cannot create file: $_name");
|
| + callback();
|
| + } else if (_onError != null) {
|
| + _onError("Cannot create file: $_name");
|
| }
|
| });
|
| }
|
| @@ -379,7 +372,7 @@ class _File implements File {
|
| }
|
| }
|
|
|
| - void delete() {
|
| + void delete(void callback()) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -387,9 +380,9 @@ class _File implements File {
|
| request[1] = _name;
|
| _fileService.call(request).receive((deleted, replyTo) {
|
| if (deleted) {
|
| - if (_deleteHandler != null) _deleteHandler();
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("Cannot delete file: $_name");
|
| + callback();
|
| + } else if (_onError != null) {
|
| + _onError("Cannot delete file: $_name");
|
| }
|
| });
|
| }
|
| @@ -405,7 +398,7 @@ class _File implements File {
|
| }
|
| }
|
|
|
| - void directory() {
|
| + void directory(void callback(Directory dir)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -413,9 +406,9 @@ class _File implements File {
|
| request[1] = _name;
|
| _fileService.call(request).receive((path, replyTo) {
|
| if (path != null) {
|
| - if (_directoryHandler != null) _directoryHandler(new Directory(path));
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("Cannot get directory for: ${_name}");
|
| + callback(new Directory(path));
|
| + } else if (_onError != null) {
|
| + _onError("Cannot get directory for: ${_name}");
|
| }
|
| });
|
| }
|
| @@ -431,15 +424,15 @@ class _File implements File {
|
| return new Directory(_FileUtils.directory(_name));
|
| }
|
|
|
| - void open([FileMode mode = FileMode.READ]) {
|
| + void open(FileMode mode, void callback(RandomAccessFile file)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| if (mode != FileMode.READ &&
|
| mode != FileMode.WRITE &&
|
| mode != FileMode.APPEND) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler("Unknown file mode. Use FileMode.READ, FileMode.WRITE " +
|
| - "or FileMode.APPEND.");
|
| + if (_onError != null) {
|
| + _onError("Unknown file mode. Use FileMode.READ, FileMode.WRITE " +
|
| + "or FileMode.APPEND.");
|
| return;
|
| }
|
| }
|
| @@ -448,17 +441,10 @@ class _File implements File {
|
| request[1] = _name;
|
| request[2] = mode._mode; // Direct int value for serialization.
|
| _fileService.call(request).receive((id, replyTo) {
|
| - var handler = _openHandler;
|
| - if (handler === null) {
|
| - // If no open handler is present, close the file immediately to
|
| - // avoid leaking an open file descriptor.
|
| - handler = (file) => file.close();
|
| - }
|
| if (id != 0) {
|
| - var randomAccessFile = new _RandomAccessFile(id, _name);
|
| - handler(randomAccessFile);
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("Cannot open file: $_name");
|
| + callback(new _RandomAccessFile(id, _name));
|
| + } else if (_onError != null) {
|
| + _onError("Cannot open file: $_name");
|
| }
|
| });
|
| }
|
| @@ -489,7 +475,7 @@ class _File implements File {
|
| return new _RandomAccessFile(id, "");
|
| }
|
|
|
| - void fullPath() {
|
| + void fullPath(void callback(String result)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -497,9 +483,9 @@ class _File implements File {
|
| request[1] = _name;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result != null) {
|
| - if (_fullPathHandler != null) _fullPathHandler(result);
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("fullPath failed");
|
| + callback(result);
|
| + } else if (_onError != null) {
|
| + _onError("fullPath failed");
|
| }
|
| });
|
| }
|
| @@ -529,22 +515,20 @@ class _File implements File {
|
| return new _FileOutputStream(_name, mode);
|
| }
|
|
|
| - void readAsBytes() {
|
| + void readAsBytes(void callback(List<int> bytes)) {
|
| _asyncUsed = true;
|
| var chunks = new _BufferList();
|
| var stream = openInputStream();
|
| - stream.closeHandler = () {
|
| - if (_readAsBytesHandler != null) {
|
| - _readAsBytesHandler(chunks.readBytes(chunks.length));
|
| - }
|
| + stream.onClosed = () {
|
| + callback(chunks.readBytes(chunks.length));
|
| };
|
| - stream.dataHandler = () {
|
| + stream.onData = () {
|
| var chunk = stream.read();
|
| chunks.add(chunk);
|
| };
|
| - stream.errorHandler = () {
|
| - if (_errorHandler != null) {
|
| - _errorHandler("Failed to read file as bytes: $_name");
|
| + stream.onError = () {
|
| + if (_onError != null) {
|
| + _onError("Failed to read file as bytes: $_name");
|
| }
|
| };
|
| }
|
| @@ -561,7 +545,7 @@ class _File implements File {
|
| if (read != length) {
|
| throw new FileIOException("Failed reading file as bytes: $_name");
|
| }
|
| - opened.close();
|
| + opened.closeSync();
|
| return result;
|
| }
|
|
|
| @@ -576,26 +560,23 @@ class _File implements File {
|
| throw new FileIOException("Unsupported encoding $_encoding");
|
| }
|
|
|
| - void readAsText([String encoding = "UTF-8"]) {
|
| + void readAsText(String encoding, void callback(String text)) {
|
| _asyncUsed = true;
|
| var decoder = _getDecoder(encoding);
|
| - readAsBytes();
|
| - readAsBytesHandler = (bytes) {
|
| - if (_readAsTextHandler != null) {
|
| - try {
|
| - decoder.write(bytes);
|
| - } catch (var e) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler(e.toString());
|
| - return;
|
| - }
|
| + readAsBytes((bytes) {
|
| + try {
|
| + decoder.write(bytes);
|
| + } catch (var e) {
|
| + if (_onError != null) {
|
| + _onError(e.toString());
|
| + return;
|
| }
|
| - _readAsTextHandler(decoder.decoded);
|
| }
|
| - };
|
| + callback(decoder.decoded);
|
| + });
|
| }
|
|
|
| - String readAsTextSync([String encoding = "UTF-8"]) {
|
| + String readAsTextSync([String encoding = 'UTF-8']) {
|
| if (_asyncUsed) {
|
| throw new FileIOException(
|
| "Mixed use of synchronous and asynchronous API");
|
| @@ -622,23 +603,20 @@ class _File implements File {
|
| return result;
|
| }
|
|
|
| - void readAsLines([String encoding = "UTF-8"]) {
|
| + void readAsLines(String encoding, void callback(List<String> lines)) {
|
| _asyncUsed = true;
|
| var decoder = _getDecoder(encoding);
|
| - readAsBytes();
|
| - readAsBytesHandler = (bytes) {
|
| - if (_readAsLinesHandler != null) {
|
| - try {
|
| - decoder.write(bytes);
|
| - } catch (var e) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler(e.toString());
|
| - return;
|
| - }
|
| + readAsBytes((bytes) {
|
| + try {
|
| + decoder.write(bytes);
|
| + } catch (var e) {
|
| + if (_onError != null) {
|
| + _onError(e.toString());
|
| + return;
|
| }
|
| - _readAsLinesHandler(_getDecodedLines(decoder));
|
| }
|
| - };
|
| + callback(_getDecodedLines(decoder));
|
| + });
|
| }
|
|
|
| List<String> readAsLinesSync([String encoding = "UTF-8"]) {
|
| @@ -654,44 +632,8 @@ class _File implements File {
|
|
|
| String get name() => _name;
|
|
|
| - void set existsHandler(void handler(bool exists)) {
|
| - _existsHandler = handler;
|
| - }
|
| -
|
| - void set createHandler(void handler()) {
|
| - _createHandler = handler;
|
| - }
|
| -
|
| - void set deleteHandler(void handler()) {
|
| - _deleteHandler = handler;
|
| - }
|
| -
|
| - void set directoryHandler(void handler(Directory directory)) {
|
| - _directoryHandler = handler;
|
| - }
|
| -
|
| - void set openHandler(void handler(RandomAccessFile file)) {
|
| - _openHandler = handler;
|
| - }
|
| -
|
| - void set readAsBytesHandler(void handler(List<int> bytes)) {
|
| - _readAsBytesHandler = handler;
|
| - }
|
| -
|
| - void set readAsTextHandler(void handler(String text)) {
|
| - _readAsTextHandler = handler;
|
| - }
|
| -
|
| - void set readAsLinesHandler(void handler(List<String> lines)) {
|
| - _readAsLinesHandler = handler;
|
| - }
|
| -
|
| - void set fullPathHandler(void handler(String)) {
|
| - _fullPathHandler = handler;
|
| - }
|
| -
|
| - void set errorHandler(void handler(String error)) {
|
| - _errorHandler = handler;
|
| + void set onError(void handler(String error)) {
|
| + _onError = handler;
|
| }
|
|
|
| void _ensureFileService() {
|
| @@ -705,23 +647,14 @@ class _File implements File {
|
|
|
| SendPort _fileService;
|
|
|
| - Function _existsHandler;
|
| - Function _createHandler;
|
| - Function _deleteHandler;
|
| - Function _directoryHandler;
|
| - Function _openHandler;
|
| - Function _readAsBytesHandler;
|
| - Function _readAsTextHandler;
|
| - Function _readAsLinesHandler;
|
| - Function _fullPathHandler;
|
| - Function _errorHandler;
|
| + Function _onError;
|
| }
|
|
|
|
|
| class _RandomAccessFile implements RandomAccessFile {
|
| _RandomAccessFile(int this._id, String this._name) : _asyncUsed = false;
|
|
|
| - void close() {
|
| + void close(void callback()) {
|
| if (_id == 0) return;
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| @@ -734,9 +667,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result != -1) {
|
| _id = result;
|
| - if (_closeHandler != null) _closeHandler();
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("Cannot close file: $_name");
|
| + callback();
|
| + } else if (_onError != null) {
|
| + _onError("Cannot close file: $_name");
|
| }
|
| });
|
| }
|
| @@ -753,7 +686,7 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _id = id;
|
| }
|
|
|
| - void readByte() {
|
| + void readByte(void callback(int byte)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -761,9 +694,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| request[1] = _id;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result != -1) {
|
| - if (_readByteHandler != null) _readByteHandler(result);
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("readByte failed");
|
| + callback(result);
|
| + } else if (_onError != null) {
|
| + _onError("readByte failed");
|
| }
|
| });
|
| }
|
| @@ -780,12 +713,13 @@ class _RandomAccessFile implements RandomAccessFile {
|
| return result;
|
| }
|
|
|
| - void readList(List<int> buffer, int offset, int bytes) {
|
| + void readList(List<int> buffer, int offset, int bytes,
|
| + void callback(int read)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| if (buffer is !List || offset is !int || bytes is !int) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler("Invalid arguments to readList");
|
| + if (_onError != null) {
|
| + _onError("Invalid arguments to readList");
|
| }
|
| return;
|
| };
|
| @@ -798,10 +732,10 @@ class _RandomAccessFile implements RandomAccessFile {
|
| var read = result[0];
|
| var data = result[1];
|
| buffer.setRange(offset, read, data);
|
| - if (_readListHandler != null) _readListHandler(read);
|
| + callback(read);
|
| return;
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler(result is String ? result : "readList failed");
|
| + } else if (_onError != null) {
|
| + _onError(result is String ? result : "readList failed");
|
| }
|
| });
|
| }
|
| @@ -831,8 +765,8 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| if (value is !int) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler("Invalid argument to writeByte");
|
| + if (_onError != null) {
|
| + _onError("Invalid argument to writeByte");
|
| }
|
| return;
|
| }
|
| @@ -843,8 +777,8 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _writeEnqueued();
|
| _fileService.call(request).receive((result, replyTo) {
|
| _writeCompleted();
|
| - if (result == -1 && _errorHandler !== null) {
|
| - _errorHandler("writeByte failed");
|
| + if (result == -1 && _onError !== null) {
|
| + _onError("writeByte failed");
|
| }
|
| });
|
| }
|
| @@ -868,8 +802,8 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| if (buffer is !List || offset is !int || bytes is !int) {
|
| - if (_errorHandler != null) {
|
| - _errorHandler("Invalid arguments to writeList");
|
| + if (_onError != null) {
|
| + _onError("Invalid arguments to writeList");
|
| }
|
| return;
|
| }
|
| @@ -888,8 +822,8 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _writeEnqueued();
|
| _fileService.call(request).receive((result, replyTo) {
|
| _writeCompleted();
|
| - if (result == -1 && _errorHandler !== null) {
|
| - _errorHandler("writeList failed");
|
| + if (result == -1 && _onError !== null) {
|
| + _onError("writeList failed");
|
| }
|
| });
|
| }
|
| @@ -925,8 +859,8 @@ class _RandomAccessFile implements RandomAccessFile {
|
| _writeEnqueued();
|
| _fileService.call(request).receive((result, replyTo) {
|
| _writeCompleted();
|
| - if (result == -1 && _errorHandler !== null) {
|
| - _errorHandler("writeString failed");
|
| + if (result == -1 && _onError !== null) {
|
| + _onError("writeString failed");
|
| }
|
| });
|
| }
|
| @@ -943,7 +877,7 @@ class _RandomAccessFile implements RandomAccessFile {
|
| return result;
|
| }
|
|
|
| - void position() {
|
| + void position(void callback(int position)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -951,9 +885,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| request[1] = _id;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result != -1) {
|
| - if (_positionHandler != null) _positionHandler(result);
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("position failed");
|
| + callback(result);
|
| + } else if (_onError != null) {
|
| + _onError("position failed");
|
| }
|
| });
|
| }
|
| @@ -970,7 +904,7 @@ class _RandomAccessFile implements RandomAccessFile {
|
| return result;
|
| }
|
|
|
| - void setPosition(int position) {
|
| + void setPosition(int position, void callback()) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(3);
|
| @@ -979,9 +913,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| request[2] = position;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result) {
|
| - if (_setPositionHandler != null) _setPositionHandler();
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("setPosition failed");
|
| + callback();
|
| + } else if (_onError != null) {
|
| + _onError("setPosition failed");
|
| }
|
| });
|
| }
|
| @@ -998,7 +932,7 @@ class _RandomAccessFile implements RandomAccessFile {
|
| }
|
| }
|
|
|
| - void truncate(int length) {
|
| + void truncate(int length, void callback()) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(3);
|
| @@ -1007,9 +941,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| request[2] = length;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result) {
|
| - if (_truncateHandler != null) _truncateHandler();
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("truncate failed");
|
| + callback();
|
| + } else if (_onError != null) {
|
| + _onError("truncate failed");
|
| }
|
| });
|
| }
|
| @@ -1025,7 +959,7 @@ class _RandomAccessFile implements RandomAccessFile {
|
| }
|
| }
|
|
|
| - void length() {
|
| + void length(void callback(int length)) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -1033,9 +967,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| request[1] = _id;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result != -1) {
|
| - if (_lengthHandler != null) _lengthHandler(result);
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("length failed");
|
| + callback(result);
|
| + } else if (_onError != null) {
|
| + _onError("length failed");
|
| }
|
| });
|
| }
|
| @@ -1052,7 +986,7 @@ class _RandomAccessFile implements RandomAccessFile {
|
| return result;
|
| }
|
|
|
| - void flush() {
|
| + void flush(void callback()) {
|
| _ensureFileService();
|
| _asyncUsed = true;
|
| List request = new List(2);
|
| @@ -1060,9 +994,9 @@ class _RandomAccessFile implements RandomAccessFile {
|
| request[1] = _id;
|
| _fileService.call(request).receive((result, replyTo) {
|
| if (result != -1) {
|
| - if (_flushHandler != null) _flushHandler();
|
| - } else if (_errorHandler != null) {
|
| - _errorHandler("flush failed");
|
| + callback();
|
| + } else if (_onError != null) {
|
| + _onError("flush failed");
|
| }
|
| });
|
| }
|
| @@ -1080,51 +1014,19 @@ class _RandomAccessFile implements RandomAccessFile {
|
|
|
| String get name() => _name;
|
|
|
| - void set errorHandler(void handler(String error)) {
|
| - _errorHandler = handler;
|
| - }
|
| -
|
| - void set closeHandler(void handler()) {
|
| - _closeHandler = handler;
|
| - }
|
| -
|
| - void set readByteHandler(void handler(int byte)) {
|
| - _readByteHandler = handler;
|
| + void set onError(void handler(String error)) {
|
| + _onError = handler;
|
| }
|
|
|
| - void set readListHandler(void handler(int read)) {
|
| - _readListHandler = handler;
|
| - }
|
| -
|
| - void set noPendingWriteHandler(void handler()) {
|
| - _noPendingWriteHandler = handler;
|
| + void set onNoPendingWrites(void handler()) {
|
| + _onNoPendingWrites = handler;
|
| if (_pendingWrites == 0) {
|
| _noPendingWriteTimer = new Timer((t) {
|
| - if (_noPendingWriteHandler != null) _noPendingWriteHandler();
|
| + if (_onNoPendingWrites != null) _onNoPendingWrites();
|
| }, 0);
|
| }
|
| }
|
|
|
| - void set positionHandler(void handler(int pos)) {
|
| - _positionHandler = handler;
|
| - }
|
| -
|
| - void set setPositionHandler(void handler()) {
|
| - _setPositionHandler = handler;
|
| - }
|
| -
|
| - void set truncateHandler(void handler()) {
|
| - _truncateHandler = handler;
|
| - }
|
| -
|
| - void set lengthHandler(void handler(int length)) {
|
| - _lengthHandler = handler;
|
| - }
|
| -
|
| - void set flushHandler(void handler()) {
|
| - _flushHandler = handler;
|
| - }
|
| -
|
| void _ensureFileService() {
|
| if (_fileService == null) {
|
| _fileService = _FileUtils.newServicePort();
|
| @@ -1141,8 +1043,8 @@ class _RandomAccessFile implements RandomAccessFile {
|
|
|
| void _writeCompleted() {
|
| _pendingWrites--;
|
| - if (_pendingWrites == 0 && _noPendingWriteHandler != null) {
|
| - _noPendingWriteHandler();
|
| + if (_pendingWrites == 0 && _onNoPendingWrites != null) {
|
| + _onNoPendingWrites();
|
| }
|
| }
|
|
|
| @@ -1156,14 +1058,6 @@ class _RandomAccessFile implements RandomAccessFile {
|
|
|
| Timer _noPendingWriteTimer;
|
|
|
| - Function _closeHandler;
|
| - Function _readByteHandler;
|
| - Function _readListHandler;
|
| - Function _noPendingWriteHandler;
|
| - Function _positionHandler;
|
| - Function _setPositionHandler;
|
| - Function _truncateHandler;
|
| - Function _lengthHandler;
|
| - Function _flushHandler;
|
| - Function _errorHandler;
|
| + Function _onNoPendingWrites;
|
| + Function _onError;
|
| }
|
|
|