| 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 part of dart.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 // Constants used when working with native ports. | 7 // Constants used when working with native ports. |
| 8 // These must match the constants in runtime/bin/dartutils.h class CObject. | 8 // These must match the constants in runtime/bin/dartutils.h class CObject. |
| 9 const int _SUCCESS_RESPONSE = 0; | 9 const int _SUCCESS_RESPONSE = 0; |
| 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; | 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 /** | 22 /** |
| 23 * Returns an Exception or an Error | 23 * Returns an Exception or an Error |
| 24 */ | 24 */ |
| 25 _exceptionFromResponse(response, String message, String path) { | 25 _exceptionFromResponse(response, String message, String path) { |
| 26 assert(_isErrorResponse(response)); | 26 assert(_isErrorResponse(response)); |
| 27 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { | 27 switch (response[_ERROR_RESPONSE_ERROR_TYPE]) { |
| 28 case _ILLEGAL_ARGUMENT_RESPONSE: | 28 case _ILLEGAL_ARGUMENT_RESPONSE: |
| 29 return new ArgumentError("$message: $path"); | 29 return new ArgumentError("$message: $path"); |
| 30 case _OSERROR_RESPONSE: | 30 case _OSERROR_RESPONSE: |
| 31 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], | 31 var err = new OSError(response[_OSERROR_RESPONSE_MESSAGE], |
| 32 response[_OSERROR_RESPONSE_ERROR_CODE]); | 32 response[_OSERROR_RESPONSE_ERROR_CODE]); |
| 33 return new FileSystemException(message, path, err); | 33 return new FileSystemException(message, path, err); |
| 34 case _FILE_CLOSED_RESPONSE: | 34 case _FILE_CLOSED_RESPONSE: |
| 35 return new FileSystemException("File closed", path); | 35 return new FileSystemException("File closed", path); |
| 36 default: | 36 default: |
| 37 return new Exception("Unknown error"); | 37 return new Exception("Unknown error"); |
| 38 } | 38 } |
| 39 } | 39 } |
| 40 | 40 |
| 41 /** | 41 /** |
| 42 * Base class for all IO related exceptions. | 42 * Base class for all IO related exceptions. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 66 final int errorCode; | 66 final int errorCode; |
| 67 | 67 |
| 68 /** Creates an OSError object from a message and an errorCode. */ | 68 /** Creates an OSError object from a message and an errorCode. */ |
| 69 const OSError([this.message = "", this.errorCode = noErrorCode]); | 69 const OSError([this.message = "", this.errorCode = noErrorCode]); |
| 70 | 70 |
| 71 /** Converts an OSError object to a string representation. */ | 71 /** Converts an OSError object to a string representation. */ |
| 72 String toString() { | 72 String toString() { |
| 73 StringBuffer sb = new StringBuffer(); | 73 StringBuffer sb = new StringBuffer(); |
| 74 sb.write("OS Error"); | 74 sb.write("OS Error"); |
| 75 if (!message.isEmpty) { | 75 if (!message.isEmpty) { |
| 76 sb..write(": ") | 76 sb..write(": ")..write(message); |
| 77 ..write(message); | |
| 78 if (errorCode != noErrorCode) { | 77 if (errorCode != noErrorCode) { |
| 79 sb..write(", errno = ") | 78 sb..write(", errno = ")..write(errorCode.toString()); |
| 80 ..write(errorCode.toString()); | |
| 81 } | 79 } |
| 82 } else if (errorCode != noErrorCode) { | 80 } else if (errorCode != noErrorCode) { |
| 83 sb..write(": errno = ") | 81 sb..write(": errno = ")..write(errorCode.toString()); |
| 84 ..write(errorCode.toString()); | |
| 85 } | 82 } |
| 86 return sb.toString(); | 83 return sb.toString(); |
| 87 } | 84 } |
| 88 } | 85 } |
| 89 | 86 |
| 90 | |
| 91 // Object for holding a buffer and an offset. | 87 // Object for holding a buffer and an offset. |
| 92 class _BufferAndStart { | 88 class _BufferAndStart { |
| 93 List<int> buffer; | 89 List<int> buffer; |
| 94 int start; | 90 int start; |
| 95 _BufferAndStart(this.buffer, this.start); | 91 _BufferAndStart(this.buffer, this.start); |
| 96 } | 92 } |
| 97 | 93 |
| 98 // Ensure that the input List can be serialized through a native port. | 94 // Ensure that the input List can be serialized through a native port. |
| 99 // Only Int8List and Uint8List Lists are serialized directly. | 95 // Only Int8List and Uint8List Lists are serialized directly. |
| 100 // All other lists are first copied into a Uint8List. This has the added | 96 // All other lists are first copied into a Uint8List. This has the added |
| (...skipping 10 matching lines...) Expand all Loading... |
| 111 int value = buffer[j]; | 107 int value = buffer[j]; |
| 112 if (value is! int) { | 108 if (value is! int) { |
| 113 throw new ArgumentError("List element is not an integer at index $j"); | 109 throw new ArgumentError("List element is not an integer at index $j"); |
| 114 } | 110 } |
| 115 newBuffer[i] = value; | 111 newBuffer[i] = value; |
| 116 j++; | 112 j++; |
| 117 } | 113 } |
| 118 return new _BufferAndStart(newBuffer, 0); | 114 return new _BufferAndStart(newBuffer, 0); |
| 119 } | 115 } |
| 120 | 116 |
| 121 | |
| 122 class _IOCrypto { | 117 class _IOCrypto { |
| 123 external static Uint8List getRandomBytes(int count); | 118 external static Uint8List getRandomBytes(int count); |
| 124 } | 119 } |
| OLD | NEW |