📄 pi3jspwriter.java
字号:
/*____________________________________________________________________________*\
*
Copyright (c) 1997-2003 John Roy, Holger Zimmermann. All rights reserved.
These sources, libraries and applications are
FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
as long as the following conditions are adhered to.
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 name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
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 AUTHORS 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.
*____________________________________________________________________________*|
*
* $Source: /cvsroot/pi3web/Pi3Web_200/Source/Servlet/org/pi3/jsp/core/Pi3JspWriter.java,v $
* $Date: 2003/05/13 18:42:20 $
*
Description:
Implementation of jsp API JspWriter interface.
\*____________________________________________________________________________*/
package org.pi3.jsp.core;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.OutputStream;
import javax.servlet.jsp.JspWriter;
import org.pi3.servlet.util.Pi3BufferedOutputStream;
/**
* <p>
* This abstract class emulates some of the functionality found in the
* java.io.BufferedWriter and java.io.PrintWriter classes,
* however it differs in that it throws java.io.IOException from the print
* methods with PrintWriter does not.
* </p>
* <p>
* The "out" implicit variable of a JSP implementation class is of this type.
* If the page directive selects autoflush="true" then all the I/O operations
* on this class shall automatically fluch the contents of the buffer if an
* overflow condition would result if the current operation were performed
* without a flush. If autoflush="false" then all the I/O operations on this
* class shall throw an IOException if performing the current opertion would
* result in a buffer overflow condition.
* </p>
*
* @see java.io.Writer
* @see java.io.BufferedWriter
* @see java.io.PrintWriter
*/
public class Pi3JspWriter extends JspWriter {
private Pi3BufferedOutputStream os = null;
private PrintWriter pw;
/** Comment */
public Pi3JspWriter(OutputStream out, int bufSize,
boolean autoflush) throws IOException {
super(bufSize, autoflush);
if (bufSize == JspWriter.NO_BUFFER ) {
pw = new PrintWriter(out);
} else {
os = (bufSize != JspWriter.DEFAULT_BUFFER) ?
new Pi3BufferedOutputStream(out, bufSize) : new Pi3BufferedOutputStream(out);
pw = new PrintWriter(os);
}
}
/** Comment */
private void internalWrite(String s) throws IOException {
char[] chrs = new char[s.length()];
s.getChars(0, s.length(), chrs, 0);
write(chrs, 0, s.length());
};
/** Comment */
private void internalWriteln(String s) throws IOException {
StringBuffer sb = new StringBuffer(s);
sb.append(System.getProperty("line.separator"));
char[] chrs = new char[sb.length()];
sb.getChars(0, sb.length(), chrs, 0);
write(chrs, 0, sb.length());
};
/** Comment */
public void write(char[] cbuf, int off, int len) throws IOException {
if (getRemaining() > len) {
for (int i = off; i < off + len; pw.print(cbuf[i++]));
} else {
if (autoFlush) {
flush();
for (int i = off; i < off + len; pw.print(cbuf[i++]));
} else {
IOException e = new IOException("Buffer overrun");
throw e;
};
};
}
/**
* Write a line separator. The line separator string is defined by the
* system property <tt>line.separator</tt>, and is not necessarily a single
* newline ('\n') character.
*
* @exception IOException If an I/O error occurs
*/
public void newLine() throws IOException {
internalWrite(System.getProperty("line.separator"));
}
/**
* Print a boolean value. The string produced by <code>{@link
* java.lang.String#valueOf(boolean)}</code> is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link
* #write(int)}</code> method.
*
* @param b The <code>boolean</code> to be printed
* @throws java.io.IOException
*/
public void print(boolean b) throws IOException {
internalWrite(String.valueOf(b));
}
/**
* Print a character. The character is translated into one or more bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link
* #write(int)}</code> method.
*
* @param c The <code>char</code> to be printed
* @throws java.io.IOException
*/
public void print(char c) throws IOException {
internalWrite(String.valueOf(c));
}
/**
* Print an integer. The string produced by <code>{@link
* java.lang.String#valueOf(int)}</code> is translated into bytes according
* to the platform's default character encoding, and these bytes are
* written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
*
* @param i The <code>int</code> to be printed
* @see java.lang.Integer#toString(int)
* @throws java.io.IOException
*/
public void print(int i) throws IOException {
internalWrite(String.valueOf(i));
}
/**
* Print a long integer. The string produced by <code>{@link
* java.lang.String#valueOf(long)}</code> is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
*
* @param l The <code>long</code> to be printed
* @see java.lang.Long#toString(long)
* @throws java.io.IOException
*/
public void print(long l) throws IOException {
internalWrite(String.valueOf(l));
}
/**
* Print a floating-point number. The string produced by <code>{@link
* java.lang.String#valueOf(float)}</code> is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
*
* @param f The <code>float</code> to be printed
* @see java.lang.Float#toString(float)
* @throws java.io.IOException
*/
public void print(float f) throws IOException {
internalWrite(String.valueOf(f));
}
/**
* Print a double-precision floating-point number. The string produced by
* <code>{@link java.lang.String#valueOf(double)}</code> is translated into
* bytes according to the platform's default character encoding, and these
* bytes are written in exactly the manner of the <code>{@link
* #write(int)}</code> method.
*
* @param d The <code>double</code> to be printed
* @see java.lang.Double#toString(double)
* @throws java.io.IOException
*/
public void print(double d) throws IOException {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -