GXPARSE hosted by SourceForge.net Logo

ca.gorman.io
Class ResequencingWriterStack<K>

java.lang.Object
  extended by java.io.Writer
      extended by ca.gorman.io.WriterStack
          extended by ca.gorman.io.ResequencingWriterStack<K>
All Implemented Interfaces:
Resequencer<K>, Closeable, Flushable, Appendable

public class ResequencingWriterStack<K>
extends WriterStack
implements Resequencer<K>

A WriterStack that acts as a Resequencer when the Writer at top of stack is a Resequencer.


Nested Class Summary
 
Nested classes/interfaces inherited from interface ca.gorman.io.Resequencer
Resequencer.Buffer<K>, Resequencer.Mark<K>, Resequencer.MarkGroup<K>, Resequencer.SpillBuffer
 
Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
ResequencingWriterStack(ResequencingWriter<K> resequencingWriter)
           Construct new ResequencingWriterStack on a ResequencingWriter.
 
Method Summary
 void flush()
           Flush the WriterStack.
 Resequencer.Mark<K> getMark(K key)
           Get an existing Mark.
 Resequencer.MarkGroup<K> getMarkGroup()
           Get the MarkGroup used by this Resequencer.
 boolean isFlushThrowsException()
           Always returns false.
 Resequencer.Mark<K> mark()
           Create a Mark without a key.
 Resequencer.Mark<K> mark(K key)
           Get the Mark for a specific key, creating a new Mark if one does not already exist.
 void push(ResequencingWriter<K> writer)
           Push a ResequencingWriter on the ResequencingWriterStack.
 void setFlushThrowsException(boolean b)
           Unsupported operation.
 void write(Resequencer.Mark<K> mark)
          

Write a Mark representing data that will be supplied at some other time..

 void writeMark(K key)
          

Write a Mark representing data that will be supplied at some other time, creating a new Mark if one does not already exist..

 
Methods inherited from class ca.gorman.io.WriterStack
close, isEmpty, peek, pop, push, size, write, write, write, write, write
 
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

ResequencingWriterStack

public ResequencingWriterStack(ResequencingWriter<K> resequencingWriter)

Construct new ResequencingWriterStack on a ResequencingWriter.

Throws:
NullPointerException - when writer is null;
Method Detail

push

public void push(ResequencingWriter<K> writer)
          throws IOException

Push a ResequencingWriter on the ResequencingWriterStack. 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.

Throws:
NullPointerException - when writer is null;
IOException - if the Writer previously at top of stack throws the exception when flushed.
IllegalArgumentException - when the ResequencingWriter does not have the same MarkGroup as the ResequencingWriterStack.

getMarkGroup

public Resequencer.MarkGroup<K> getMarkGroup()
Description copied from interface: Resequencer

Get the MarkGroup used by this Resequencer.

Specified by:
getMarkGroup in interface Resequencer<K>

getMark

public Resequencer.Mark<K> getMark(K key)
Description copied from interface: Resequencer

Get an existing Mark.

This method should be delegated to the Buffer that supports the Resequencer.

Specified by:
getMark in interface Resequencer<K>

mark

public Resequencer.Mark<K> mark()
Description copied from interface: Resequencer

Create a Mark without a key. This method returns a new Mark each time it is invoked. The only way to obtain the same Mark again is to assign it to a variable for later use.

This method should be delegated to the Buffer that supports the Resequencer.

Specified by:
mark in interface Resequencer<K>

mark

public Resequencer.Mark<K> mark(K key)
Description copied from interface: Resequencer

Get the Mark for a specific key, creating a new Mark if one does not already exist. This method returns the same Mark each time it is invoked with the same key.

This method should be delegated to the Buffer that supports the Resequencer.

Specified by:
mark in interface Resequencer<K>
Parameters:
key - Identifies the mark to be retrieved or created

writeMark

public void writeMark(K key)
               throws IOException

Write a Mark representing data that will be supplied at some other time, creating a new Mark if one does not already exist. The Mark will be replaced by data when this Resequencer is closed.

This method should be delegated to the Buffer that supports the Resequencer..

Specified by:
writeMark in interface Resequencer<K>
Parameters:
key - the key that identifies the place mark within the MarkGroup used by this Resequencer
Throws:
ClassCastException - when the Writer at top of stack is not a Resequencer or a NullOutputWriter.
IOException

write

public void write(Resequencer.Mark<K> mark)
           throws IOException

Write a Mark representing data that will be supplied at some other time. The Mark will be replaced by data when this Resequencer is closed.

This method should be delegated to the Buffer that supports the Resequencer..

Specified by:
write in interface Resequencer<K>
Parameters:
mark - The Mark to be written,
Throws:
ClassCastException - when the Writer at top of stack is not a Resequencer or a NullOutputWriter.
IOException

flush

public void flush()
           throws IOException
Description copied from class: WriterStack

Flush the WriterStack.

Writers below the top of stack are already flushed by the push operation, so only the top Writer will be flushed.

Specified by:
flush in interface Flushable
Overrides:
flush in class WriterStack
Throws:
IOException

isFlushThrowsException

public boolean isFlushThrowsException()

Always returns false.

Indicate whether flush will throw UnsupportedOperationException or fail silently (the default). A Resequencer cannot be flushed because it retains all data until the supporting Writer is closed..

Specified by:
isFlushThrowsException in interface Resequencer<K>
Returns:
true if flush will throw UnsupportedOperationException, false if flush will be ignored.
See Also:
Resequencer.setFlushThrowsException(boolean)

setFlushThrowsException

public void setFlushThrowsException(boolean b)

Unsupported operation.

Choose whether flush will throw UnsupportedOperationException or fail silently (the default). A Resequencer cannot be flushed because it retains all data until the supporting Writer is closed..

Specified by:
setFlushThrowsException in interface Resequencer<K>
Parameters:
b - true to throw UnsupportedOperationException, false (default) to simply ignore flush.
Throws:
UnsupportedOperationException - when invoked.
See Also:
Resequencer.isFlushThrowsException()

GXPARSE download

GXPARSE Generic XML Stream Parser API and supporting tools.   Release $Name: gxparse-sf-alpha-2_0 $
Copyright 2003-2004 Ian E. Gorman
Released under GNU Lesser General Public License