| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library channel; | 5 library channel; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * Instances of [_JsonStreamDecoder] convert JSON strings to JSON maps | 173 * Instances of [_JsonStreamDecoder] convert JSON strings to JSON maps |
| 174 */ | 174 */ |
| 175 class _JsonStreamDecoder extends Converter<String, Map> { | 175 class _JsonStreamDecoder extends Converter<String, Map> { |
| 176 | 176 |
| 177 @override | 177 @override |
| 178 Map convert(String text) => JSON.decode(text); | 178 Map convert(String text) => JSON.decode(text); |
| 179 | 179 |
| 180 @override | 180 @override |
| 181 ChunkedConversionSink startChunkedConversion(ChunkedConversionSink sink) => | 181 ChunkedConversionSink startChunkedConversion(Sink sink) => |
| 182 new _ChannelChunkSink<String, Map>(this, sink); | 182 new _ChannelChunkSink<String, Map>(this, sink); |
| 183 } | 183 } |
| 184 | 184 |
| 185 /** | 185 /** |
| 186 * Instances of [_ResponseConverter] convert JSON maps to [Response]s. | 186 * Instances of [_ResponseConverter] convert JSON maps to [Response]s. |
| 187 */ | 187 */ |
| 188 class _ResponseConverter extends Converter<Map, Response> { | 188 class _ResponseConverter extends Converter<Map, Response> { |
| 189 | 189 |
| 190 @override | 190 @override |
| 191 Response convert(Map json) => new Response.fromJson(json); | 191 Response convert(Map json) => new Response.fromJson(json); |
| 192 | 192 |
| 193 @override | 193 @override |
| 194 ChunkedConversionSink startChunkedConversion(ChunkedConversionSink sink) => | 194 ChunkedConversionSink startChunkedConversion(Sink sink) => |
| 195 new _ChannelChunkSink<Map, Response>(this, sink); | 195 new _ChannelChunkSink<Map, Response>(this, sink); |
| 196 } | 196 } |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Instances of [_NotificationConverter] convert JSON maps to [Notification]s. | 199 * Instances of [_NotificationConverter] convert JSON maps to [Notification]s. |
| 200 */ | 200 */ |
| 201 class _NotificationConverter extends Converter<Map, Notification> { | 201 class _NotificationConverter extends Converter<Map, Notification> { |
| 202 | 202 |
| 203 @override | 203 @override |
| 204 Notification convert(Map json) => new Notification.fromJson(json); | 204 Notification convert(Map json) => new Notification.fromJson(json); |
| 205 | 205 |
| 206 @override | 206 @override |
| 207 ChunkedConversionSink startChunkedConversion(ChunkedConversionSink sink) => | 207 ChunkedConversionSink startChunkedConversion(Sink sink) => |
| 208 new _ChannelChunkSink<Map, Notification>(this, sink); | 208 new _ChannelChunkSink<Map, Notification>(this, sink); |
| 209 } | 209 } |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * A [_ChannelChunkSink] uses a [Convter] to translate chunks. | 212 * A [_ChannelChunkSink] uses a [Converter] to translate chunks. |
| 213 */ | 213 */ |
| 214 class _ChannelChunkSink<S, T> extends ChunkedConversionSink<S> { | 214 class _ChannelChunkSink<S, T> extends ChunkedConversionSink<S> { |
| 215 final Converter<S, T> _converter; | 215 final Converter<S, T> _converter; |
| 216 final ChunkedConversionSink _chunkedSink; | 216 final Sink _sink; |
| 217 | 217 |
| 218 _ChannelChunkSink(this._converter, this._chunkedSink); | 218 _ChannelChunkSink(this._converter, this._sink); |
| 219 | 219 |
| 220 @override | 220 @override |
| 221 void add(S chunk) { | 221 void add(S chunk) { |
| 222 var convertedChunk = _converter.convert(chunk); | 222 var convertedChunk = _converter.convert(chunk); |
| 223 if (convertedChunk != null) { | 223 if (convertedChunk != null) { |
| 224 _chunkedSink.add(convertedChunk); | 224 _sink.add(convertedChunk); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 @override | 228 @override |
| 229 void close() => _chunkedSink.close(); | 229 void close() => _sink.close(); |
| 230 } | 230 } |
| OLD | NEW |