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:
13: public List subHandlers = new LinkedList();
14:
15: public CachingResultFormatter() throws Exception {
16: buffer = new ContentBuffer(".results");
17: }
18:
19: public void acceptResult(PageResult result) throws Exception {
20: ByteArrayOutputStream output = new ByteArrayOutputStream();
21: FitProtocol.writeData(result.toString() + "\n", output);
22: buffer.append(output.toByteArray());
23:
24: for (Iterator iterator = subHandlers.iterator(); iterator
25: .hasNext();)
26: ((ResultHandler) iterator.next()).acceptResult(result);
27: }
28:
29: public void acceptFinalCount(Counts count) throws Exception {
30: ByteArrayOutputStream output = new ByteArrayOutputStream();
31: FitProtocol.writeCounts(count, output);
32: buffer.append(output.toByteArray());
33:
34: for (Iterator iterator = subHandlers.iterator(); iterator
35: .hasNext();)
36: ((ResultHandler) iterator.next()).acceptFinalCount(count);
37: }
38:
39: public int getByteCount() throws Exception {
40: return buffer.getSize();
41: }
42:
43: public InputStream getResultStream() throws Exception {
44: return buffer.getNonDeleteingInputStream();
45: }
46:
47: public void cleanUp() throws Exception {
48: buffer.delete();
49: }
50:
51: public void addHandler(ResultHandler handler) {
52: subHandlers.add(handler);
53: }
54: }
|