KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > util > StringBufferWriter


1 // ========================================================================
2
// $Id: StringBufferWriter.java,v 1.4 2004/05/09 20:33:04 gregwilkins Exp $
3
// Copyright 2001-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.util;
17 import java.io.IOException JavaDoc;
18 import java.io.Writer JavaDoc;
19
20
21 /* ------------------------------------------------------------ */
22 /** A Writer to a StringBuffer.
23  *
24  * @version $Id: StringBufferWriter.java,v 1.4 2004/05/09 20:33:04 gregwilkins Exp $
25  * @author Greg Wilkins (gregw)
26  */

27 public class StringBufferWriter extends Writer JavaDoc
28 {
29     /* ------------------------------------------------------------ */
30     private StringBuffer JavaDoc _buffer;
31
32     /* ------------------------------------------------------------ */
33     /** Constructor.
34      */

35     public StringBufferWriter()
36     {
37         _buffer=new StringBuffer JavaDoc();
38     }
39     
40     /* ------------------------------------------------------------ */
41     /** Constructor.
42      * @param buffer
43      */

44     public StringBufferWriter(StringBuffer JavaDoc buffer)
45     {
46         _buffer=buffer;
47     }
48
49     /* ------------------------------------------------------------ */
50     public void setStringBuffer(StringBuffer JavaDoc buffer)
51     {
52         _buffer=buffer;
53     }
54     
55     /* ------------------------------------------------------------ */
56     public StringBuffer JavaDoc getStringBuffer()
57     {
58         return _buffer;
59     }
60     
61     /* ------------------------------------------------------------ */
62     public void write(char c)
63         throws IOException JavaDoc
64     {
65         _buffer.append(c);
66     }
67     
68     /* ------------------------------------------------------------ */
69     public void write(char[] ca)
70         throws IOException JavaDoc
71     {
72         _buffer.append(ca);
73     }
74     
75     
76     /* ------------------------------------------------------------ */
77     public void write(char[] ca,int offset, int length)
78         throws IOException JavaDoc
79     {
80         _buffer.append(ca,offset,length);
81     }
82     
83     /* ------------------------------------------------------------ */
84     public void write(String JavaDoc s)
85         throws IOException JavaDoc
86     {
87         _buffer.append(s);
88     }
89     
90     /* ------------------------------------------------------------ */
91     public void write(String JavaDoc s,int offset, int length)
92         throws IOException JavaDoc
93     {
94         for (int i=0;i<length;i++)
95             _buffer.append(s.charAt(offset+i));
96     }
97     
98     /* ------------------------------------------------------------ */
99     public void flush()
100     {}
101
102     /* ------------------------------------------------------------ */
103     public void reset()
104     {
105         _buffer.setLength(0);
106     }
107
108     /* ------------------------------------------------------------ */
109     public void close()
110     {}
111
112 }
113
Popular Tags