KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > vladium > emma > report > html > doc > HTMLWriter


1 /* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved.
2  *
3  * This program and the accompanying materials are made available under
4  * the terms of the Common Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/cpl-v10.html
6  *
7  * $Id: HTMLWriter.java,v 1.1.1.1 2004/05/09 16:57:41 vlad_r Exp $
8  */

9 package com.vladium.emma.report.html.doc;
10
11 import java.io.IOException JavaDoc;
12 import java.io.Writer JavaDoc;
13
14 import com.vladium.util.IConstants;
15 import com.vladium.util.asserts.$assert;
16 import com.vladium.emma.IAppErrorCodes;
17 import com.vladium.emma.EMMARuntimeException;
18
19 // ----------------------------------------------------------------------------
20
/**
21  * @author Vlad Roubtsov, (C) 2003
22  */

23 public
24 final class HTMLWriter
25 {
26     // public: ................................................................
27

28     // TODO: add API for indenting
29

30     public HTMLWriter (final Writer JavaDoc out)
31     {
32         if (out == null) throw new IllegalArgumentException JavaDoc ("null input: out");
33         
34         m_out = out;
35     }
36     
37     
38     public void write (final String JavaDoc s)
39     {
40         if ($assert.ENABLED) $assert.ASSERT (s != null, "s = null");
41         
42         if (m_out != null)
43         {
44             try
45             {
46                 m_out.write (s);
47             }
48             catch (IOException JavaDoc ioe)
49             {
50                 throw new EMMARuntimeException (IAppErrorCodes.REPORT_IO_FAILURE, ioe);
51             }
52         }
53     }
54     
55     public void write (final char c)
56     {
57         if (m_out != null)
58         {
59             try
60             {
61                 m_out.write (c);
62             }
63             catch (IOException JavaDoc ioe)
64             {
65                 throw new EMMARuntimeException (IAppErrorCodes.REPORT_IO_FAILURE, ioe);
66             }
67         }
68     }
69     
70     public void eol ()
71     {
72         if (m_out != null)
73         {
74             try
75             {
76                 m_out.write (IConstants.EOL);
77             }
78             catch (IOException JavaDoc ioe)
79             {
80                 throw new EMMARuntimeException (IAppErrorCodes.REPORT_IO_FAILURE, ioe);
81             }
82         }
83     }
84     
85     public void flush ()
86     {
87         if (m_out != null)
88         {
89             try
90             {
91                 m_out.flush ();
92             }
93             catch (IOException JavaDoc ioe)
94             {
95                 throw new EMMARuntimeException (IAppErrorCodes.REPORT_IO_FAILURE, ioe);
96             }
97         }
98     }
99     
100     public void close ()
101     {
102         if (m_out != null)
103         {
104             try { m_out.close (); } catch (IOException JavaDoc ignore) {}
105             m_out = null;
106         }
107     }
108     
109     // protected: .............................................................
110

111     // package: ...............................................................
112

113     // private: ...............................................................
114

115     
116     private Writer JavaDoc m_out;
117
118 } // end of class
119
// ----------------------------------------------------------------------------
Popular Tags