| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// The current system encoding. | 7 /// The current system encoding. |
| 8 /// | 8 /// |
| 9 /// This us used for converting from bytes to/from String when | 9 /// This us used for converting from bytes to/from String when |
| 10 /// communicating on stdin, stdout and stderr. | 10 /// communicating on stdin, stdout and stderr. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 return encoded; | 55 return encoded; |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Starts a chunked conversion. | 59 * Starts a chunked conversion. |
| 60 */ | 60 */ |
| 61 StringConversionSink startChunkedConversion(Sink<List<int>> sink) { | 61 StringConversionSink startChunkedConversion(Sink<List<int>> sink) { |
| 62 return new _WindowsCodePageEncoderSink(sink); | 62 return new _WindowsCodePageEncoderSink(sink); |
| 63 } | 63 } |
| 64 | 64 |
| 65 // Override the base-class' bind, to provide a better type. | |
| 66 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream); | |
| 67 | |
| 68 external static List<int> _encodeString(String string); | 65 external static List<int> _encodeString(String string); |
| 69 } | 66 } |
| 70 | 67 |
| 71 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { | 68 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { |
| 72 // TODO(floitsch): provide more efficient conversions when the input is | 69 // TODO(floitsch): provide more efficient conversions when the input is |
| 73 // not a String. | 70 // not a String. |
| 74 | 71 |
| 75 final Sink<List<int>> _sink; | 72 final Sink<List<int>> _sink; |
| 76 | 73 |
| 77 _WindowsCodePageEncoderSink(this._sink); | 74 _WindowsCodePageEncoderSink(this._sink); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 107 return _decodeBytes(input); | 104 return _decodeBytes(input); |
| 108 } | 105 } |
| 109 | 106 |
| 110 /** | 107 /** |
| 111 * Starts a chunked conversion. | 108 * Starts a chunked conversion. |
| 112 */ | 109 */ |
| 113 ByteConversionSink startChunkedConversion(Sink<String> sink) { | 110 ByteConversionSink startChunkedConversion(Sink<String> sink) { |
| 114 return new _WindowsCodePageDecoderSink(sink); | 111 return new _WindowsCodePageDecoderSink(sink); |
| 115 } | 112 } |
| 116 | 113 |
| 117 // Override the base-class' bind, to provide a better type. | |
| 118 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); | |
| 119 | |
| 120 external static String _decodeBytes(List<int> bytes); | 114 external static String _decodeBytes(List<int> bytes); |
| 121 } | 115 } |
| 122 | 116 |
| 123 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { | 117 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { |
| 124 // TODO(floitsch): provide more efficient conversions when the input is | 118 // TODO(floitsch): provide more efficient conversions when the input is |
| 125 // a slice. | 119 // a slice. |
| 126 | 120 |
| 127 final Sink<String> _sink; | 121 final Sink<String> _sink; |
| 128 | 122 |
| 129 _WindowsCodePageDecoderSink(this._sink); | 123 _WindowsCodePageDecoderSink(this._sink); |
| 130 | 124 |
| 131 void close() { | 125 void close() { |
| 132 _sink.close(); | 126 _sink.close(); |
| 133 } | 127 } |
| 134 | 128 |
| 135 void add(List<int> bytes) { | 129 void add(List<int> bytes) { |
| 136 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); | 130 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); |
| 137 } | 131 } |
| 138 } | 132 } |
| OLD | NEW |