| 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 : _data = const [], | 7 : _data = const [], |
| 8 _position = 0, | 8 _position = 0, |
| 9 _filePosition = 0 { | 9 _filePosition = 0 { |
| 10 var file = new File(name); | 10 var file = new File(name); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 } | 133 } |
| 134 | 134 |
| 135 void _close() { | 135 void _close() { |
| 136 _data = const []; | 136 _data = const []; |
| 137 _position = 0; | 137 _position = 0; |
| 138 _filePosition = 0; | 138 _filePosition = 0; |
| 139 _fileLength = 0; | 139 _fileLength = 0; |
| 140 _closeFile(); | 140 _closeFile(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 static final int _bufferLength = 64 * 1024; | 143 static const int _bufferLength = 64 * 1024; |
| 144 | 144 |
| 145 RandomAccessFile _openedFile; | 145 RandomAccessFile _openedFile; |
| 146 List<int> _data; | 146 List<int> _data; |
| 147 int _position; | 147 int _position; |
| 148 int _filePosition; | 148 int _filePosition; |
| 149 int _fileLength; | 149 int _fileLength; |
| 150 bool _activeFillBufferCall = false; | 150 bool _activeFillBufferCall = false; |
| 151 } | 151 } |
| 152 | 152 |
| 153 | 153 |
| 154 class _PendingOperation { | 154 class _PendingOperation { |
| 155 const _PendingOperation(this._id); | 155 const _PendingOperation(this._id); |
| 156 static final _PendingOperation CLOSE = const _PendingOperation(0); | 156 static const _PendingOperation CLOSE = const _PendingOperation(0); |
| 157 static final _PendingOperation FLUSH = const _PendingOperation(1); | 157 static const _PendingOperation FLUSH = const _PendingOperation(1); |
| 158 final int _id; | 158 final int _id; |
| 159 } | 159 } |
| 160 | 160 |
| 161 | 161 |
| 162 class _FileOutputStream extends _BaseOutputStream implements OutputStream { | 162 class _FileOutputStream extends _BaseOutputStream implements OutputStream { |
| 163 _FileOutputStream(String name, FileMode mode) { | 163 _FileOutputStream(String name, FileMode mode) { |
| 164 _pendingOperations = new List(); | 164 _pendingOperations = new List(); |
| 165 var f = new File(name); | 165 var f = new File(name); |
| 166 var openFuture = f.open(mode); | 166 var openFuture = f.open(mode); |
| 167 openFuture.then((openedFile) { | 167 openFuture.then((openedFile) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 // file was successfully opened. | 299 // file was successfully opened. |
| 300 List _pendingOperations; | 300 List _pendingOperations; |
| 301 | 301 |
| 302 Function _onNoPendingWrites; | 302 Function _onNoPendingWrites; |
| 303 Function _onClosed; | 303 Function _onClosed; |
| 304 } | 304 } |
| 305 | 305 |
| 306 | 306 |
| 307 // Helper class containing static file helper methods. | 307 // Helper class containing static file helper methods. |
| 308 class _FileUtils { | 308 class _FileUtils { |
| 309 static final EXISTS_REQUEST = 0; | 309 static const EXISTS_REQUEST = 0; |
| 310 static final CREATE_REQUEST = 1; | 310 static const CREATE_REQUEST = 1; |
| 311 static final DELETE_REQUEST = 2; | 311 static const DELETE_REQUEST = 2; |
| 312 static final OPEN_REQUEST = 3; | 312 static const OPEN_REQUEST = 3; |
| 313 static final FULL_PATH_REQUEST = 4; | 313 static const FULL_PATH_REQUEST = 4; |
| 314 static final DIRECTORY_REQUEST = 5; | 314 static const DIRECTORY_REQUEST = 5; |
| 315 static final CLOSE_REQUEST = 6; | 315 static const CLOSE_REQUEST = 6; |
| 316 static final POSITION_REQUEST = 7; | 316 static const POSITION_REQUEST = 7; |
| 317 static final SET_POSITION_REQUEST = 8; | 317 static const SET_POSITION_REQUEST = 8; |
| 318 static final TRUNCATE_REQUEST = 9; | 318 static const TRUNCATE_REQUEST = 9; |
| 319 static final LENGTH_REQUEST = 10; | 319 static const LENGTH_REQUEST = 10; |
| 320 static final LENGTH_FROM_NAME_REQUEST = 11; | 320 static const LENGTH_FROM_NAME_REQUEST = 11; |
| 321 static final LAST_MODIFIED_REQUEST = 12; | 321 static const LAST_MODIFIED_REQUEST = 12; |
| 322 static final FLUSH_REQUEST = 13; | 322 static const FLUSH_REQUEST = 13; |
| 323 static final READ_BYTE_REQUEST = 14; | 323 static const READ_BYTE_REQUEST = 14; |
| 324 static final WRITE_BYTE_REQUEST = 15; | 324 static const WRITE_BYTE_REQUEST = 15; |
| 325 static final READ_LIST_REQUEST = 16; | 325 static const READ_LIST_REQUEST = 16; |
| 326 static final WRITE_LIST_REQUEST = 17; | 326 static const WRITE_LIST_REQUEST = 17; |
| 327 static final WRITE_STRING_REQUEST = 18; | 327 static const WRITE_STRING_REQUEST = 18; |
| 328 | 328 |
| 329 static final SUCCESS_RESPONSE = 0; | 329 static const SUCCESS_RESPONSE = 0; |
| 330 static final ILLEGAL_ARGUMENT_RESPONSE = 1; | 330 static const ILLEGAL_ARGUMENT_RESPONSE = 1; |
| 331 static final OSERROR_RESPONSE = 2; | 331 static const OSERROR_RESPONSE = 2; |
| 332 static final FILE_CLOSED_RESPONSE = 3; | 332 static const FILE_CLOSED_RESPONSE = 3; |
| 333 | 333 |
| 334 static final ERROR_RESPONSE_ERROR_TYPE = 0; | 334 static const ERROR_RESPONSE_ERROR_TYPE = 0; |
| 335 static final OSERROR_RESPONSE_ERROR_CODE = 1; | 335 static const OSERROR_RESPONSE_ERROR_CODE = 1; |
| 336 static final OSERROR_RESPONSE_MESSAGE = 2; | 336 static const OSERROR_RESPONSE_MESSAGE = 2; |
| 337 | 337 |
| 338 static List ensureFastAndSerializableBuffer( | 338 static List ensureFastAndSerializableBuffer( |
| 339 List buffer, int offset, int bytes) { | 339 List buffer, int offset, int bytes) { |
| 340 // When using the Dart C API to access raw data, using a ByteArray is | 340 // When using the Dart C API to access raw data, using a ByteArray is |
| 341 // currently much faster. This function will make a copy of the | 341 // currently much faster. This function will make a copy of the |
| 342 // supplied List to a ByteArray if it isn't already. | 342 // supplied List to a ByteArray if it isn't already. |
| 343 List outBuffer; | 343 List outBuffer; |
| 344 int outOffset = offset; | 344 int outOffset = offset; |
| 345 if (buffer is Uint8List || buffer is ObjectArray) { | 345 if (buffer is Uint8List || buffer is ObjectArray) { |
| 346 outBuffer = buffer; | 346 outBuffer = buffer; |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 new FileIOException("File closed '$_name'")); | 1161 new FileIOException("File closed '$_name'")); |
| 1162 }); | 1162 }); |
| 1163 return completer.future; | 1163 return completer.future; |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 final String _name; | 1166 final String _name; |
| 1167 int _id; | 1167 int _id; |
| 1168 | 1168 |
| 1169 SendPort _fileService; | 1169 SendPort _fileService; |
| 1170 } | 1170 } |
| OLD | NEW |