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 /** | 7 /** |
8 * A [Converter] converts data from one representation into another. | 8 * A [Converter] converts data from one representation into another. |
9 * | 9 * |
10 * It is recommended that implementations of `Converter` extend this class, | 10 * It is recommended that implementations of `Converter` extend this class, |
(...skipping 23 matching lines...) Expand all Loading... |
34 * The returned sink serves as input for the long-running conversion. The | 34 * The returned sink serves as input for the long-running conversion. The |
35 * given [sink] serves as output. | 35 * given [sink] serves as output. |
36 */ | 36 */ |
37 Sink/*<S>*/ startChunkedConversion(Sink/*<T>*/ sink) { | 37 Sink/*<S>*/ startChunkedConversion(Sink/*<T>*/ sink) { |
38 throw new UnsupportedError( | 38 throw new UnsupportedError( |
39 "This converter does not support chunked conversions: $this"); | 39 "This converter does not support chunked conversions: $this"); |
40 } | 40 } |
41 | 41 |
42 Stream<T> bind(Stream<S> stream) { | 42 Stream<T> bind(Stream<S> stream) { |
43 return new Stream<T>.eventTransformed( | 43 return new Stream<T>.eventTransformed( |
44 stream, | 44 stream, (EventSink sink) => new _ConverterStreamEventSink(this, sink)); |
45 (EventSink sink) => new _ConverterStreamEventSink(this, sink)); | |
46 } | 45 } |
47 } | 46 } |
48 | 47 |
49 /** | 48 /** |
50 * Fuses two converters. | 49 * Fuses two converters. |
51 * | 50 * |
52 * For a non-chunked conversion converts the input in sequence. | 51 * For a non-chunked conversion converts the input in sequence. |
53 */ | 52 */ |
54 class _FusedConverter<S, M, T> extends Converter<S, T> | 53 class _FusedConverter<S, M, T> extends Converter<S, T> |
55 implements ChunkedConverter<S, T, S, T> { | 54 implements ChunkedConverter<S, T, S, T> { |
56 final Converter<S, M> _first; | 55 final Converter<S, M> _first; |
57 final Converter<M, T> _second; | 56 final Converter<M, T> _second; |
58 | 57 |
59 _FusedConverter(this._first, this._second); | 58 _FusedConverter(this._first, this._second); |
60 | 59 |
61 T convert(S input) => _second.convert(_first.convert(input)); | 60 T convert(S input) => _second.convert(_first.convert(input)); |
62 | 61 |
63 Sink/*<S>*/ startChunkedConversion(Sink/*<T>*/ sink) { | 62 Sink/*<S>*/ startChunkedConversion(Sink/*<T>*/ sink) { |
64 return _first.startChunkedConversion(_second.startChunkedConversion(sink)); | 63 return _first.startChunkedConversion(_second.startChunkedConversion(sink)); |
65 } | 64 } |
66 } | 65 } |
OLD | NEW |