|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Writer
org.barracudamvc.plankton.io.BetterPipedWriter
public class BetterPipedWriter
This class is based on Sun's PipedWriter. It attempts to address 2 deficiencies in the Sun implementation: the PIPE_SIZE is configurable, and if we get a dewadlock on the writer (because the pipe size has been reached) then the writer will timeout after a certain amount of time. This is important in a servlet environment, where one request may start a writer pumping data into the sink, but you have no guarantee that anyone is going to actually read the data from the sink. Using the Sun implementation, the writer deadlocks and that thread is completely out of action for the duration...not very robust behavior for a servlet environment. This implementation will gracefully timeout, allowing the thread to complete and be returned to the servlet container for further use. Note that we completely reimplement these classes because the Sun classes weren't really designed to be extended (grrr).
Field Summary | |
---|---|
protected boolean |
closed
|
protected static org.apache.log4j.Logger |
logger
|
protected BetterPipedReader |
sink
|
Fields inherited from class java.io.Writer |
---|
lock |
Constructor Summary | |
---|---|
BetterPipedWriter()
Creates a piped writer that is not yet connected to a piped reader. |
|
BetterPipedWriter(BetterPipedReader snk)
Creates a piped writer connected to the specified piped reader. |
Method Summary | |
---|---|
void |
close()
Closes this piped output stream and releases any system resources associated with this stream. |
void |
connect(BetterPipedReader snk)
Connects this piped writer to a receiver. |
void |
flush()
Flushes this output stream and forces any buffered output characters to be written out. |
void |
write(char[] cbuf,
int off,
int len)
Writes len characters from the specified character array
starting at offset off to this piped output stream. |
void |
write(int c)
Writes the specified char to the piped output stream. |
Methods inherited from class java.io.Writer |
---|
append, append, append, write, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final org.apache.log4j.Logger logger
protected BetterPipedReader sink
protected boolean closed
Constructor Detail |
---|
public BetterPipedWriter(BetterPipedReader snk) throws IOException
snk
.
snk
- The piped reader to connect to.
IOException
- if an I/O error occurs.public BetterPipedWriter()
PipedReader.connect(java.io.PipedWriter)
,
PipedWriter.connect(java.io.PipedReader)
Method Detail |
---|
public void connect(BetterPipedReader snk) throws IOException
IOException
is thrown.
If snk
is an unconnected piped reader and
src
is an unconnected piped writer, they may
be connected by either the call:
or the call:src.connect(snk)
The two calls have the same effect.snk.connect(src)
snk
- the piped reader to connect to.
IOException
- if an I/O error occurs.public void write(int c) throws IOException
char
to the piped output stream.
If a thread was reading data characters from the connected piped input
stream, but the thread is no longer alive, then an
IOException
is thrown.
Implements the write
method of Writer
.
write
in class Writer
c
- the char
to be written.
IOException
- if an I/O error occurs.public void write(char[] cbuf, int off, int len) throws IOException
len
characters from the specified character array
starting at offset off
to this piped output stream.
If a thread was reading data characters from the connected piped input
stream, but the thread is no longer alive, then an
IOException
is thrown.
write
in class Writer
cbuf
- the data.off
- the start offset in the data.len
- the number of characters to write.
IOException
- if an I/O error occurs.public void flush() throws IOException
flush
in interface Flushable
flush
in class Writer
IOException
- if an I/O error occurs.public void close() throws IOException
close
in interface Closeable
close
in class Writer
IOException
- if an I/O error occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |