KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xalan > xsltc > runtime > output > WriterOutputBuffer


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

16 /*
17  * $Id: WriterOutputBuffer.java,v 1.5 2004/02/16 22:56:25 minchau Exp $
18  */

19
20 package org.apache.xalan.xsltc.runtime.output;
21
22 import java.io.BufferedWriter JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.Writer JavaDoc;
25
26 /**
27  * @author Santiago Pericas-Geertsen
28  */

29 class WriterOutputBuffer implements OutputBuffer {
30     private static final int KB = 1024;
31     private static int BUFFER_SIZE = 4 * KB;
32
33     static {
34     // Set a larger buffer size for Solaris
35
final String JavaDoc osName = System.getProperty("os.name");
36     if (osName.equalsIgnoreCase("solaris")) {
37         BUFFER_SIZE = 32 * KB;
38     }
39     }
40
41     private Writer JavaDoc _writer;
42
43     /**
44      * Initializes a WriterOutputBuffer by creating an instance of a
45      * BufferedWriter. The size of the buffer in this writer may have
46      * a significant impact on throughput. Solaris prefers a larger
47      * buffer, while Linux works better with a smaller one.
48      */

49     public WriterOutputBuffer(Writer JavaDoc writer) {
50     _writer = new BufferedWriter JavaDoc(writer, BUFFER_SIZE);
51     }
52
53     public String JavaDoc close() {
54     try {
55         _writer.flush();
56     }
57     catch (IOException JavaDoc e) {
58         throw new RuntimeException JavaDoc(e.toString());
59     }
60     return "";
61     }
62
63     public OutputBuffer append(String JavaDoc s) {
64     try {
65         _writer.write(s);
66     }
67     catch (IOException JavaDoc e) {
68         throw new RuntimeException JavaDoc(e.toString());
69     }
70     return this;
71     }
72
73     public OutputBuffer append(char[] s, int from, int to) {
74     try {
75         _writer.write(s, from, to);
76     }
77     catch (IOException JavaDoc e) {
78         throw new RuntimeException JavaDoc(e.toString());
79     }
80     return this;
81     }
82
83     public OutputBuffer append(char ch) {
84     try {
85         _writer.write(ch);
86     }
87     catch (IOException JavaDoc e) {
88         throw new RuntimeException JavaDoc(e.toString());
89     }
90     return this;
91     }
92 }
93
94
95
Popular Tags