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 /** | 5 /** |
6 * An [OSError] object holds information about an error from the | 6 * An [OSError] object holds information about an error from the |
7 * operating system. | 7 * operating system. |
8 */ | 8 */ |
9 class OSError { | 9 class OSError { |
| 10 /** Constant used to indicate that no OS error code is available. */ |
10 static const int noErrorCode = -1; | 11 static const int noErrorCode = -1; |
11 | 12 |
| 13 /** Creates an OSError object from a message and an errorCode. */ |
12 const OSError([String this.message = "", int this.errorCode = noErrorCode]); | 14 const OSError([String this.message = "", int this.errorCode = noErrorCode]); |
13 | 15 |
| 16 /** Converts an OSError object to a string representation. */ |
14 String toString() { | 17 String toString() { |
15 StringBuffer sb = new StringBuffer(); | 18 StringBuffer sb = new StringBuffer(); |
16 sb.add("OS Error"); | 19 sb.add("OS Error"); |
17 if (!message.isEmpty()) { | 20 if (!message.isEmpty()) { |
18 sb.add(": "); | 21 sb.add(": "); |
19 sb.add(message); | 22 sb.add(message); |
20 if (errorCode != noErrorCode) { | 23 if (errorCode != noErrorCode) { |
21 sb.add(", errno = "); | 24 sb.add(", errno = "); |
22 sb.add(errorCode.toString()); | 25 sb.add(errorCode.toString()); |
23 } | 26 } |
24 } else if (errorCode != noErrorCode) { | 27 } else if (errorCode != noErrorCode) { |
25 sb.add(": errno = "); | 28 sb.add(": errno = "); |
26 sb.add(errorCode.toString()); | 29 sb.add(errorCode.toString()); |
27 } | 30 } |
28 return sb.toString(); | 31 return sb.toString(); |
29 } | 32 } |
30 | 33 |
31 /** | 34 /** |
32 * Error message supplied by the operating system. null if no message is | 35 * Error message supplied by the operating system. null if no message is |
33 * associated with the error. | 36 * associated with the error. |
34 */ | 37 */ |
35 final String message; | 38 final String message; |
36 | 39 |
37 /** | 40 /** |
38 * Error code supplied by the operating system. Will have the value | 41 * Error code supplied by the operating system. Will have the value |
39 * [noErrorCode] if there is no error code associated with the error. | 42 * [noErrorCode] if there is no error code associated with the error. |
40 */ | 43 */ |
41 final int errorCode; | 44 final int errorCode; |
42 } | 45 } |
| 46 |
| 47 |
| 48 // Check if a List is a builtin VM List type. Returns true |
| 49 // if the List is a builtin VM List type and false if it is |
| 50 // a user defined List type. |
| 51 // |
| 52 // TODO(5474): At this point it actually return false for |
| 53 // _GrowableObjectArrays because of serialization issues. |
| 54 bool _isBuiltinList(List buffer) native "Common_IsBuiltinList"; |
| 55 |
| 56 |
| 57 // Ensure that the input List can be serialized through a native port. |
| 58 // Only builtin Lists can be serialized through. If user-defined Lists |
| 59 // get here, the contents is copied to a Uint8List. This has the added |
| 60 // benefit that it is faster to access from the C code as well. |
| 61 List _ensureFastAndSerializableBuffer( |
| 62 List buffer, int offset, int bytes) { |
| 63 List outBuffer; |
| 64 int outOffset = offset; |
| 65 if (buffer is Uint8List || _isBuiltinList(buffer)) { |
| 66 outBuffer = buffer; |
| 67 } else { |
| 68 outBuffer = new Uint8List(bytes); |
| 69 outOffset = 0; |
| 70 int j = offset; |
| 71 for (int i = 0; i < bytes; i++) { |
| 72 int value = buffer[j]; |
| 73 if (value is! int) { |
| 74 throw new FileIOException( |
| 75 "List element is not an integer at index $j"); |
| 76 } |
| 77 outBuffer[i] = value; |
| 78 j++; |
| 79 } |
| 80 } |
| 81 return [outBuffer, outOffset]; |
| 82 } |
OLD | NEW |