Chromium Code Reviews| 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(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 _replyPort.send(0, port.toSendPort()); | 214 _replyPort.send(0, port.toSendPort()); |
| 215 return; | 215 return; |
| 216 } | 216 } |
| 217 int index = | 217 int index = |
| 218 _FileUtils.checkReadWriteListArguments(_buffer.length, _offset, _bytes); | 218 _FileUtils.checkReadWriteListArguments(_buffer.length, _offset, _bytes); |
| 219 if (index != 0) { | 219 if (index != 0) { |
| 220 _replyPort.send("index out of range in writeList: $index", | 220 _replyPort.send("index out of range in writeList: $index", |
| 221 port.toSendPort()); | 221 port.toSendPort()); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 var result = _FileUtils.writeList(_id, _buffer, _offset, _bytes); | 224 var result = _FileUtils._writeList(_id, _buffer, _offset, _bytes); |
| 225 _replyPort.send(result, port.toSendPort()); | 225 _replyPort.send(result, port.toSendPort()); |
| 226 } | 226 } |
| 227 | 227 |
| 228 bool isWrite() => true; | 228 bool isWrite() => true; |
| 229 | 229 |
| 230 int _id; | 230 int _id; |
| 231 List _buffer; | 231 List _buffer; |
| 232 int _offset; | 232 int _offset; |
| 233 int _bytes; | 233 int _bytes; |
| 234 } | 234 } |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 static bool exists(String name) native "File_Exists"; | 413 static bool exists(String name) native "File_Exists"; |
| 414 static int open(String name, int mode) native "File_Open"; | 414 static int open(String name, int mode) native "File_Open"; |
| 415 static bool create(String name) native "File_Create"; | 415 static bool create(String name) native "File_Create"; |
| 416 static bool delete(String name) native "File_Delete"; | 416 static bool delete(String name) native "File_Delete"; |
| 417 static String fullPath(String name) native "File_FullPath"; | 417 static String fullPath(String name) native "File_FullPath"; |
| 418 static int close(int id) native "File_Close"; | 418 static int close(int id) native "File_Close"; |
| 419 static int readByte(int id) native "File_ReadByte"; | 419 static int readByte(int id) native "File_ReadByte"; |
| 420 static int readList(int id, List<int> buffer, int offset, int bytes) | 420 static int readList(int id, List<int> buffer, int offset, int bytes) |
| 421 native "File_ReadList"; | 421 native "File_ReadList"; |
| 422 static int writeByte(int id, int value) native "File_WriteByte"; | 422 static int writeByte(int id, int value) native "File_WriteByte"; |
| 423 static int writeList(int id, List<int> buffer, int offset, int bytes) | 423 static int _writeList(int id, List<int> buffer, int offset, int bytes) { |
|
Mads Ager (google)
2012/01/19 07:13:27
You can't get to this member in any case from the
Ivan Posva
2012/01/20 21:55:06
The thing is that if somebody decides to make File
| |
| 424 ObjectArray out_buffer; | |
| 425 int out_offset = offset; | |
| 426 if (buffer is ObjectArray) { | |
| 427 out_buffer = buffer; | |
| 428 } else { | |
| 429 out_buffer = new ObjectArray(bytes); | |
| 430 out_offset = 0; | |
| 431 int j = offset; | |
| 432 for (int i = 0; i < bytes; i++) { | |
| 433 out_buffer[i] = buffer[j]; | |
| 434 j++; | |
| 435 } | |
| 436 } | |
| 437 return __writeList(id, out_buffer, out_offset, bytes); | |
| 438 } | |
| 439 static int __writeList(int id, List<int> buffer, int offset, int bytes) | |
| 424 native "File_WriteList"; | 440 native "File_WriteList"; |
| 425 static int writeString(int id, String string) native "File_WriteString"; | 441 static int writeString(int id, String string) native "File_WriteString"; |
| 426 static int position(int id) native "File_Position"; | 442 static int position(int id) native "File_Position"; |
| 427 static bool setPosition(int id, int position) native "File_SetPosition"; | 443 static bool setPosition(int id, int position) native "File_SetPosition"; |
| 428 static bool truncate(int id, int length) native "File_Truncate"; | 444 static bool truncate(int id, int length) native "File_Truncate"; |
| 429 static int length(int id) native "File_Length"; | 445 static int length(int id) native "File_Length"; |
| 430 static int flush(int id) native "File_Flush"; | 446 static int flush(int id) native "File_Flush"; |
| 431 | 447 |
| 432 static int checkedOpen(String name, int mode) { | 448 static int checkedOpen(String name, int mode) { |
| 433 if (name is !String || mode is !int) return 0; | 449 if (name is !String || mode is !int) return 0; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 567 var randomAccessFile = new _RandomAccessFile(id, _name); | 583 var randomAccessFile = new _RandomAccessFile(id, _name); |
| 568 handler(randomAccessFile); | 584 handler(randomAccessFile); |
| 569 } else if (_errorHandler != null) { | 585 } else if (_errorHandler != null) { |
| 570 _errorHandler("Cannot open file: $_name"); | 586 _errorHandler("Cannot open file: $_name"); |
| 571 } | 587 } |
| 572 }; | 588 }; |
| 573 var operation = new _OpenOperation(_name, mode.mode); | 589 var operation = new _OpenOperation(_name, mode.mode); |
| 574 _scheduler.enqueue(operation, handleOpenResult); | 590 _scheduler.enqueue(operation, handleOpenResult); |
| 575 } | 591 } |
| 576 | 592 |
| 577 void openSync([FileMode mode = FileMode.READ]) { | 593 RandomAccessFile openSync([FileMode mode = FileMode.READ]) { |
| 578 if (_asyncUsed) { | 594 if (_asyncUsed) { |
| 579 throw new FileIOException( | 595 throw new FileIOException( |
| 580 "Mixed use of synchronous and asynchronous API"); | 596 "Mixed use of synchronous and asynchronous API"); |
| 581 } | 597 } |
| 582 if (mode != FileMode.READ && | 598 if (mode != FileMode.READ && |
| 583 mode != FileMode.WRITE && | 599 mode != FileMode.WRITE && |
| 584 mode != FileMode.APPEND) { | 600 mode != FileMode.APPEND) { |
| 585 throw new FileIOException("Unknown file mode. Use FileMode.READ, " + | 601 throw new FileIOException("Unknown file mode. Use FileMode.READ, " + |
| 586 "FileMode.WRITE or FileMode.APPEND."); | 602 "FileMode.WRITE or FileMode.APPEND."); |
| 587 } | 603 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 840 } | 856 } |
| 841 if (buffer is !List || offset is !int || bytes is !int) { | 857 if (buffer is !List || offset is !int || bytes is !int) { |
| 842 throw new FileIOException("Invalid arguments to writeList"); | 858 throw new FileIOException("Invalid arguments to writeList"); |
| 843 } | 859 } |
| 844 if (bytes == 0) return 0; | 860 if (bytes == 0) return 0; |
| 845 int index = | 861 int index = |
| 846 _FileUtils.checkReadWriteListArguments(buffer.length, offset, bytes); | 862 _FileUtils.checkReadWriteListArguments(buffer.length, offset, bytes); |
| 847 if (index != 0) { | 863 if (index != 0) { |
| 848 throw new IndexOutOfRangeException(index); | 864 throw new IndexOutOfRangeException(index); |
| 849 } | 865 } |
| 850 int result = _FileUtils.writeList(_id, buffer, offset, bytes); | 866 int result = _FileUtils._writeList(_id, buffer, offset, bytes); |
| 851 if (result == -1) { | 867 if (result == -1) { |
| 852 throw new FileIOException("writeList failed"); | 868 throw new FileIOException("writeList failed"); |
| 853 } | 869 } |
| 854 return result; | 870 return result; |
| 855 } | 871 } |
| 856 | 872 |
| 857 void writeString(String string) { | 873 void writeString(String string) { |
| 858 _asyncUsed = true; | 874 _asyncUsed = true; |
| 859 var handleWriteStringResult = (result, ignored) { | 875 var handleWriteStringResult = (result, ignored) { |
| 860 if (result == -1 &&_errorHandler != null) { | 876 if (result == -1 &&_errorHandler != null) { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 var _readByteHandler; | 1079 var _readByteHandler; |
| 1064 var _readListHandler; | 1080 var _readListHandler; |
| 1065 var _noPendingWriteHandler; | 1081 var _noPendingWriteHandler; |
| 1066 var _positionHandler; | 1082 var _positionHandler; |
| 1067 var _setPositionHandler; | 1083 var _setPositionHandler; |
| 1068 var _truncateHandler; | 1084 var _truncateHandler; |
| 1069 var _lengthHandler; | 1085 var _lengthHandler; |
| 1070 var _flushHandler; | 1086 var _flushHandler; |
| 1071 var _errorHandler; | 1087 var _errorHandler; |
| 1072 } | 1088 } |
| OLD | NEW |