Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Side by Side Diff: sdk/lib/convert/chunked_conversion.dart

Issue 203603008: Introduce class Sink<T>. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/convert/byte_conversion.dart ('k') | sdk/lib/convert/converter.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /** 9 /**
10 * A [ChunkedConversionSink] is used to transmit data more efficiently between 10 * A [ChunkedConversionSink] is used to transmit data more efficiently between
11 * two converters during chunked conversions. 11 * two converters during chunked conversions.
12 * 12 *
13 * The basic `ChunkedConversionSink` is just a [Sink], and converters should
14 * work with a plain `Sink`, but may work more efficiently with certain
15 * specialized types of `ChunkedConversionSink`.
16 *
13 * It is recommended that implementations of `ChunkedConversionSink` extends 17 * It is recommended that implementations of `ChunkedConversionSink` extends
14 * this class, to inherit any further methods that may be added to the class. 18 * this class, to inherit any further methods that may be added to the class.
15 */ 19 */
16 abstract class ChunkedConversionSink<T> { 20 abstract class ChunkedConversionSink<T> implements Sink<T> {
17 ChunkedConversionSink(); 21 ChunkedConversionSink();
18 factory ChunkedConversionSink.withCallback( 22 factory ChunkedConversionSink.withCallback(
19 void callback(List<T> accumulated)) = _SimpleCallbackSink; 23 void callback(List<T> accumulated)) = _SimpleCallbackSink;
20 24
21 /** 25 /**
22 * Adds chunked data to this sink. 26 * Adds chunked data to this sink.
23 * 27 *
24 * This method is also used when converters are used as [StreamTransformer]s. 28 * This method is also used when converters are used as [StreamTransformer]s.
25 */ 29 */
26 void add(T chunk); 30 void add(T chunk);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 final EventSink<T> _eventSink; 77 final EventSink<T> _eventSink;
74 78
75 /** 79 /**
76 * The input sink for new data. All data that is received with 80 * The input sink for new data. All data that is received with
77 * [handleData] is added into this sink. 81 * [handleData] is added into this sink.
78 */ 82 */
79 ChunkedConversionSink _chunkedSink; 83 ChunkedConversionSink _chunkedSink;
80 84
81 _ConverterStreamEventSink(Converter converter, EventSink<T> sink) 85 _ConverterStreamEventSink(Converter converter, EventSink<T> sink)
82 : this._eventSink = sink, 86 : this._eventSink = sink,
83 _chunkedSink = 87 _chunkedSink = converter.startChunkedConversion(sink);
84 converter.startChunkedConversion(new _EventSinkAdapter(sink));
85 88
86 void add(S o) => _chunkedSink.add(o); 89 void add(S o) => _chunkedSink.add(o);
87 void addError(Object error, [StackTrace stackTrace]) { 90 void addError(Object error, [StackTrace stackTrace]) {
88 _eventSink.addError(error, stackTrace); 91 _eventSink.addError(error, stackTrace);
89 } 92 }
90 void close() => _chunkedSink.close(); 93 void close() => _chunkedSink.close();
91 } 94 }
OLDNEW
« no previous file with comments | « sdk/lib/convert/byte_conversion.dart ('k') | sdk/lib/convert/converter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698