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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 return encoded; | 54 return encoded; |
55 } | 55 } |
56 | 56 |
57 /** | 57 /** |
58 * Starts a chunked conversion. | 58 * Starts a chunked conversion. |
59 */ | 59 */ |
60 StringConversionSink startChunkedConversion(Sink<List<int>> sink) { | 60 StringConversionSink startChunkedConversion(Sink<List<int>> sink) { |
61 return new _WindowsCodePageEncoderSink(sink); | 61 return new _WindowsCodePageEncoderSink(sink); |
62 } | 62 } |
63 | 63 |
| 64 // Override the base-class' bind, to provide a better type. |
| 65 Stream<List<int>> bind(Stream<String> stream) => super.bind(stream); |
| 66 |
64 external static List<int> _encodeString(String string); | 67 external static List<int> _encodeString(String string); |
65 } | 68 } |
66 | 69 |
67 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { | 70 class _WindowsCodePageEncoderSink extends StringConversionSinkBase { |
68 // TODO(floitsch): provide more efficient conversions when the input is | 71 // TODO(floitsch): provide more efficient conversions when the input is |
69 // not a String. | 72 // not a String. |
70 | 73 |
71 final Sink<List<int>> _sink; | 74 final Sink<List<int>> _sink; |
72 | 75 |
73 _WindowsCodePageEncoderSink(this._sink); | 76 _WindowsCodePageEncoderSink(this._sink); |
(...skipping 28 matching lines...) Expand all Loading... |
102 return _decodeBytes(input); | 105 return _decodeBytes(input); |
103 } | 106 } |
104 | 107 |
105 /** | 108 /** |
106 * Starts a chunked conversion. | 109 * Starts a chunked conversion. |
107 */ | 110 */ |
108 ByteConversionSink startChunkedConversion(Sink<String> sink) { | 111 ByteConversionSink startChunkedConversion(Sink<String> sink) { |
109 return new _WindowsCodePageDecoderSink(sink); | 112 return new _WindowsCodePageDecoderSink(sink); |
110 } | 113 } |
111 | 114 |
| 115 // Override the base-class' bind, to provide a better type. |
| 116 Stream<String> bind(Stream<List<int>> stream) => super.bind(stream); |
| 117 |
112 external static String _decodeBytes(List<int> bytes); | 118 external static String _decodeBytes(List<int> bytes); |
113 } | 119 } |
114 | 120 |
115 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { | 121 class _WindowsCodePageDecoderSink extends ByteConversionSinkBase { |
116 // TODO(floitsch): provide more efficient conversions when the input is | 122 // TODO(floitsch): provide more efficient conversions when the input is |
117 // a slice. | 123 // a slice. |
118 | 124 |
119 final Sink<String> _sink; | 125 final Sink<String> _sink; |
120 | 126 |
121 _WindowsCodePageDecoderSink(this._sink); | 127 _WindowsCodePageDecoderSink(this._sink); |
122 | 128 |
123 void close() { | 129 void close() { |
124 _sink.close(); | 130 _sink.close(); |
125 } | 131 } |
126 | 132 |
127 void add(List<int> bytes) { | 133 void add(List<int> bytes) { |
128 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); | 134 _sink.add(_WindowsCodePageDecoder._decodeBytes(bytes)); |
129 } | 135 } |
130 } | 136 } |
OLD | NEW |