|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Writer
java.io.PrintWriter
org.apache.sling.engine.impl.output.BufferedPrintWriter
public class BufferedPrintWriter
The BufferedPrintWriter
implements buffering for the
PrintWriter
returned by the
ServletResponse.getWriter()
method.
We need this additional buffering class for the
ServletResponse.getWriter()
class because
we wrap the original
PrintWriter
retrieved from the servlet container with optional
caching and link checking writers.
This class overwrites all the base class's write methods, which are used as the base for writing. All other methods of the base class use the write methods after having formatted the parameter.
The buffer is flushed to the wrapped writer in the following cases :
flush()
method is called.
This class is not multithread safe as it is intended to be used on single requests which are assigned to single threads.
This extension to the PrintWriter
class does not support
automatic flush of the output buffer. That is, the println
method never ever flushes output.
Field Summary | |
---|---|
protected boolean |
closed
flag to indicate that the writer has been closed |
protected boolean |
loggedNoBuffering
|
protected boolean |
trouble
|
Fields inherited from class java.io.PrintWriter |
---|
out |
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
BufferedPrintWriter(PrintWriter servletWriter,
int bufferSize)
Creates an instance wrapping the PrintWriter and providing
an initial buffer size. |
Method Summary | |
---|---|
boolean |
checkError()
Flush the stream if it's not closed and check its error state. |
void |
close()
Closes the output after flushing the buffer contents to the wrapped writer. |
void |
flush()
Writes the contents of the buffer to the wrapped writer and flushes the latter. |
void |
flushBuffer()
Writes the contents of the buffer to the wrapped writer. |
int |
getBufferSize()
Returns the size of the buffer |
void |
println()
Terminate the current line by writing the line separator string without ever flushing the buffer. |
void |
resetBuffer()
Clears the buffer. |
void |
setBufferSize(int bufferSize)
Sets the buffer size. |
protected void |
setError()
Indicate that an error has occurred. |
void |
write(char[] buf,
int off,
int len)
Writes a portion of an array of characters. |
void |
write(int c)
Writes a single character. |
void |
write(String s,
int off,
int len)
Writes a portion of a string. |
Methods inherited from class java.io.PrintWriter |
---|
append, append, append, clearError, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected boolean trouble
checkError()
,
setError()
protected boolean closed
protected boolean loggedNoBuffering
Constructor Detail |
---|
public BufferedPrintWriter(PrintWriter servletWriter, int bufferSize)
PrintWriter
and providing
an initial buffer size.
The servletWriter
is to initially write data to.
The other use of the servletWriter
is to check for any
errors occurred by forwarding the call to the checkError()
to this
writer.
servletWriter
- The PrintWriter
to which data is
initially written.bufferSize
- The initial size of the buffer. If negative or zero
no buffering is initiallly done.Method Detail |
---|
public void setBufferSize(int bufferSize)
setBufferSize
in interface Buffer
bufferSize
- The new size of the buffer. If this value is less than
or equal to zero, buffering is disabled alltogether.
IllegalStateException
- if the buffer contains data.public int getBufferSize()
getBufferSize
in interface Buffer
public void resetBuffer()
resetBuffer
in interface Buffer
public void flushBuffer()
flushBuffer
in interface Buffer
public boolean checkError()
This implementation checks with the PrintWriter
used to
create this BufferedPrintWriter
.
checkError
in class PrintWriter
true
if the print stream has encountered an error,
either on the underlying output stream or during a format conversion.protected void setError()
setError
in class PrintWriter
public void flush()
flush
in interface Flushable
flush
in class PrintWriter
public void close()
close
in interface Closeable
close
in class PrintWriter
public void write(int c)
write
in class PrintWriter
c
- The character to write to the buffer.public void write(char[] buf, int off, int len)
If the number of characters is more than the buffer capacity, the buffer is flushed. Due to buffering it is not guaranteed that the complete number of characters is either buffered or written. It is acceptable for part of the characters to be written and the rest to be buffered.
write
in class PrintWriter
buf
- The characters to writeoff
- The starting offset into the character arraylen
- The number of characters to write starting with the offset.
NullPointerException
- if buf is null
IndexOutOfBoundsException
- if either or both off
and off+len
are outside of the bounds of the character
array buf
.public void write(String s, int off, int len)
If the number of characters is more than the buffer capacity, the buffer is flushed. Due to buffering it is not guaranteed that the complete number of characters is either buffered or written. It is acceptable for part of the characters to be written and the rest to be buffered.
write
in class PrintWriter
s
- The string to writeoff
- The starting offset into the stringlen
- The number of characters to write starting with the offset.
NullPointerException
- if s is null
IndexOutOfBoundsException
- if either or both off
and off+len
are outside of the bounds of the string
s
.public void println()
line.separator
, and is not necessarily a
single newline character ('\n'
).
This duplicates the functionality of the private of the
PrintWriter.newLine
method.
println
in class PrintWriter
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |