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 /** | 7 /** |
8 * String encodings. | 8 * String encodings. |
9 */ | 9 */ |
10 class Encoding { | 10 class Encoding { |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 final int _replacementChar; | 243 final int _replacementChar; |
244 | 244 |
245 _SingleByteDecoder(this._replacementChar); | 245 _SingleByteDecoder(this._replacementChar); |
246 | 246 |
247 Stream<String> bind(Stream<List<int>> stream) { | 247 Stream<String> bind(Stream<List<int>> stream) { |
248 _controller = new StreamController<String>( | 248 _controller = new StreamController<String>( |
249 onPauseStateChange: _pauseChanged, | 249 onPauseStateChange: _pauseChanged, |
250 onSubscriptionStateChange: _subscriptionChanged); | 250 onSubscriptionStateChange: _subscriptionChanged); |
251 _subscription = stream.listen( | 251 _subscription = stream.listen( |
252 (data) { | 252 (data) { |
253 var buffer = new List<int>.fixedLength(data.length); | 253 var buffer = new List<int>(data.length); |
254 for (int i = 0; i < data.length; i++) { | 254 for (int i = 0; i < data.length; i++) { |
255 int char = _decodeByte(data[i]); | 255 int char = _decodeByte(data[i]); |
256 if (char < 0) char = _replacementChar; | 256 if (char < 0) char = _replacementChar; |
257 buffer[i] = char; | 257 buffer[i] = char; |
258 } | 258 } |
259 _controller.add(new String.fromCharCodes(buffer)); | 259 _controller.add(new String.fromCharCodes(buffer)); |
260 }, | 260 }, |
261 onDone: _controller.close, | 261 onDone: _controller.close, |
262 onError: _controller.signalError); | 262 onError: _controller.signalError); |
263 return _controller.stream; | 263 return _controller.stream; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 _subscription.resume(); | 405 _subscription.resume(); |
406 } | 406 } |
407 } | 407 } |
408 | 408 |
409 void _subscriptionChanged() { | 409 void _subscriptionChanged() { |
410 if (!_controller.hasSubscribers) { | 410 if (!_controller.hasSubscribers) { |
411 _subscription.cancel(); | 411 _subscription.cancel(); |
412 } | 412 } |
413 } | 413 } |
414 } | 414 } |
OLD | NEW |