01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.runner;
04:
05: import fit.Counts;
06: import java.io.*;
07: import java.util.*;
08: import fitnesse.components.*;
09:
10: public class CachingResultFormatter implements ResultFormatter {
11: private ContentBuffer buffer;
12: public List<ResultHandler> subHandlers = new LinkedList<ResultHandler>();
13:
14: public CachingResultFormatter() throws Exception {
15: buffer = new ContentBuffer(".results");
16: }
17:
18: public void acceptResult(PageResult result) throws Exception {
19: ByteArrayOutputStream output = new ByteArrayOutputStream();
20: FitProtocol.writeData(result.toString() + "\n", output);
21: buffer.append(output.toByteArray());
22:
23: for (Iterator iterator = subHandlers.iterator(); iterator
24: .hasNext();)
25: ((ResultHandler) iterator.next()).acceptResult(result);
26: }
27:
28: public void acceptFinalCount(Counts count) throws Exception {
29: ByteArrayOutputStream output = new ByteArrayOutputStream();
30: FitProtocol.writeCounts(count, output);
31: buffer.append(output.toByteArray());
32:
33: for (Iterator iterator = subHandlers.iterator(); iterator
34: .hasNext();)
35: ((ResultHandler) iterator.next()).acceptFinalCount(count);
36: }
37:
38: public int getByteCount() throws Exception {
39: return buffer.getSize();
40: }
41:
42: public InputStream getResultStream() throws Exception {
43: return buffer.getNonDeleteingInputStream();
44: }
45:
46: public void cleanUp() throws Exception {
47: buffer.delete();
48: }
49:
50: public void addHandler(ResultHandler handler) {
51: subHandlers.add(handler);
52: }
53: }
|