6
|
1 |
/*
|
|
2 |
* reserved comment block
|
|
3 |
* DO NOT REMOVE OR ALTER!
|
|
4 |
*/
|
|
5 |
/*
|
|
6 |
* Copyright 2001-2004 The Apache Software Foundation.
|
|
7 |
*
|
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9 |
* you may not use this file except in compliance with the License.
|
|
10 |
* You may obtain a copy of the License at
|
|
11 |
*
|
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13 |
*
|
|
14 |
* Unless required by applicable law or agreed to in writing, software
|
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17 |
* See the License for the specific language governing permissions and
|
|
18 |
* limitations under the License.
|
|
19 |
*/
|
|
20 |
/*
|
|
21 |
* $Id: WriterOutputBuffer.java,v 1.2.4.1 2005/09/06 11:43:01 pvedula Exp $
|
|
22 |
*/
|
|
23 |
|
|
24 |
package com.sun.org.apache.xalan.internal.xsltc.runtime.output;
|
|
25 |
|
16953
|
26 |
import com.sun.org.apache.xalan.internal.utils.SecuritySupport;
|
6
|
27 |
import java.io.BufferedWriter;
|
|
28 |
import java.io.IOException;
|
|
29 |
import java.io.Writer;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* @author Santiago Pericas-Geertsen
|
|
33 |
*/
|
|
34 |
class WriterOutputBuffer implements OutputBuffer {
|
|
35 |
private static final int KB = 1024;
|
|
36 |
private static int BUFFER_SIZE = 4 * KB;
|
|
37 |
|
|
38 |
static {
|
|
39 |
// Set a larger buffer size for Solaris
|
16953
|
40 |
final String osName = SecuritySupport.getSystemProperty("os.name");
|
6
|
41 |
if (osName.equalsIgnoreCase("solaris")) {
|
|
42 |
BUFFER_SIZE = 32 * KB;
|
|
43 |
}
|
|
44 |
}
|
|
45 |
|
|
46 |
private Writer _writer;
|
|
47 |
|
|
48 |
/**
|
|
49 |
* Initializes a WriterOutputBuffer by creating an instance of a
|
|
50 |
* BufferedWriter. The size of the buffer in this writer may have
|
|
51 |
* a significant impact on throughput. Solaris prefers a larger
|
|
52 |
* buffer, while Linux works better with a smaller one.
|
|
53 |
*/
|
|
54 |
public WriterOutputBuffer(Writer writer) {
|
|
55 |
_writer = new BufferedWriter(writer, BUFFER_SIZE);
|
|
56 |
}
|
|
57 |
|
|
58 |
public String close() {
|
|
59 |
try {
|
|
60 |
_writer.flush();
|
|
61 |
}
|
|
62 |
catch (IOException e) {
|
|
63 |
throw new RuntimeException(e.toString());
|
|
64 |
}
|
|
65 |
return "";
|
|
66 |
}
|
|
67 |
|
|
68 |
public OutputBuffer append(String s) {
|
|
69 |
try {
|
|
70 |
_writer.write(s);
|
|
71 |
}
|
|
72 |
catch (IOException e) {
|
|
73 |
throw new RuntimeException(e.toString());
|
|
74 |
}
|
|
75 |
return this;
|
|
76 |
}
|
|
77 |
|
|
78 |
public OutputBuffer append(char[] s, int from, int to) {
|
|
79 |
try {
|
|
80 |
_writer.write(s, from, to);
|
|
81 |
}
|
|
82 |
catch (IOException e) {
|
|
83 |
throw new RuntimeException(e.toString());
|
|
84 |
}
|
|
85 |
return this;
|
|
86 |
}
|
|
87 |
|
|
88 |
public OutputBuffer append(char ch) {
|
|
89 |
try {
|
|
90 |
_writer.write(ch);
|
|
91 |
}
|
|
92 |
catch (IOException e) {
|
|
93 |
throw new RuntimeException(e.toString());
|
|
94 |
}
|
|
95 |
return this;
|
|
96 |
}
|
|
97 |
}
|