You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2002/09/10 17:25:06 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output OutputBuffer.java StringOutputBuffer.java WriterOutputBuffer.java StreamHTMLOutput.java StreamOutput.java StreamTextOutput.java StreamXMLOutput.java
santiagopg 2002/09/10 08:25:05
Modified: java/src/org/apache/xalan/xsltc/runtime/output
StreamHTMLOutput.java StreamOutput.java
StreamTextOutput.java StreamXMLOutput.java
Added: java/src/org/apache/xalan/xsltc/runtime/output
OutputBuffer.java StringOutputBuffer.java
WriterOutputBuffer.java
Log:
New buffering system for stream output.
Revision Changes Path
1.18 +32 -1 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java
Index: StreamHTMLOutput.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamHTMLOutput.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- StreamHTMLOutput.java 12 Aug 2002 19:33:55 -0000 1.17
+++ StreamHTMLOutput.java 10 Sep 2002 15:25:05 -0000 1.18
@@ -97,12 +97,14 @@
public StreamHTMLOutput(StreamOutput output) {
super(output);
+ _buffer = new WriterOutputBuffer(_writer);
setIndent(true); // default for HTML
// System.out.println("StreamHTMLOutput.<init> this = " + this);
}
public StreamHTMLOutput(Writer writer, String encoding) {
super(writer, encoding);
+ _buffer = new WriterOutputBuffer(_writer);
setIndent(true); // default for HTML
//System.out.println("StreamHTMLOutput.<init> this = " + this);
}
@@ -111,6 +113,7 @@
throws IOException
{
super(out, encoding);
+ _buffer = new WriterOutputBuffer(_writer);
setIndent(true); // default for HTML
//System.out.println("StreamHTMLOutput.<init> this = " + this);
}
@@ -326,6 +329,33 @@
*/
private String escapeNonURL(String base) {
final int length = base.length();
+ StringBuffer result = null;
+
+ for (int i = 0; i < length; i++){
+ final char ch = base.charAt(i);
+
+ if ((ch >= '\u007F' && ch < '\u00A0') ||
+ (_is8859Encoded && ch > '\u00FF'))
+ {
+ if (result == null) {
+ result = new StringBuffer((int) (1.2 * length));
+ result.append(base.substring(0, i));
+ }
+ result.append(CHAR_ESC_START)
+ .append(Integer.toString((int) ch))
+ .append(';');
+ }
+ else if (result != null) {
+ result.append(ch);
+ }
+ }
+
+ return (result == null) ? base : result.toString();
+ }
+
+/*
+ private String escapeNonURL(String base) {
+ final int length = base.length();
final StringBuffer result = new StringBuffer();
for (int i = 0; i < length; i++){
@@ -344,6 +374,7 @@
}
return result.toString();
}
+*/
/**
* This method escapes special characters used in HTML attribute values
1.20 +4 -21 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java
Index: StreamOutput.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamOutput.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- StreamOutput.java 12 Aug 2002 19:33:55 -0000 1.19
+++ StreamOutput.java 10 Sep 2002 15:25:05 -0000 1.20
@@ -64,6 +64,7 @@
package org.apache.xalan.xsltc.runtime.output;
import java.io.Writer;
+import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -89,11 +90,8 @@
protected static final int MAX_INDENT_LEVEL = (INDENT.length >> 1);
protected static final int MAX_INDENT = INDENT.length;
- protected static final int BUFFER_SIZE = 32 * 1024;
- protected static final int OUTPUT_BUFFER_SIZE = 4 * 1024;
-
protected Writer _writer;
- protected StringBuffer _buffer;
+ protected OutputBuffer _buffer;
protected boolean _is8859Encoded = false;
protected boolean _indent = false;
@@ -147,7 +145,6 @@
_writer = writer;
_encoding = encoding;
_is8859Encoded = encoding.equalsIgnoreCase("iso-8859-1");
- _buffer = new StringBuffer(BUFFER_SIZE);
}
protected StreamOutput(OutputStream out, String encoding)
@@ -160,7 +157,6 @@
catch (UnsupportedEncodingException e) {
_writer = new OutputStreamWriter(out, _encoding = "utf-8");
}
- _buffer = new StringBuffer(BUFFER_SIZE);
}
public void setIndentNumber(int value) {
@@ -194,22 +190,9 @@
protected void outputBuffer() {
try {
- int n = 0;
- final int length = _buffer.length();
- final String output = _buffer.toString();
-
- // Output buffer in chunks of OUTPUT_BUFFER_SIZE
- if (length > OUTPUT_BUFFER_SIZE) {
- do {
- _writer.write(output, n, OUTPUT_BUFFER_SIZE);
- n += OUTPUT_BUFFER_SIZE;
- } while (n + OUTPUT_BUFFER_SIZE < length);
- }
- _writer.write(output, n, length - n);
- _writer.flush();
+ _writer.write(_buffer.close());
}
catch (IOException e) {
- // ignore
}
}
1.3 +3 -1 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamTextOutput.java
Index: StreamTextOutput.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamTextOutput.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StreamTextOutput.java 4 Jun 2002 11:58:31 -0000 1.2
+++ StreamTextOutput.java 10 Sep 2002 15:25:05 -0000 1.3
@@ -72,12 +72,14 @@
public StreamTextOutput(Writer writer, String encoding) {
super(writer, encoding);
+ _buffer = new WriterOutputBuffer(_writer);
}
public StreamTextOutput(OutputStream out, String encoding)
throws IOException
{
super(out, encoding);
+ _buffer = new WriterOutputBuffer(_writer);
}
public void startDocument() throws TransletException {
1.20 +18 -2 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java
Index: StreamXMLOutput.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StreamXMLOutput.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- StreamXMLOutput.java 12 Aug 2002 19:33:55 -0000 1.19
+++ StreamXMLOutput.java 10 Sep 2002 15:25:05 -0000 1.20
@@ -90,6 +90,7 @@
public StreamXMLOutput(Writer writer, String encoding) {
super(writer, encoding);
+ _buffer = new StringOutputBuffer();
initCDATA();
initNamespaces();
//System.out.println("StreamXMLOutput.<init>");
@@ -99,11 +100,22 @@
throws IOException
{
super(out, encoding);
+ _buffer = new StringOutputBuffer();
initCDATA();
initNamespaces();
//System.out.println("StreamXMLOutput.<init>");
}
+ private void insertHeader(String header) {
+ try {
+ _writer.write(header);
+ _writer.write(_buffer.close());
+ _buffer = new WriterOutputBuffer(_writer);
+ }
+ catch (IOException e) {
+ }
+ }
+
public void startDocument() throws TransletException {
//System.out.println("startDocument");
if (!_omitHeader) {
@@ -115,7 +127,11 @@
header.append("\"?>\n");
// Always insert header at the beginning
- _buffer.insert(0, header.toString());
+ insertHeader(header.toString());
+ }
+ else {
+ // Must inform buffer the absence of a header
+ insertHeader(EMPTYSTRING);
}
}
1.1 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/OutputBuffer.java
Index: OutputBuffer.java
===================================================================
/*
* @(#)$Id: OutputBuffer.java,v 1.1 2002/09/10 15:25:05 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES{} LOSS OF
* USE, DATA, OR PROFITS{} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Sun
* Microsystems., http://www.sun.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* @author Santiago Pericas-Geertsen
*
*/
package org.apache.xalan.xsltc.runtime.output;
interface OutputBuffer {
public String close();
public OutputBuffer append(char ch);
public OutputBuffer append(String s);
public OutputBuffer append(char[] s, int from, int to);
}
1.1 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/StringOutputBuffer.java
Index: StringOutputBuffer.java
===================================================================
/*
* @(#)$Id: StringOutputBuffer.java,v 1.1 2002/09/10 15:25:05 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES{} LOSS OF
* USE, DATA, OR PROFITS{} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Sun
* Microsystems., http://www.sun.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* @author Santiago Pericas-Geertsen
*
*/
package org.apache.xalan.xsltc.runtime.output;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.IOException;
class StringOutputBuffer implements OutputBuffer {
private StringBuffer _buffer;
public StringOutputBuffer() {
_buffer = new StringBuffer();
}
public String close() {
return _buffer.toString();
}
public OutputBuffer append(String s) {
_buffer.append(s);
return this;
}
public OutputBuffer append(char[] s, int from, int to) {
_buffer.append(s, from, to);
return this;
}
public OutputBuffer append(char ch) {
_buffer.append(ch);
return this;
}
}
1.1 xml-xalan/java/src/org/apache/xalan/xsltc/runtime/output/WriterOutputBuffer.java
Index: WriterOutputBuffer.java
===================================================================
/*
* @(#)$Id: WriterOutputBuffer.java,v 1.1 2002/09/10 15:25:05 santiagopg Exp $
*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xalan" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES{} LOSS OF
* USE, DATA, OR PROFITS{} OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, Sun
* Microsystems., http://www.sun.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* @author Santiago Pericas-Geertsen
*
*/
package org.apache.xalan.xsltc.runtime.output;
import java.io.Writer;
import java.io.BufferedWriter;
import java.io.IOException;
class WriterOutputBuffer implements OutputBuffer {
protected static final int BUFFER_SIZE = 32 * 1024;
private Writer _writer;
/**
* Initializes a WriterOutputBuffer by creating an instance of a
* BufferedWriter. The size of the buffer in this writer may have
* a significant impact on throughput. Solaris prefers a larger
* buffer, while Linux works better with a smaller one.
*/
public WriterOutputBuffer(Writer writer) {
_writer = new BufferedWriter(writer, BUFFER_SIZE);
}
public String close() {
try {
_writer.flush();
}
catch (IOException e) {
throw new RuntimeException(e.toString());
}
return "";
}
public OutputBuffer append(String s) {
try {
_writer.write(s);
}
catch (IOException e) {
throw new RuntimeException(e.toString());
}
return this;
}
public OutputBuffer append(char[] s, int from, int to) {
try {
_writer.write(s, from, to);
}
catch (IOException e) {
throw new RuntimeException(e.toString());
}
return this;
}
public OutputBuffer append(char ch) {
try {
_writer.write(ch);
}
catch (IOException e) {
throw new RuntimeException(e.toString());
}
return this;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org