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.convert; | 5 part of dart.convert; |
6 | 6 |
7 typedef void _ChunkedConversionCallback<T>(T accumulated); | 7 typedef void _ChunkedConversionCallback<T>(T accumulated); |
8 | 8 |
9 /// This class is deprecated. Extend [Converter] directly. | 9 /// This class is deprecated. Extend [Converter] directly. |
10 @deprecated | 10 @deprecated |
11 abstract class ChunkedConverter<S, T, S2, T2> extends Converter<S, T> { | 11 abstract class ChunkedConverter<S, T, S2, T2> extends Converter<S, T> { |
12 const ChunkedConverter(): super(); | 12 const ChunkedConverter() : super(); |
13 | 13 |
14 dynamic bind(dynamic other) => super.bind(other); | 14 dynamic bind(dynamic other) => super.bind(other); |
15 dynamic startChunkedConversion(dynamic sink) => | 15 dynamic startChunkedConversion(dynamic sink) => |
16 super.startChunkedConversion(sink); | 16 super.startChunkedConversion(sink); |
17 } | 17 } |
18 | 18 |
19 /** | 19 /** |
20 * A [ChunkedConversionSink] is used to transmit data more efficiently between | 20 * A [ChunkedConversionSink] is used to transmit data more efficiently between |
21 * two converters during chunked conversions. | 21 * two converters during chunked conversions. |
22 * | 22 * |
(...skipping 30 matching lines...) Expand all Loading... |
53 * the chunks when the sink is closed. | 53 * the chunks when the sink is closed. |
54 * | 54 * |
55 * This class can be used to terminate a chunked conversion. | 55 * This class can be used to terminate a chunked conversion. |
56 */ | 56 */ |
57 class _SimpleCallbackSink<T> extends ChunkedConversionSink<T> { | 57 class _SimpleCallbackSink<T> extends ChunkedConversionSink<T> { |
58 final _ChunkedConversionCallback<List<T>> _callback; | 58 final _ChunkedConversionCallback<List<T>> _callback; |
59 final List<T> _accumulated = <T>[]; | 59 final List<T> _accumulated = <T>[]; |
60 | 60 |
61 _SimpleCallbackSink(this._callback); | 61 _SimpleCallbackSink(this._callback); |
62 | 62 |
63 void add(T chunk) { _accumulated.add(chunk); } | 63 void add(T chunk) { |
64 void close() { _callback(_accumulated); } | 64 _accumulated.add(chunk); |
| 65 } |
| 66 |
| 67 void close() { |
| 68 _callback(_accumulated); |
| 69 } |
65 } | 70 } |
66 | 71 |
67 /** | 72 /** |
68 * This class implements the logic for a chunked conversion as a | 73 * This class implements the logic for a chunked conversion as a |
69 * stream transformer. | 74 * stream transformer. |
70 * | 75 * |
71 * It is used as strategy in the [EventTransformStream]. | 76 * It is used as strategy in the [EventTransformStream]. |
72 * | 77 * |
73 * It also implements the [ChunkedConversionSink] interface so that it | 78 * It also implements the [ChunkedConversionSink] interface so that it |
74 * can be used as output sink in a chunked conversion. | 79 * can be used as output sink in a chunked conversion. |
75 */ | 80 */ |
76 class _ConverterStreamEventSink<S, T> implements EventSink<S> { | 81 class _ConverterStreamEventSink<S, T> implements EventSink<S> { |
77 /** The output sink for the converter. */ | 82 /** The output sink for the converter. */ |
78 final EventSink<T> _eventSink; | 83 final EventSink<T> _eventSink; |
79 | 84 |
80 /** | 85 /** |
81 * The input sink for new data. All data that is received with | 86 * The input sink for new data. All data that is received with |
82 * [handleData] is added into this sink. | 87 * [handleData] is added into this sink. |
83 */ | 88 */ |
84 final Sink<S> _chunkedSink; | 89 final Sink<S> _chunkedSink; |
85 | 90 |
86 _ConverterStreamEventSink( | 91 _ConverterStreamEventSink(Converter<S, T> converter, EventSink<T> sink) |
87 Converter<S, T> converter, | |
88 EventSink<T> sink) | |
89 : this._eventSink = sink, | 92 : this._eventSink = sink, |
90 _chunkedSink = converter.startChunkedConversion(sink); | 93 _chunkedSink = converter.startChunkedConversion(sink); |
91 | 94 |
92 void add(S o) { _chunkedSink.add(o); } | 95 void add(S o) { |
| 96 _chunkedSink.add(o); |
| 97 } |
| 98 |
93 void addError(Object error, [StackTrace stackTrace]) { | 99 void addError(Object error, [StackTrace stackTrace]) { |
94 _eventSink.addError(error, stackTrace); | 100 _eventSink.addError(error, stackTrace); |
95 } | 101 } |
96 void close() { _chunkedSink.close(); } | 102 |
| 103 void close() { |
| 104 _chunkedSink.close(); |
| 105 } |
97 } | 106 } |
OLD | NEW |