|
GXPARSE hosted by |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.Writer
ca.gorman.io.WriterStack
public class WriterStack
A Writer with additional methods to support nested temporary redirection of the output destination.
WriterStack supports multilevel temporary redirection of
output. A stack of Writer objects is itself a Writer and all of its
output methods are delegated to the Writer at the top of the stack. That
Writer is the current destination. A reference to the stack is always
a reference to the current destination, even as the current destination is
changed by pushing and popping Writers.
Pushing a Writer
on WriterStack makes the new Writer the
destination of all output to WriterStack.
Popping the Writer from
WriterStack restores the previous Writer as the
output destination.
All of the Writers below top of stack are maintained in a flushed state to
ensure that the sequence of output from the Writers will be identical to the
sequence of input to the WriterStack. This invariant is maintained by
causing each push and pop to flush the top of stack before adding or
removing a Writer. However, the invariant is violated when a
ResequencingWriter is on the WriterStack, because
the ResequencingWriter flush violates
the contract of Writer.flush.
WriterStack always has a destination because the default
Writer becomes the current destination when the stack is empty.
| Field Summary |
|---|
| Fields inherited from class java.io.Writer |
|---|
lock |
| Constructor Summary | |
|---|---|
WriterStack(Writer writer)
Create new WriterStack with a default Writer. |
|
| Method Summary | |
|---|---|
void |
close()
Close all Writers on the WriterStack. |
void |
flush()
Flush the WriterStack. |
boolean |
isEmpty()
Test if stack is empty. |
protected Writer |
peek()
Return the Writer (and current destination) at the top of WriterStack. |
Writer |
pop()
Pop and return the Writer at the top of WriterStack. |
void |
push(Writer writer)
Push a Writer on the WriterStack. |
int |
size()
Get the number of Writers currently pushed on the WriterStack. |
void |
write(char[] ch)
Write an array of characters to the current destination. |
void |
write(char[] ch,
int offset,
int length)
Write a subarray of characters to the current destination. |
void |
write(int ch)
Write one character to the current destination. |
void |
write(String str)
Write a string to the current destination. |
void |
write(String str,
int offset,
int length)
Write a substring to the current destination. |
| Methods inherited from class java.io.Writer |
|---|
append, append, append |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WriterStack(Writer writer)
Create new WriterStack with a default Writer. The default destination is the current destination when the WriterStack is empty.
NullPointerException - when writer is null;| Method Detail |
|---|
public void push(Writer writer)
throws IOException
Push a Writer on the WriterStack. The Writer currently at top of stack will be flushed before the new Writer is pushed.
The new Writer becomes the output destination, until the previous destination is restored by popping the new Writer.
NullPointerException - when writer is null;
IOException - if the Writer previously at top of stack throws
the exception when flushed.
public Writer pop()
throws EmptyStackException,
IOException
Pop and return the Writer at the top of WriterStack. The Writer will be flushed before it is popped.
The Writer under the popped Writer will become the destination.
EmptyStackException - when there is the only remaining
destination is the Default Writer (which cannot be popped).
IOException - if the Writer currently at top of stack throws
the exception when flushed.
UnsupportedOperationException - when writer is a
Resequencer and
Resequencer.isFlushThrowsException() returns
true;protected Writer peek()
Return the Writer (and current destination) at the top of WriterStack.
public boolean isEmpty()
Test if stack is empty. The Writer used to construct WriterStack cannot be popped, so this method will return true when the only Writer is the default Writer.
public int size()
Get the number of Writers currently pushed on the WriterStack. The Default Writer is not included in the count.
public void close()
throws IOException
Close all Writers on the WriterStack.
All the Writers will remain on the WriterStack until they are popped.
close in interface Closeableclose in class WriterIOException
public void flush()
throws IOException
Flush the WriterStack.
Writers below the top of stack are already flushed by
the push operation, so only the top
Writer will be flushed.
flush in interface Flushableflush in class WriterIOException
public void write(int ch)
throws IOException
Write one character to the current destination.
write in class WriterIOException
public void write(char[] ch)
throws IOException
Write an array of characters to the current destination.
write in class WriterIOException
public void write(char[] ch,
int offset,
int length)
throws IOException
Write a subarray of characters to the current destination.
write in class WriterIOException
public void write(String str)
throws IOException
Write a string to the current destination.
write in class WriterIOException
public void write(String str,
int offset,
int length)
throws IOException
Write a substring to the current destination.
write in class WriterIOException
|
GXPARSE download | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||