KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > slide > webdav > logger > XServletWriterFacade


1 /*
2  * ====================================================================
3  *
4  * Copyright 1999-2002 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */

19
20
21 package org.apache.slide.webdav.logger;
22
23 import java.io.PrintWriter JavaDoc;
24 import java.io.Writer JavaDoc;
25
26 /**
27  * Facade to the PrintWriter returned by Response.
28  * This will grow to include more support for JSPs ( and other templating
29  * systems ) buffering requirements, provide support for accounting
30  * and will allow more control over char-to-byte conversion ( if it proves
31  * that we spend too much time in that area ).
32  *
33  * This will also help us control the multi-buffering ( since all writers have
34  * 8k or more of un-recyclable buffers).
35  *
36  */

37 public class XServletWriterFacade extends PrintWriter JavaDoc {
38     
39     protected static final int DEFAULT_BUFFER_SIZE = 8*1024;
40     int defaultBufferSize = DEFAULT_BUFFER_SIZE;
41     int bytesWritten = 0;
42
43     /** The buffer
44      */

45     public StringBuffer JavaDoc buffer;
46
47     public XServletWriterFacade( Writer JavaDoc w ) {
48         super( w );
49 // buf = new byte[defaultBufferSize];
50
buffer = new StringBuffer JavaDoc();
51     }
52
53     // -------------------- Write methods --------------------
54

55     public void flush() {
56     super.flush();
57     }
58
59     public void print( String JavaDoc str ) {
60         buffer = buffer.append(str);
61         super.print( str );
62    }
63
64     public void println( String JavaDoc str ) {
65         buffer = buffer.append(str + "\n");
66         super.println( str );
67    }
68
69     public void write( char buf[], int offset, int count ) {
70         buffer = buffer.append( buf, offset, count );
71         super.write( buf, offset, count );
72     }
73
74     public void write( String JavaDoc str ) {
75         buffer = buffer.append(str);
76         super.write( str );
77     }
78
79     public String JavaDoc getOutputBuffer() {
80         return buffer.toString();
81     }
82
83 }
84
85
Popular Tags