OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 // Output provider that collects the output in string buffers. |
| 6 |
| 7 library output_collector; |
| 8 |
| 9 import 'dart:async'; |
| 10 |
| 11 class BufferedEventSink implements EventSink<String> { |
| 12 StringBuffer sb = new StringBuffer(); |
| 13 String text; |
| 14 |
| 15 void add(String event) { |
| 16 sb.write(event); |
| 17 } |
| 18 |
| 19 void addError(errorEvent, [StackTrace stackTrace]) { |
| 20 // Do not support this. |
| 21 } |
| 22 |
| 23 void close() { |
| 24 text = sb.toString(); |
| 25 sb = null; |
| 26 } |
| 27 } |
| 28 |
| 29 class OutputCollector { |
| 30 Map<String, Map<String, BufferedEventSink>> outputMap = {}; |
| 31 |
| 32 EventSink<String> call(String name, String extension) { |
| 33 Map<String, BufferedEventSink> sinkMap = |
| 34 outputMap.putIfAbsent(extension, () => {}); |
| 35 return sinkMap.putIfAbsent(name, () => new BufferedEventSink()); |
| 36 } |
| 37 |
| 38 String getOutput(String name, String extension) { |
| 39 Map<String, BufferedEventSink> sinkMap = outputMap[extension]; |
| 40 if (sinkMap == null) return null; |
| 41 BufferedEventSink sink = sinkMap[name]; |
| 42 return sink != null ? sink.text : null; |
| 43 } |
| 44 } |
OLD | NEW |