GXPARSE hosted by SourceForge.net Logo

ca.gorman.io
Class Resequencer.Buffer<K>

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

public abstract static class Resequencer.Buffer<K>
extends Writer

Buffer to hold Marks with keys of type K and character data until all character data have been written, and all Marks have been associated with data values.

A Buffer contains a fast primary buffer with limited capacity aand spills the overflow to a slower secondary buffer that has unlimited capacity.


Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
protected Resequencer.Buffer(Writer writer, Resequencer.MarkGroup<K> markGroup)
           Superclass constructor for use by subclass constructor.
protected Resequencer.Buffer(Writer writer, Resequencer.MarkGroup<K> markGroup, int bufferSize, Resequencer.SpillBuffer spillBuffer)
           Superclass constructor for use by subclass constructor.
 
Method Summary
 void close()
           Close this Buffer and send output to final destination.
 void flush()
           Unsupported operation.
 Resequencer.Mark<K> getMark(K key)
           Get an existing Mark.
 Resequencer.MarkGroup<K> getMarkGroup()
           Get the MarkGroup that serves this Buffer.
protected  boolean isClosed()
           Indicate whether this Buffer is closed.
protected  boolean isSpilling()
           Indicate whether the fast buffer has filled and the overflow buffer contains data.
 Resequencer.Mark<K> mark()
           Create a Mark without a key.
 Resequencer.Mark<K> mark(K key)
           Get the Mark coresponding to a key, creating the Mark if it does not already exist.
static
<K> Resequencer.Buffer<K>
newInstance(Writer writer, Resequencer.MarkGroup<K> markGroup)
           Create a new Buffer using defaults for the fast buffer and the overflow buffer.
static
<K> Resequencer.Buffer<K>
newInstance(Writer writer, Resequencer.MarkGroup<K> markGroup, int bufferSize, Resequencer.SpillBuffer spillBuffer)
           Create a new Buffer specifying the fast buffer and the overflow buffer.
 void write(char[] cbuf, int off, int len)
           Write data to the Buffer.
 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 the Mark if it does not exist.
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resequencer.Buffer

protected Resequencer.Buffer(Writer writer,
                             Resequencer.MarkGroup<K> markGroup)

Superclass constructor for use by subclass constructor. Uses a default sized memory block as the primary buffer and a temporary file as the secondary buffer for overflow from the primary buffer. The default memory block size is chosen for good performance when a small number of Resequencers are in use, and some of them may hold large amounts of data.

Parameters:
markGroup - The MarkGroup that this Buffer will use.
writer - The final destination for output when this this Buffer is closed.
Throws:
NullPointerException - if writer or markGroup is null

Resequencer.Buffer

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

Superclass constructor for use by subclass constructor. Uses a memory block as the primary buffer and a secondary buffer for overflow from the primary buffer.

Parameters:
markGroup - The MarkGroup that this Buffer will use.
writer - The final destination for output when this this Buffer is closed.
bufferSize - Number of characters to allocate in memory as a primary buffer.
spillBuffer - the secondary buffer for overflow from the primary buffer.
Throws:
NullPointerException - if writer, markGroup or spillBuffer is null
IllegalArgumentException - if bufferSize < 0
Method Detail

newInstance

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

Create a new Buffer specifying the fast buffer and the overflow buffer.

Parameters:
writer - The Writer that serves as a final destination for output.
markGroup - The MarkGroup used by the Buffer
bufferSize - Size of fast buffer.
spillBuffer - the overflow buffer.
Throws:
NullPointerException - if writer, markGroup or spillBuffer is null
IllegalArgumentException - if bufferSize < 0

newInstance

public static <K> Resequencer.Buffer<K> newInstance(Writer writer,
                                                    Resequencer.MarkGroup<K> markGroup)

Create a new Buffer using defaults for the fast buffer and the overflow buffer.

Parameters:
writer - The Writer that serves as a final destination for output.
markGroup - The MarkGroup used by the Buffer
Throws:
NullPointerException - if writer or markGroup is null

getMarkGroup

public Resequencer.MarkGroup<K> getMarkGroup()

Get the MarkGroup that serves this Buffer.


flush

public void flush()
           throws IOException

Unsupported operation. This Buffer cannot be flushed because it holds Marks and allows them to be updated at any time prior to closing this Buffer

Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
UnsupportedOperationException
IOException

close

public void close()
           throws IOException

Close this Buffer and send output to final destination. When a subclass method overrides this method, the subclass method must invoke the superclass method.

Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

getMark

public Resequencer.Mark<K> getMark(K key)

Get an existing Mark.

Throws:
NoSuchElementException - if the Mark does not exist.

mark

public Resequencer.Mark<K> mark()

Create a Mark without a key.


mark

public Resequencer.Mark<K> mark(K key)

Get the Mark coresponding to a key, creating the Mark if it does not already exist.

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 the Mark if it does not exist. The Mark will be replaced by data when this Buffer is closed.

Parameters:
key - the key that identifies the place mark within the MarkGroup used by this Buffer
Throws:
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.

Parameters:
mark - The Mark to be written,
Throws:
NullPointerException - if mark is null
IOException

write

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

Write data to the Buffer.

Specified by:
write in class Writer
Throws:
IOException

isClosed

protected boolean isClosed()

Indicate whether this Buffer is closed.


isSpilling

protected boolean isSpilling()

Indicate whether the fast buffer has filled and the overflow buffer contains data.


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