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 _file = new File(name); |
8 _data = []; | 8 _data = []; |
9 _position = 0; | 9 _position = 0; |
10 _file.onError = (e) { | 10 _file.onError = (e) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 static final kWriteByteRequest = 13; | 222 static final kWriteByteRequest = 13; |
223 static final kReadListRequest = 14; | 223 static final kReadListRequest = 14; |
224 static final kWriteListRequest = 15; | 224 static final kWriteListRequest = 15; |
225 static final kWriteStringRequest = 16; | 225 static final kWriteStringRequest = 16; |
226 | 226 |
227 static final kSuccessResponse = 0; | 227 static final kSuccessResponse = 0; |
228 static final kIllegalArgumentResponse = 1; | 228 static final kIllegalArgumentResponse = 1; |
229 static final kOSErrorResponse = 2; | 229 static final kOSErrorResponse = 2; |
230 static final kFileClosedResponse = 3; | 230 static final kFileClosedResponse = 3; |
231 | 231 |
| 232 static final kErrorResponseErrorType = 0; |
| 233 static final kOSErrorResponseErrorCode = 1; |
| 234 static final kOSErrorResponseMessage = 2; |
| 235 |
232 static List ensureFastAndSerializableBuffer( | 236 static List ensureFastAndSerializableBuffer( |
233 List buffer, int offset, int bytes) { | 237 List buffer, int offset, int bytes) { |
234 // When using the Dart C API to access raw data, using a ByteArray is | 238 // When using the Dart C API to access raw data, using a ByteArray is |
235 // currently much faster. This function will make a copy of the | 239 // currently much faster. This function will make a copy of the |
236 // supplied List to a ByteArray if it isn't already. | 240 // supplied List to a ByteArray if it isn't already. |
237 List outBuffer; | 241 List outBuffer; |
238 int outOffset = offset; | 242 int outOffset = offset; |
239 if (buffer is ByteArray || buffer is ObjectArray) { | 243 if (buffer is ByteArray || buffer is ObjectArray) { |
240 outBuffer = buffer; | 244 outBuffer = buffer; |
241 } else { | 245 } else { |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 370 |
367 // Base class for _File and _RandomAccessFile with shared functions. | 371 // Base class for _File and _RandomAccessFile with shared functions. |
368 class _FileBase { | 372 class _FileBase { |
369 bool _isErrorResponse(response) { | 373 bool _isErrorResponse(response) { |
370 return response is List && response[0] != _FileUtils.kSuccessResponse; | 374 return response is List && response[0] != _FileUtils.kSuccessResponse; |
371 } | 375 } |
372 | 376 |
373 bool _reportError(response, String message) { | 377 bool _reportError(response, String message) { |
374 assert(_isErrorResponse(response)); | 378 assert(_isErrorResponse(response)); |
375 if (_onError != null) { | 379 if (_onError != null) { |
376 switch (response[0]) { | 380 switch (response[_FileUtil.kErrorResponseErrorType]) { |
377 case _FileUtils.kIllegalArgumentResponse: | 381 case _FileUtils.kIllegalArgumentResponse: |
378 _onError(new IllegalArgumentException()); | 382 _onError(new IllegalArgumentException()); |
379 break; | 383 break; |
380 case _FileUtils.kOSErrorResponse: | 384 case _FileUtils.kOSErrorResponse: |
381 _onError(new FileIOException(message, | 385 var err = new OSError(response[_FileUtils.kOSErrorResponseErrorCode], |
382 new OSError(response[2], response[1]))); | 386 response[_FileUtils.kOSErrorResponseMessage]); |
| 387 _onError(new FileIOException(message, err)); |
383 break; | 388 break; |
384 case _FileUtils.kFileClosedResponse: | 389 case _FileUtils.kFileClosedResponse: |
385 _onError(new FileIOException("File closed")); | 390 _onError(new FileIOException("File closed")); |
386 break; | 391 break; |
387 default: | 392 default: |
388 _onError(new Exception("Unknown error")); | 393 _onError(new Exception("Unknown error")); |
389 break; | 394 break; |
390 } | 395 } |
391 } | 396 } |
392 } | 397 } |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 String _name; | 1058 String _name; |
1054 int _id; | 1059 int _id; |
1055 int _pendingWrites = 0; | 1060 int _pendingWrites = 0; |
1056 | 1061 |
1057 SendPort _fileService; | 1062 SendPort _fileService; |
1058 | 1063 |
1059 Timer _noPendingWriteTimer; | 1064 Timer _noPendingWriteTimer; |
1060 | 1065 |
1061 Function _onNoPendingWrites; | 1066 Function _onNoPendingWrites; |
1062 } | 1067 } |
OLD | NEW |