Chromium Code Reviews| 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.io; | 5 part of dart.io; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Helper class to wrap a [StreamConsumer<List<int>>] and provide | 8 * Helper class to wrap a [StreamConsumer<List<int>>] and provide |
| 9 * utility functions for writing to the StreamConsumer directly. The | 9 * utility functions for writing to the StreamConsumer directly. The |
| 10 * [IOSink] buffers the input given by all [StringSink] methods and will delay | 10 * [IOSink] buffers the input given by all [StringSink] methods and will delay |
| 11 * a [addStream] until the buffer is flushed. | 11 * a [addStream] until the buffer is flushed. |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
a -> an
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 12 * | 12 * |
| 13 * When the [IOSink] is bound to a stream (through [addStream]) any call | 13 * When the [IOSink] is bound to a stream (through [addStream]) any call |
| 14 * to the [IOSink] will throw a [StateError]. When the [addStream] completes, | 14 * to the [IOSink] will throw a [StateError]. When the [addStream] completes, |
| 15 * the [IOSink] will again be open for all calls. | 15 * the [IOSink] will again be open for all calls. |
| 16 * | 16 * |
| 17 * If data is added to the [IOSink] after the sink is closed, the data will be | 17 * If data is added to the [IOSink] after the sink is closed, the data will be |
| 18 * ignored. Use the [done] future to be notified when the [IOSink] is closed. | 18 * ignored. Use the [done] future to be notified when the [IOSink] is closed. |
| 19 */ | 19 */ |
| 20 abstract class IOSink implements StreamSink<List<int>>, StringSink { | 20 abstract class IOSink implements StreamSink<List<int>>, StringSink { |
| 21 factory IOSink(StreamConsumer<List<int>> target, | 21 factory IOSink(StreamConsumer<List<int>> target, |
| 22 {Encoding encoding: UTF8}) | 22 {Encoding encoding: UTF8}) |
| 23 => new _IOSinkImpl(target, encoding); | 23 => new _IOSinkImpl(target, encoding); |
| 24 | 24 |
| 25 /** | 25 /** |
| 26 * The [Encoding] used when writing strings. Depending on the | 26 * The [Encoding] used when writing strings. Depending on the |
| 27 * underlying consumer this property might be mutable. | 27 * underlying consumer this property might be mutable. |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
Make it a getter here, and add a setter only where
Anders Johnsen
2014/03/18 12:30:57
No, can't do :)
| |
| 28 */ | 28 */ |
| 29 Encoding encoding; | 29 Encoding encoding; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Writes the bytes uninterpreted to the consumer. While the call is | 32 * Writes the bytes uninterpreted to the consumer. |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
Adds [data] to the target consumer, ignoring [enco
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 33 * synchronous, the data may be buffered until the underlying resource is | 33 * |
| 34 * ready. The data should not be modified after a call to [add]. | 34 * This function can not be called, when a stream is currently being added by |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
can not -> must not
remove comma
added by -> added
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 35 * [addStream]. | |
| 36 * | |
| 37 * This operation is non-blocking. See [flush] or [done] for how to get any | |
| 38 * errors that this call may have generated. The data should not be modified | |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
that this call may have generated -> generated by
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 39 * after a call to [add]. | |
| 35 */ | 40 */ |
| 36 void add(List<int> data); | 41 void add(List<int> data); |
| 37 | 42 |
| 38 /** | 43 /** |
| 44 * Converts [obj] to a String by invoking [Object.toString] and | |
| 45 * [add]s the result to the consumer. | |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
adds the result -> adds the encoding of the result
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 46 * | |
| 47 * This operation is non-blocking. See [flush] or [done] for how to get any | |
| 48 * errors that this call may have generated. | |
| 49 */ | |
| 50 void write(Object obj); | |
| 51 | |
| 52 /** | |
| 53 * Iterates over the given [objects] and [write]s them in sequence. | |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
If [separator] is provided, a `write` with the `se
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 54 * | |
| 55 * This operation is non-blocking. See [flush] or [done] for how to get any | |
| 56 * errors that this call may have generated. | |
| 57 */ | |
| 58 void writeAll(Iterable objects, [String separator = ""]); | |
| 59 | |
| 60 /** | |
| 61 * Converts [obj] to a String by invoking [Object.toString] and | |
| 62 * adds the result to `this`, followed by a newline. | |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
adds -> writes
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 63 * | |
| 64 * This operation is non-blocking. See [flush] or [done] for how to get any | |
| 65 * errors that this call may have generated. | |
| 66 */ | |
| 67 void writeln([Object obj = ""]); | |
| 68 | |
| 69 /** | |
| 70 * Writes the [charCode] to `this`. | |
| 71 * | |
| 72 * This method is equivalent to `write(new String.fromCharCode(charCode))`. | |
| 73 * | |
| 74 * This operation is non-blocking. See [flush] or [done] for how to get any | |
| 75 * errors that this call may have generated. | |
| 76 */ | |
| 77 void writeCharCode(int charCode); | |
| 78 | |
| 79 /** | |
| 39 * Writes an error to the consumer. | 80 * Writes an error to the consumer. |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
Passes the error to the target consumer as an erro
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 81 * | |
| 82 * This function can not be called, when a stream is currently being added by | |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
can not -> must not
remove comma.
added by -> adde
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 83 * [addStream]. | |
| 84 * | |
| 85 * This operation is non-blocking. See [flush] or [done] for how to get any | |
| 86 * errors that this call may have generated. | |
| 40 */ | 87 */ |
| 41 void addError(error, [StackTrace stackTrace]); | 88 void addError(error, [StackTrace stackTrace]); |
| 42 | 89 |
| 43 /** | 90 /** |
| 44 * Adds all elements of the given [stream] to `this`. | 91 * Adds all elements of the given [stream] to `this`. |
| 45 */ | 92 */ |
| 46 Future addStream(Stream<List<int>> stream); | 93 Future addStream(Stream<List<int>> stream); |
| 47 | 94 |
| 48 /** | 95 /** |
| 49 * Returns a [Future] that completes once all buffered data is accepted by the | 96 * Returns a [Future] that completes once all buffered data is accepted by the |
| 50 * to underlying [StreamConsumer]. | 97 * to underlying [StreamConsumer]. |
| 51 * | 98 * |
| 52 * It's an error to call this method, while an [addStream] is incomplete. | 99 * It's an error to call this method, while an [addStream] is incomplete. |
| 53 * | 100 * |
| 54 * NOTE: This is not necessarily the same as the data being flushed by the | 101 * NOTE: This is not necessarily the same as the data being flushed by the |
| 55 * operating system. | 102 * operating system. |
| 56 */ | 103 */ |
| 57 Future flush(); | 104 Future flush(); |
| 58 | 105 |
| 59 /** | 106 /** |
| 60 * Close the target. | 107 * Close the consumer. |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
Close the target consumer.
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 61 */ | 108 */ |
| 62 Future close(); | 109 Future close(); |
| 63 | 110 |
| 64 /** | 111 /** |
| 65 * Get a future that will complete when all synchronous have completed, or an | 112 * Get a future that will complete when the consumer is closed, or an |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
is closed -> closes
or an error happened -> or whe
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 66 * error happened. This future is identical to the future returned from close. | 113 * error happened. This future is identical to the future returned from |
|
Lasse Reichstein Nielsen
2014/03/18 11:57:14
returned from -> returned by.
Anders Johnsen
2014/03/18 12:30:57
Done.
| |
| 114 * [close]. | |
| 67 */ | 115 */ |
| 68 Future get done; | 116 Future get done; |
| 69 } | 117 } |
| 70 | 118 |
| 71 class _StreamSinkImpl<T> implements StreamSink<T> { | 119 class _StreamSinkImpl<T> implements StreamSink<T> { |
| 72 final StreamConsumer<T> _target; | 120 final StreamConsumer<T> _target; |
| 73 Completer _doneCompleter = new Completer(); | 121 Completer _doneCompleter = new Completer(); |
| 74 Future _doneFuture; | 122 Future _doneFuture; |
| 75 StreamController<T> _controllerInstance; | 123 StreamController<T> _controllerInstance; |
| 76 Completer _controllerCompleter; | 124 Completer _controllerCompleter; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 | 298 |
| 251 void writeln([Object obj = ""]) { | 299 void writeln([Object obj = ""]) { |
| 252 write(obj); | 300 write(obj); |
| 253 write("\n"); | 301 write("\n"); |
| 254 } | 302 } |
| 255 | 303 |
| 256 void writeCharCode(int charCode) { | 304 void writeCharCode(int charCode) { |
| 257 write(new String.fromCharCode(charCode)); | 305 write(new String.fromCharCode(charCode)); |
| 258 } | 306 } |
| 259 } | 307 } |
| OLD | NEW |