| 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 * This class provides an interface for converters to | 8 * This class provides an interface for converters to |
| 9 * efficiently transmit String data. | 9 * efficiently transmit String data. |
| 10 * | 10 * |
| 11 * Instead of limiting the interface to one non-chunked String it accepts | 11 * Instead of limiting the interface to one non-chunked String it accepts |
| 12 * partial strings or can be transformed into a byte sink that | 12 * partial strings or can be transformed into a byte sink that |
| 13 * accepts UTF-8 code units. | 13 * accepts UTF-8 code units. |
| 14 * | 14 * |
| 15 * This abstract class will likely get more methods over time. Implementers are | 15 * This abstract class will likely get more methods over time. Implementers are |
| 16 * urged to extend [StringConversionSinkBase] or to mix in | 16 * urged to extend [StringConversionSinkBase] or to mix in |
| 17 * [StringConversionSinkMixin], to ensure that their class covers the newly | 17 * [StringConversionSinkMixin], to ensure that their class covers the newly |
| 18 * added methods. | 18 * added methods. |
| 19 */ | 19 */ |
| 20 abstract class StringConversionSink | 20 abstract class StringConversionSink extends ChunkedConversionSink<String> { |
| 21 extends ChunkedConversionSink<String> { | |
| 22 StringConversionSink(); | 21 StringConversionSink(); |
| 23 factory StringConversionSink.withCallback(void callback(String accumulated)) | 22 factory StringConversionSink.withCallback(void callback(String accumulated)) |
| 24 = _StringCallbackSink; | 23 = _StringCallbackSink; |
| 25 factory StringConversionSink.from(Sink<String> sink) | 24 factory StringConversionSink.from(Sink<String> sink) |
| 26 = _StringAdapterSink; | 25 = _StringAdapterSink; |
| 27 | 26 |
| 28 /** | 27 /** |
| 29 * Creates a new instance wrapping the given [sink]. | 28 * Creates a new instance wrapping the given [sink]. |
| 30 * | 29 * |
| 31 * Every string that is added to the returned instance is forwarded to | 30 * Every string that is added to the returned instance is forwarded to |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 _decoder.convert(chunk, startIndex, endIndex); | 333 _decoder.convert(chunk, startIndex, endIndex); |
| 335 if (_buffer.isNotEmpty) { | 334 if (_buffer.isNotEmpty) { |
| 336 String accumulated = _buffer.toString(); | 335 String accumulated = _buffer.toString(); |
| 337 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); | 336 _chunkedSink.addSlice(accumulated, 0, accumulated.length, isLast); |
| 338 _buffer.clear(); | 337 _buffer.clear(); |
| 339 return; | 338 return; |
| 340 } | 339 } |
| 341 if (isLast) close(); | 340 if (isLast) close(); |
| 342 } | 341 } |
| 343 } | 342 } |
| OLD | NEW |