1 package org.codehaus.mojo.fitnesse.log;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.io.File;
18 import java.io.FileWriter;
19 import java.io.IOException;
20
21 public class FileConsumer
22 implements FitnesseStreamConsumer
23 {
24
25 FileWriter mOutputWriter;
26
27 private boolean mHasGeneratedResultFile = false;
28
29 private String mLineSep = System.getProperty( "line.separator" );
30
31
32 public FileConsumer()
33 {
34 }
35
36 public FileConsumer( File pOutputFile )
37 {
38 super();
39 try
40 {
41 mOutputWriter = new FileWriter( pOutputFile );
42 }
43 catch ( IOException e )
44 {
45 throw new RuntimeException( "Unable to write into file" );
46 }
47 }
48
49 public synchronized void consumeLine( String pMessage )
50 {
51 try
52 {
53 mOutputWriter.write( pMessage + mLineSep );
54 }
55 catch ( IOException e )
56 {
57 throw new RuntimeException( "Unable to write into file" );
58 }
59 mHasGeneratedResultFile = mHasGeneratedResultFile || pMessage.startsWith( "Formatting as html" );
60 }
61
62 public boolean hasGeneratedResultFile()
63 {
64 return mHasGeneratedResultFile;
65 }
66
67 public void close()
68 {
69 try
70 {
71 mOutputWriter.flush();
72 mOutputWriter.close();
73 }
74 catch ( IOException e )
75 {
76 throw new RuntimeException( "Unable to write into file" );
77 }
78 }
79
80 }