| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 _FlushOperation(int this._id); | 294 _FlushOperation(int this._id); |
| 295 | 295 |
| 296 void execute(ReceivePort port) { | 296 void execute(ReceivePort port) { |
| 297 _replyPort.send(_File._flush(_id), port.toSendPort()); | 297 _replyPort.send(_File._flush(_id), port.toSendPort()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 int _id; | 300 int _id; |
| 301 } | 301 } |
| 302 | 302 |
| 303 | 303 |
| 304 class _CreateOperation extends _FileOperation { |
| 305 _CreateOperation(String this._name); |
| 306 |
| 307 void execute(ReceivePort port) { |
| 308 _replyPort.send(_File._create(_name), port.toSendPort()); |
| 309 } |
| 310 |
| 311 String _name; |
| 312 } |
| 313 |
| 314 |
| 304 class _ExitOperation extends _FileOperation { | 315 class _ExitOperation extends _FileOperation { |
| 305 void execute(ReceivePort port) { | 316 void execute(ReceivePort port) { |
| 306 port.close(); | 317 port.close(); |
| 307 } | 318 } |
| 308 } | 319 } |
| 309 | 320 |
| 310 | 321 |
| 311 class _FileOperationIsolate extends Isolate { | 322 class _FileOperationIsolate extends Isolate { |
| 312 _FileOperationIsolate() : super.heavy(); | 323 _FileOperationIsolate() : super.heavy(); |
| 313 | 324 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 static int _readByte(int id) native "File_ReadByte"; | 394 static int _readByte(int id) native "File_ReadByte"; |
| 384 static int _readList(int id, List<int> buffer, int offset, int bytes) | 395 static int _readList(int id, List<int> buffer, int offset, int bytes) |
| 385 native "File_ReadList"; | 396 native "File_ReadList"; |
| 386 static int _writeByte(int id, int value) native "File_WriteByte"; | 397 static int _writeByte(int id, int value) native "File_WriteByte"; |
| 387 static int _writeList(int id, List<int> buffer, int offset, int bytes) | 398 static int _writeList(int id, List<int> buffer, int offset, int bytes) |
| 388 native "File_WriteList"; | 399 native "File_WriteList"; |
| 389 static int _writeString(int id, String string) native "File_WriteString"; | 400 static int _writeString(int id, String string) native "File_WriteString"; |
| 390 static int _position(int id) native "File_Position"; | 401 static int _position(int id) native "File_Position"; |
| 391 static int _length(int id) native "File_Length"; | 402 static int _length(int id) native "File_Length"; |
| 392 static int _flush(int id) native "File_Flush"; | 403 static int _flush(int id) native "File_Flush"; |
| 404 static bool _create(String name) native "File_Create"; |
| 393 | 405 |
| 394 static int _checkReadWriteListArguments(int length, int offset, int bytes) { | 406 static int _checkReadWriteListArguments(int length, int offset, int bytes) { |
| 395 if (offset < 0) return offset; | 407 if (offset < 0) return offset; |
| 396 if (bytes < 0) return bytes; | 408 if (bytes < 0) return bytes; |
| 397 if ((offset + bytes) > length) return offset + bytes; | 409 if ((offset + bytes) > length) return offset + bytes; |
| 398 return 0; | 410 return 0; |
| 399 } | 411 } |
| 400 | 412 |
| 401 void exists() { | 413 void exists() { |
| 402 _asyncUsed = true; | 414 _asyncUsed = true; |
| 403 var handler = | 415 var handler = |
| 404 (_existsHandler != null) ? _existsHandler : (result) => null; | 416 (_existsHandler != null) ? _existsHandler : (result) => null; |
| 405 var operation = new _ExistsOperation(_name); | 417 var operation = new _ExistsOperation(_name); |
| 406 _scheduler.enqueue(operation, (result, ignored) { _existsHandler(result); })
; | 418 _scheduler.enqueue(operation, (result, ignored) { _existsHandler(result); })
; |
| 407 } | 419 } |
| 408 | 420 |
| 409 bool existsSync() { | 421 bool existsSync() { |
| 410 if (_asyncUsed) { | 422 if (_asyncUsed) { |
| 411 throw new FileIOException( | 423 throw new FileIOException( |
| 412 "Mixed use of synchronous and asynchronous API"); | 424 "Mixed use of synchronous and asynchronous API"); |
| 413 } | 425 } |
| 414 return _exists(_name); | 426 return _exists(_name); |
| 415 } | 427 } |
| 416 | 428 |
| 417 void create() { | 429 void create() { |
| 418 _asyncUsed = true; | 430 _asyncUsed = true; |
| 419 throw "Unimplemented"; | 431 var handler = (_createHandler != null) ? _createHandler : () => null; |
| 432 var handleCreateResult = (created, ignored) { |
| 433 if (created) { |
| 434 handler(); |
| 435 } else if (_errorHandler != null) { |
| 436 _errorHandler("Cannot create file: $_name"); |
| 437 } |
| 438 }; |
| 439 var operation = new _CreateOperation(_name); |
| 440 _scheduler.enqueue(operation, handleCreateResult); |
| 420 } | 441 } |
| 421 | 442 |
| 422 void createSync() { | 443 void createSync() { |
| 423 if (_asyncUsed) { | 444 if (_asyncUsed) { |
| 424 throw new FileIOException( | 445 throw new FileIOException( |
| 425 "Mixed use of synchronous and asynchronous API"); | 446 "Mixed use of synchronous and asynchronous API"); |
| 426 } | 447 } |
| 427 throw "Unimplemented"; | 448 bool created = _create(_name); |
| 449 if (!created) { |
| 450 throw new FileIOException("Cannot create file: $_name"); |
| 451 } |
| 428 } | 452 } |
| 429 | 453 |
| 430 void open([bool writable = false]) { | 454 void open([bool writable = false]) { |
| 431 _asyncUsed = true; | 455 _asyncUsed = true; |
| 432 var handler = (_openHandler != null) ? _openHandler : () => null; | 456 var handler = (_openHandler != null) ? _openHandler : () => null; |
| 433 var handleOpenResult = (result, ignored) { | 457 var handleOpenResult = (result, ignored) { |
| 434 if (result != 0) { | 458 if (result != 0) { |
| 435 _id = result; | 459 _id = result; |
| 436 handler(); | 460 handler(); |
| 437 } else if (_errorHandler != null) { | 461 } else if (_errorHandler != null) { |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 var _openHandler; | 806 var _openHandler; |
| 783 var _closeHandler; | 807 var _closeHandler; |
| 784 var _readByteHandler; | 808 var _readByteHandler; |
| 785 var _readListHandler; | 809 var _readListHandler; |
| 786 var _noPendingWriteHandler; | 810 var _noPendingWriteHandler; |
| 787 var _positionHandler; | 811 var _positionHandler; |
| 788 var _lengthHandler; | 812 var _lengthHandler; |
| 789 var _flushHandler; | 813 var _flushHandler; |
| 790 var _errorHandler; | 814 var _errorHandler; |
| 791 } | 815 } |
| OLD | NEW |