📄 bodycontentimpl.java
字号:
* @throws java.io.IOException */ public void print(double d) throws IOException { write(String.valueOf(d)); } /** * Print an array of characters. The characters are converted 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 s The array of chars to be printed * * @throws NullPointerException If <code>s</code> is <code>null</code> * @throws java.io.IOException */ public void print(char s[]) throws IOException { write(s); } /** * Print a string. If the argument is <code>null</code> then the string * <code>"null"</code> is printed. Otherwise, the string's characters are * converted 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 s The <code>String</code> to be printed * @throws java.io.IOException */ public void print(String s) throws IOException { if (s == null) { s = "null"; } write(s); } /** * Print an object. The string produced by the <code>{@link * java.lang.String#valueOf(Object)}</code> method 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 obj The <code>Object</code> to be printed * @see java.lang.Object#toString() * @throws java.io.IOException */ public void print(Object obj) throws IOException { write(String.valueOf(obj)); } /** * Terminate the current line by writing the line separator string. The * line separator string is defined by the system property * <code>line.separator</code>, and is not necessarily a single newline * character (<code>'\n'</code>). * @throws java.io.IOException */ public void println() throws IOException { newLine(); } /** * Print a boolean value and then terminate the line. This method behaves * as though it invokes <code>{@link #print(boolean)}</code> and then * <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(boolean x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print a character and then terminate the line. This method behaves as * though it invokes <code>{@link #print(char)}</code> and then <code>{@link * #println()}</code>. * @throws java.io.IOException */ public void println(char x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print an integer and then terminate the line. This method behaves as * though it invokes <code>{@link #print(int)}</code> and then <code>{@link * #println()}</code>. * @throws java.io.IOException */ public void println(int x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print a long integer and then terminate the line. This method behaves * as though it invokes <code>{@link #print(long)}</code> and then * <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(long x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print a floating-point number and then terminate the line. This method * behaves as though it invokes <code>{@link #print(float)}</code> and then * <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(float x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print a double-precision floating-point number and then terminate the * line. This method behaves as though it invokes <code>{@link * #print(double)}</code> and then <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(double x) throws IOException{ synchronized (lock) { print(x); println(); } } /** * Print an array of characters and then terminate the line. This method * behaves as though it invokes <code>{@link #print(char[])}</code> and then * <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(char x[]) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print a String and then terminate the line. This method behaves as * though it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(String x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Print an Object and then terminate the line. This method behaves as * though it invokes <code>{@link #print(Object)}</code> and then * <code>{@link #println()}</code>. * @throws java.io.IOException */ public void println(Object x) throws IOException { synchronized (lock) { print(x); println(); } } /** * Clear the contents of the buffer. If the buffer has been already * been flushed then the clear operation shall throw an IOException * to signal the fact that some data has already been irrevocably * written to the client response stream. * * @throws IOException If an I/O error occurs */ public void clear() throws IOException { synchronized (lock) { cb = new char [Constants.DEFAULT_BUFFER_SIZE]; bufferSize = Constants.DEFAULT_BUFFER_SIZE; nextChar = 0; } } /** * Clears the current contents of the buffer. Unlike clear(), this * mehtod will not throw an IOException if the buffer has already been * flushed. It merely clears the current content of the buffer and * returns. * * @throws IOException If an I/O error occurs */ public void clearBuffer() throws IOException { this.clear(); } /** * Close the stream, flushing it first. Once a stream has been closed, * further write() or flush() invocations will cause an IOException to be * thrown. Closing a previously-closed stream, however, has no effect. * * @exception IOException If an I/O error occurs */ public void close() throws IOException { synchronized (lock) { cb = null; } } /** * @return the number of bytes unused in the buffer */ public int getRemaining() { return bufferSize - nextChar; } /** * Return the value of this BodyJspWriter as a Reader. * Note: this is after evaluation!! There are no scriptlets, * etc in this stream. * * @returns the value of this BodyJspWriter as a Reader */ public Reader getReader() { return new CharArrayReader (cb, 0, nextChar); } /** * Return the value of the BodyJspWriter as a String. * Note: this is after evaluation!! There are no scriptlets, * etc in this stream. * * @returns the value of the BodyJspWriter as a String */ public String getString() { return new String(cb, 0, nextChar); } /** * Write the contents of this BodyJspWriter into a Writer. * Subclasses are likely to do interesting things with the * implementation so some things are extra efficient. * * @param out The writer into which to place the contents of * this body evaluation */ public void writeOut(Writer out) throws IOException { out.write(cb, 0, nextChar); // Flush not called as the writer passed could be a BodyContent and // it doesn't allow to flush. } public static void main (String[] args) throws Exception { char[] buff = {'f','o','o','b','a','r','b','a','z','y'}; BodyContentImpl bodyContent = new BodyContentImpl(new JspWriterImpl( null, 100, false)); bodyContent.println (buff); System.out.println (bodyContent.getString ()); bodyContent.writeOut (new PrintWriter (System.out)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -