GXPARSE hosted by SourceForge.net Logo

ca.gorman.io
Class ResequencingWriter<K>

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

public class ResequencingWriter<K>
extends Writer
implements Resequencer<K>

A Writer that is a Resequencer with the capacity to accept data in a sequence that differs from the sequence of actual output.

Warning: ResequencingWriterStack violates the Writer contract because a Resequencer cannot be flushed.


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
ResequencingWriter(Writer writer)
           Construct with a private internal MarkGroup and default temporary stoage.
ResequencingWriter(Writer writer, int bufferSize, Resequencer.SpillBuffer spillBuffer)
           Construct with a private internal MarkGroup and specified temporary storage.
ResequencingWriter(Writer writer, Resequencer.MarkGroup<K> markGroup)
           Construct with an external MarkGroup and default temporary storage.
ResequencingWriter(Writer writer, Resequencer.MarkGroup<K> markGroup, int bufferSize, Resequencer.SpillBuffer spillBuffer)
           Construct with an external MarkGroup and specified temporary storage.
 
Method Summary
 void close()
           Send all data to final destination.
 void flush()
           Unsupported operation, failure mode depends on isFlushThrowsException.
 Resequencer.Mark<K> getMark(K key)
           Get an existing Mark.
 Resequencer.MarkGroup<K> getMarkGroup()
           Get the MarkGroup used by this Resequencer.
 boolean isFlushThrowsException()
           Indicate whether flush will throw UnsupportedOperationException or fail silently (the default).
 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 setFlushThrowsException(boolean b)
           Choose whether flush will throw UnsupportedOperationException or fail silently (the default).
 void write(char[] ch, int off, int len)
           Write len chars of an array, beginning from char[off].
 void write(int ch)
           Write one char.
 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 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
 

Constructor Detail

ResequencingWriter

public ResequencingWriter(Writer writer,
                          Resequencer.MarkGroup<K> markGroup,
                          int bufferSize,
                          Resequencer.SpillBuffer spillBuffer)

Construct with an external MarkGroup and specified temporary storage. ResequencingWriter will throw an exception if closed before the MarkGroup has been closed.

Parameters:
writer - destination for output from this Writer
markGroup - an external MarkGroup
spillBuffer - a "spill" buffer to hold overflow from the memory buffer
bufferSize - maximum size of the internal memory buffer
Throws:
NullPointerException - if writer is null.
NullPointerException - if markGroup is null.
IllegalArgumentException - if memoryLimit < 0
NullPointerException - if spillBuffer is null.

ResequencingWriter

public ResequencingWriter(Writer writer,
                          Resequencer.MarkGroup<K> markGroup)

Construct with an external MarkGroup and default temporary storage. ResequencingWriter will throw an exception if closed before the MarkGroup has been closed.

Parameters:
writer - destination for output from this Writer
markGroup - an external MarkGroup
Throws:
NullPointerException - if writer is null or markGroup is null
See Also:
Resequencer.MarkGroup, Resequencer.Mark

ResequencingWriter

public ResequencingWriter(Writer writer,
                          int bufferSize,
                          Resequencer.SpillBuffer spillBuffer)

Construct with a private internal MarkGroup and specified temporary storage. ResequencingWriter will close the internal MarkGroup automatically at the appropriate time.

Parameters:
writer - destination for output from this Writer
spillBuffer - a "spill" buffer to hold overflow from the memory buffer
bufferSize - maximum size of the internal memory buffer
Throws:
NullPointerException - if writer is null.
IllegalArgumentException - if memoryLimit < 0
NullPointerException - if spillBuffer is null.

ResequencingWriter

public ResequencingWriter(Writer writer)

Construct with a private internal MarkGroup and default temporary stoage. ResequencingWriter will close the internal MarkGroup automatically at the appropriate time.

Parameters:
writer - destination for output from this Writer
Throws:
NullPointerException - if writer is null.
Method Detail

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
Description copied from interface: Resequencer

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:
IOException

write

public void write(Resequencer.Mark<K> mark)
           throws IOException
Description copied from interface: Resequencer

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:
IOException

write

public void write(char[] ch,
                  int off,
                  int len)
           throws IOException

Write len chars of an array, beginning from char[off].

Specified by:
write in class Writer
Throws:
IOException

write

public void write(int ch)
           throws IOException

Write one char. The value written is the 16 lowest-order bits of ch.

Overrides:
write in class Writer
Throws:
IOException

close

public void close()
           throws IOException

Send all data to final destination. A second pass is made through all the data, replacing all markers by the current data values in the corresponding mark buffers.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException - when an I/O error occurs, or when the MarkGroup had not been closed.

flush

public void flush()
           throws IOException

Unsupported operation, failure mode depends on isFlushThrowsException.

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
UnsupportedOperationException - when this method is invoked and isFlushThrowsException returns true.
IOException
See Also:
isFlushThrowsException(), setFlushThrowsException(boolean)

isFlushThrowsException

public boolean isFlushThrowsException()
Description copied from interface: Resequencer

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)
Description copied from interface: Resequencer

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.
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