Methods Summary |
---|
public void | clear()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.
if (writer != null) {
throw new IOException();
} else {
nextChar = 0;
}
|
public void | clearBuffer()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.
if (writer == null) {
this.clear();
}
|
public void | close()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.
if (writer != null) {
writer.close();
} else {
cb = null;
closed = true;
}
|
private void | ensureOpen()
if (closed) throw new IOException("Stream closed");
|
public java.io.Reader | getReader()Return the value of this BodyJspWriter as a Reader.
Note: this is after evaluation!! There are no scriptlets,
etc in this stream.
return (writer == null) ? new CharArrayReader (cb, 0, nextChar) : null;
|
public int | getRemaining()
return (writer == null) ? bufferSize-nextChar : 0;
|
public java.lang.String | getString()Return the value of the BodyJspWriter as a String.
Note: this is after evaluation!! There are no scriptlets,
etc in this stream.
return (writer == null) ? new String(cb, 0, nextChar) : null;
|
public static void | main(java.lang.String[] args)
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));
|
public void | newLine()Write a line separator. The line separator string is defined by the
system property line.separator, and is not necessarily a single
newline ('\n') character.
if (writer != null) {
writer.write(LINE_SEPARATOR);
} else {
write(LINE_SEPARATOR);
}
|
public void | print(int i)Print an integer. The string produced by {@link
java.lang.String#valueOf(int)} is translated into bytes according
to the platform's default character encoding, and these bytes are
written in exactly the manner of the {@link #write(int)}
method.
if (writer != null) {
writer.write(String.valueOf(i));
} else {
write(String.valueOf(i));
}
|
public void | print(long l)Print a long integer. The string produced by {@link
java.lang.String#valueOf(long)} is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
{@link #write(int)} method.
if (writer != null) {
writer.write(String.valueOf(l));
} else {
write(String.valueOf(l));
}
|
public void | print(float f)Print a floating-point number. The string produced by {@link
java.lang.String#valueOf(float)} is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
{@link #write(int)} method.
if (writer != null) {
writer.write(String.valueOf(f));
} else {
write(String.valueOf(f));
}
|
public void | print(double d)Print a double-precision floating-point number. The string produced by
{@link java.lang.String#valueOf(double)} is translated into
bytes according to the platform's default character encoding, and these
bytes are written in exactly the manner of the {@link
#write(int)} method.
if (writer != null) {
writer.write(String.valueOf(d));
} else {
write(String.valueOf(d));
}
|
public void | print(char[] s)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
{@link #write(int)} method.
if (writer != null) {
writer.write(s);
} else {
write(s);
}
|
public void | print(java.lang.String s)Print a string. If the argument is null then the string
"null" 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
{@link #write(int)} method.
if (s == null) s = "null";
if (writer != null) {
writer.write(s);
} else {
write(s);
}
|
public void | print(java.lang.Object obj)Print an object. The string produced by the {@link
java.lang.String#valueOf(Object)} method is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the
{@link #write(int)} method.
if (writer != null) {
writer.write(String.valueOf(obj));
} else {
write(String.valueOf(obj));
}
|
public void | print(boolean b)Print a boolean value. The string produced by {@link
java.lang.String#valueOf(boolean)} is translated into bytes
according to the platform's default character encoding, and these bytes
are written in exactly the manner of the {@link
#write(int)} method.
if (writer != null) {
writer.write(b ? "true" : "false");
} else {
write(b ? "true" : "false");
}
|
public void | print(char c)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 {@link
#write(int)} method.
if (writer != null) {
writer.write(String.valueOf(c));
} else {
write(String.valueOf(c));
}
|
public void | println()Terminate the current line by writing the line separator string. The
line separator string is defined by the system property
line.separator , and is not necessarily a single newline
character ('\n' ).
newLine();
|
public void | println(boolean x)Print a boolean value and then terminate the line. This method behaves
as though it invokes {@link #print(boolean)} and then
{@link #println()} .
print(x);
println();
|
public void | println(char x)Print a character and then terminate the line. This method behaves as
though it invokes {@link #print(char)} and then
{@link #println()} .
print(x);
println();
|
public void | println(int x)Print an integer and then terminate the line. This method behaves as
though it invokes {@link #print(int)} and then
{@link #println()} .
print(x);
println();
|
public void | println(long x)Print a long integer and then terminate the line. This method behaves
as though it invokes {@link #print(long)} and then
{@link #println()} .
print(x);
println();
|
public void | println(float x)Print a floating-point number and then terminate the line. This method
behaves as though it invokes {@link #print(float)} and then
{@link #println()} .
print(x);
println();
|
public void | println(double x)Print a double-precision floating-point number and then terminate the
line. This method behaves as though it invokes {@link
#print(double)} and then {@link #println()} .
print(x);
println();
|
public void | println(char[] x)Print an array of characters and then terminate the line. This method
behaves as though it invokes {@link #print(char[])} and
then {@link #println()} .
print(x);
println();
|
public void | println(java.lang.String x)Print a String and then terminate the line. This method behaves as
though it invokes {@link #print(String)} and then
{@link #println()} .
print(x);
println();
|
public void | println(java.lang.Object x)Print an Object and then terminate the line. This method behaves as
though it invokes {@link #print(Object)} and then
{@link #println()} .
print(x);
println();
|
private void | reAllocBuff(int len)Reallocates buffer since the spec requires it to be unbounded.
if (bufferSize + len <= cb.length) {
bufferSize = cb.length;
return;
}
if (len < cb.length) {
len = cb.length;
}
bufferSize = cb.length + len;
char[] tmp = new char[bufferSize];
System.arraycopy(cb, 0, tmp, 0, cb.length);
cb = tmp;
tmp = null;
|
void | setWriter(java.io.Writer writer)Sets the writer to which all output is written.
this.writer = writer;
if (writer != null) {
// According to the spec, the JspWriter returned by
// JspContext.pushBody(java.io.Writer writer) must behave as
// though it were unbuffered. This means that its getBufferSize()
// must always return 0. The implementation of
// JspWriter.getBufferSize() returns the value of JspWriter's
// 'bufferSize' field, which is inherited by this class.
// Therefore, we simply save the current 'bufferSize' (so we can
// later restore it should this BodyContentImpl ever be reused by
// a call to PageContext.pushBody()) before setting it to 0.
if (bufferSize != 0) {
bufferSizeSave = bufferSize;
bufferSize = 0;
}
} else {
bufferSize = bufferSizeSave;
clearBody();
}
|
public void | write(int c)Write a single character.
if (writer != null) {
writer.write(c);
} else {
ensureOpen();
if (nextChar >= bufferSize) {
reAllocBuff (1);
}
cb[nextChar++] = (char) c;
}
|
public void | write(char[] cbuf, int off, int len)Write a portion of an array of characters.
Ordinarily this method stores characters from the given array into
this stream's buffer, flushing the buffer to the underlying stream as
needed. If the requested length is at least as large as the buffer,
however, then this method will flush the buffer and write the characters
directly to the underlying stream. Thus redundant
DiscardableBufferedWriter s will not copy data
unnecessarily.
if (writer != null) {
writer.write(cbuf, off, len);
} else {
ensureOpen();
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
if (len >= bufferSize - nextChar)
reAllocBuff (len);
System.arraycopy(cbuf, off, cb, nextChar, len);
nextChar+=len;
}
|
public void | write(char[] buf)Write an array of characters. This method cannot be inherited from the
Writer class because it must suppress I/O exceptions.
if (writer != null) {
writer.write(buf);
} else {
write(buf, 0, buf.length);
}
|
public void | write(java.lang.String s, int off, int len)Write a portion of a String.
if (writer != null) {
writer.write(s, off, len);
} else {
ensureOpen();
if (len >= bufferSize - nextChar)
reAllocBuff(len);
s.getChars(off, off + len, cb, nextChar);
nextChar += len;
}
|
public void | write(java.lang.String s)Write a string. This method cannot be inherited from the Writer class
because it must suppress I/O exceptions.
if (writer != null) {
writer.write(s);
} else {
write(s, 0, s.length());
}
|
public void | writeOut(java.io.Writer out)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.
if (writer == null) {
out.write(cb, 0, nextChar);
// Flush not called as the writer passed could be a BodyContent and
// it doesn't allow to flush.
}
|