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 * A combined byte and text output. | 8 * A combined byte and text output. |
9 * | 9 * |
10 * An [IOSink] combines a [StreamSink] of bytes with a [StringSink], | 10 * An [IOSink] combines a [StreamSink] of bytes with a [StringSink], |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 final StreamConsumer<T> _target; | 139 final StreamConsumer<T> _target; |
140 final Completer _doneCompleter = new Completer(); | 140 final Completer _doneCompleter = new Completer(); |
141 StreamController<T> _controllerInstance; | 141 StreamController<T> _controllerInstance; |
142 Completer _controllerCompleter; | 142 Completer _controllerCompleter; |
143 bool _isClosed = false; | 143 bool _isClosed = false; |
144 bool _isBound = false; | 144 bool _isBound = false; |
145 bool _hasError = false; | 145 bool _hasError = false; |
146 | 146 |
147 _StreamSinkImpl(this._target); | 147 _StreamSinkImpl(this._target); |
148 | 148 |
149 void _reportClosedSink() { | |
150 // TODO(29554): this is very brittle and depends on the layout of the | |
151 // stderr class. | |
152 if (this == stderr._sink) { | |
153 // We can't report on stderr anymore (as we would otherwise | |
154 // have an infinite recursion. | |
155 throw new StateError("Stderr is closed."); | |
156 } | |
157 // TODO(29554): throw a StateError, and don't just report the problem. | |
158 stderr.writeln("StreamSink is closed and adding to it is an error."); | |
159 stderr.writeln(" See http://dartbug.com/29554."); | |
160 stderr.writeln(StackTrace.current); | |
161 } | |
162 | |
163 void add(T data) { | 149 void add(T data) { |
164 if (_isClosed) { | 150 if (_isClosed) { |
165 _reportClosedSink(); | 151 throw new StateError("StreamSink is closed"); |
166 return; | |
167 } | 152 } |
168 _controller.add(data); | 153 _controller.add(data); |
169 } | 154 } |
170 | 155 |
171 void addError(error, [StackTrace stackTrace]) { | 156 void addError(error, [StackTrace stackTrace]) { |
172 if (_isClosed) { | 157 if (_isClosed) { |
173 _reportClosedSink(); | 158 throw new StateError("StreamSink is closed"); |
174 return; | |
175 } | 159 } |
176 _controller.addError(error, stackTrace); | 160 _controller.addError(error, stackTrace); |
177 } | 161 } |
178 | 162 |
179 Future addStream(Stream<T> stream) { | 163 Future addStream(Stream<T> stream) { |
180 if (_isBound) { | 164 if (_isBound) { |
181 throw new StateError("StreamSink is already bound to a stream"); | 165 throw new StateError("StreamSink is already bound to a stream"); |
182 } | 166 } |
183 _isBound = true; | 167 _isBound = true; |
184 if (_hasError) return done; | 168 if (_hasError) return done; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 304 |
321 void writeln([Object object = ""]) { | 305 void writeln([Object object = ""]) { |
322 write(object); | 306 write(object); |
323 write("\n"); | 307 write("\n"); |
324 } | 308 } |
325 | 309 |
326 void writeCharCode(int charCode) { | 310 void writeCharCode(int charCode) { |
327 write(new String.fromCharCode(charCode)); | 311 write(new String.fromCharCode(charCode)); |
328 } | 312 } |
329 } | 313 } |
OLD | NEW |