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 |
(...skipping 20 matching lines...) Expand all Loading... |
31 /** | 31 /** |
32 * Writes the bytes uninterpreted to the consumer. While the call is | 32 * Writes the bytes uninterpreted to the consumer. While the call is |
33 * synchronous, the data may be buffered until the underlying resource is | 33 * synchronous, the data may be buffered until the underlying resource is |
34 * ready. The data should not be modified after a call to [add]. | 34 * ready. The data should not be modified after a call to [add]. |
35 */ | 35 */ |
36 void add(List<int> data); | 36 void add(List<int> data); |
37 | 37 |
38 /** | 38 /** |
39 * Writes an error to the consumer. | 39 * Writes an error to the consumer. |
40 */ | 40 */ |
41 void addError(error); | 41 void addError(error, [StackTrace stackTrace]); |
42 | 42 |
43 /** | 43 /** |
44 * Adds all elements of the given [stream] to `this`. | 44 * Adds all elements of the given [stream] to `this`. |
45 */ | 45 */ |
46 Future addStream(Stream<List<int>> stream); | 46 Future addStream(Stream<List<int>> stream); |
47 | 47 |
48 /** | 48 /** |
49 * Close the target. | 49 * Close the target. |
50 */ | 50 */ |
51 Future close(); | 51 Future close(); |
(...skipping 17 matching lines...) Expand all Loading... |
69 | 69 |
70 _StreamSinkImpl(StreamConsumer<T> this._target) { | 70 _StreamSinkImpl(StreamConsumer<T> this._target) { |
71 _doneFuture = _doneCompleter.future; | 71 _doneFuture = _doneCompleter.future; |
72 } | 72 } |
73 | 73 |
74 void add(T data) { | 74 void add(T data) { |
75 if (_isClosed) return; | 75 if (_isClosed) return; |
76 _controller.add(data); | 76 _controller.add(data); |
77 } | 77 } |
78 | 78 |
79 void addError(error) { | 79 void addError(error, [StackTrace stackTrace]) { |
80 _controller.addError(error); | 80 _controller.addError(error, stackTrace); |
81 } | 81 } |
82 | 82 |
83 Future addStream(Stream<T> stream) { | 83 Future addStream(Stream<T> stream) { |
84 if (_isBound) { | 84 if (_isBound) { |
85 throw new StateError("StreamSink is already bound to a stream"); | 85 throw new StateError("StreamSink is already bound to a stream"); |
86 } | 86 } |
87 _isBound = true; | 87 _isBound = true; |
88 if (_hasError) return done; | 88 if (_hasError) return done; |
89 // Wait for any sync operations to complete. | 89 // Wait for any sync operations to complete. |
90 Future targetAddStream() { | 90 Future targetAddStream() { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 225 |
226 void writeln([Object obj = ""]) { | 226 void writeln([Object obj = ""]) { |
227 write(obj); | 227 write(obj); |
228 write("\n"); | 228 write("\n"); |
229 } | 229 } |
230 | 230 |
231 void writeCharCode(int charCode) { | 231 void writeCharCode(int charCode) { |
232 write(new String.fromCharCode(charCode)); | 232 write(new String.fromCharCode(charCode)); |
233 } | 233 } |
234 } | 234 } |
OLD | NEW |