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

Unified Diff: sdk/lib/io/io_sink.dart

Issue 12389050: Remane io_stream_consumer.dart to io_sink and move out all implementation from IOSink to _IOSinkImp… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Make _DetachedSocket pass dart-analyzer. Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/io/io.dart ('k') | sdk/lib/io/io_stream_consumer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/io_sink.dart
diff --git a/sdk/lib/io/io_stream_consumer.dart b/sdk/lib/io/io_sink.dart
similarity index 89%
rename from sdk/lib/io/io_stream_consumer.dart
rename to sdk/lib/io/io_sink.dart
index 9ae639e570af3428ec9c8c86920afda6339b9d3a..ace6f92f696f5e1e56ae1c01f18cf24d8269aed7 100644
--- a/sdk/lib/io/io_stream_consumer.dart
+++ b/sdk/lib/io/io_sink.dart
@@ -14,7 +14,44 @@ part of dart.io;
* or [addStream]) any call to the [IOSink] will throw a
* [StateError].
*/
-class IOSink<T> implements StreamConsumer<List<int>, T> {
+abstract class IOSink<T> implements StreamConsumer<List<int>, T> {
+ factory IOSink(StreamConsumer<List<int>, T> target)
+ => new _IOSinkImpl(target);
+
+ /**
+ * Provide functionality for piping to the [IOSink].
+ */
+ Future<T> consume(Stream<List<int>> stream);
+
+ /**
+ * Like [consume], but will not close the target when done.
+ */
+ Future<T> addStream(Stream<List<int>> stream);
+
+ /**
+ * Write a list of bytes to the target.
+ */
+ void add(List<int> data);
+
+ /**
+ * Write a String to the target.
+ */
+ void addString(String string, [Encoding encoding = Encoding.UTF_8]);
+
+ /**
+ * Close the target.
+ */
+ void close();
+
+ /**
+ * Get future that will complete when all data has been written to
+ * the IOSink and it has been closed.
+ */
+ Future<T> get done;
+}
+
+
+class _IOSinkImpl<T> implements IOSink<T> {
final StreamConsumer<List<int>, T> _target;
StreamController<List<int>> _controllerInstance;
@@ -22,11 +59,8 @@ class IOSink<T> implements StreamConsumer<List<int>, T> {
StreamSubscription<List<int>> _bindSubscription;
bool _paused = true;
- IOSink(StreamConsumer<List<int>, T> target) : _target = target;
+ _IOSinkImpl(StreamConsumer<List<int>, T> target) : _target = target;
- /**
- * Provide functionality for piping to the [IOSink].
- */
Future<T> consume(Stream<List<int>> stream) {
if (_isBound) {
throw new StateError("IOSink is already bound to a stream");
@@ -34,9 +68,6 @@ class IOSink<T> implements StreamConsumer<List<int>, T> {
return _fillFromStream(stream);
}
- /**
- * Like [consume], but will not close the target when done.
- */
Future<T> addStream(Stream<List<int>> stream) {
if (_isBound) {
throw new StateError("IOSink is already bound to a stream");
@@ -44,9 +75,6 @@ class IOSink<T> implements StreamConsumer<List<int>, T> {
return _fillFromStream(stream, unbind: true);
}
- /**
- * Write a list of bytes to the target.
- */
void add(List<int> data) {
if (_isBound) {
throw new StateError("IOSink is already bound to a stream");
@@ -54,16 +82,10 @@ class IOSink<T> implements StreamConsumer<List<int>, T> {
_controller.add(data);
}
- /**
- * Write a String to the target.
- */
void addString(String string, [Encoding encoding = Encoding.UTF_8]) {
add(_encodeString(string, encoding));
}
- /**
- * Close the target.
- */
void close() {
if (_isBound) {
throw new StateError("IOSink is already bound to a stream");
@@ -71,10 +93,6 @@ class IOSink<T> implements StreamConsumer<List<int>, T> {
_controller.close();
}
- /**
- * Get future that will complete when all data has been written to
- * the IOSink and it has been closed.
- */
Future<T> get done {
_controller;
return _pipeFuture.then((_) => this);
« no previous file with comments | « sdk/lib/io/io.dart ('k') | sdk/lib/io/io_stream_consumer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698