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