tribble.io
Class SuspendableWriter

java.lang.Object
  extended by java.io.Writer
      extended by tribble.io.SuspendableWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable, SuspendableWriterI

public class SuspendableWriter
extends java.io.Writer
implements SuspendableWriterI

A character output stream that can be suspended and resumed.

This is a default implementation of a character output stream that can be suspended and resumed (see SuspendableWriterI), based on the standard Writer class. It provides the capability of suspending all output written to the stream, so that subsequent write requests perform no output. It also has the capability of resuming all output written to the stream.

Since:
2001-06-21
Version:
$Revision: 1.1 $ $Date: 2001/09/01 17:59:40 $
Author:
David R. Tribble, david@tribble.com.
Copyright 2001 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.
See Also:
Writer

Field Summary
protected static java.lang.String EXCEPT_CLOSED
          Exception text contents for a closed output stream.
protected  java.io.Writer m_out
          Underlying output stream.
protected  java.io.Writer m_sus
          Suspended underlying output stream.
(package private) static java.lang.String REV
          Revision information.
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
SuspendableWriter()
          Constructor.
SuspendableWriter(java.io.Writer out)
          Constructor.
 
Method Summary
 void close()
          Closes this output stream.
protected  void finalize()
          Finalization.
 void flush()
          Flushes any pending output to the output stream.
 java.io.Writer getOutput()
          Retrieves the underlying output stream to which all output for this stream is written.
 boolean isSuspended()
          Determines if this output stream is suspended or not.
 void resume()
          Resumes subsequent output written to this output stream.
 void setOutput(java.io.Writer out)
          Establishes the underlying output stream to which all output for this stream is written.
 void suspend()
          Suspends subsequent output written to this output stream.
 void write(char[] cbuf)
          Writes the contents of a character array to this output stream.
 void write(char[] cbuf, int off, int len)
          Writes a portion of a character array to this output stream.
 void write(int c)
          Writes a single character to this output stream.
 void write(java.lang.String str)
          Writes the contents of a string to this output stream.
 void write(java.lang.String str, int off, int len)
          Writes a subset of a string to this output stream.
 
Methods inherited from class java.io.Writer
append, append, append
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values

EXCEPT_CLOSED

protected static final java.lang.String EXCEPT_CLOSED
Exception text contents for a closed output stream.

See Also:
Constant Field Values

m_out

protected java.io.Writer m_out
Underlying output stream.


m_sus

protected java.io.Writer m_sus
Suspended underlying output stream.

Constructor Detail

SuspendableWriter

public SuspendableWriter()
Constructor.

Since:
1.1, 2001-06-21

SuspendableWriter

public SuspendableWriter(java.io.Writer out)
Constructor. Establishes the underlying output stream to which all output for this stream is written.

Parameters:
out - The underlying output stream for this stream.
Since:
1.1, 2001-06-21
Method Detail

suspend

public void suspend()
Suspends subsequent output written to this output stream.

Output to this stream can be resumed by calling resume().

This method may be called multiple times without any intervening call to resume() without any ill effects.

Specified by:
suspend in interface SuspendableWriterI
Since:
1.1, 2001-06-21
See Also:
resume()

resume

public void resume()
Resumes subsequent output written to this output stream.

Output to this stream can be suspended by calling suspend().

This method may be called multiple times without any previous or intervening call to suspend() without any ill effects.

Specified by:
resume in interface SuspendableWriterI
Since:
1.1, 2001-06-21
See Also:
suspend()

isSuspended

public boolean isSuspended()
Determines if this output stream is suspended or not.

Specified by:
isSuspended in interface SuspendableWriterI
Returns:
True if this output stream is currently suspended, otherwise false.
Since:
1.1, 2001-09-01
See Also:
suspend()

close

public void close()
           throws java.io.IOException
Closes this output stream.

Note that this method is required to flush and close the underlying output stream of this stream. Any writes subsequent to closing this stream should throw an IOException exception.

Specified by:
close in interface java.io.Closeable
Specified by:
close in interface SuspendableWriterI
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException - Thrown if an output error occurs.
Since:
1.1, 2001-06-21

flush

public void flush()
           throws java.io.IOException
Flushes any pending output to the output stream.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException - Thrown if an output error occurs.
Since:
1.1, 2001-06-21

write

public void write(char[] cbuf)
           throws java.io.IOException
Writes the contents of a character array to this output stream.

Overrides:
write in class java.io.Writer
Parameters:
cbuf - A character buffer to write.
Throws:
java.io.IOException - Thrown if an output error occurs, or if this output stream is closed.
Since:
1.1, 2001-06-21

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Writes a portion of a character array to this output stream.

Specified by:
write in class java.io.Writer
Parameters:
cbuf - A character buffer, from which a subset of characters is written.
off - The offset of the first character within character buffer cbuf to write.
len - The number of characters from character buffer cbuf to write.
Throws:
java.io.IOException - Thrown if an output error occurs, or if this output stream is closed.
Since:
1.1, 2001-06-21

write

public void write(java.lang.String str)
           throws java.io.IOException
Writes the contents of a string to this output stream.

Overrides:
write in class java.io.Writer
Parameters:
str - A string to write.
Throws:
java.io.IOException - Thrown if an output error occurs, or if this output stream is closed.
Since:
1.1, 2001-06-21

write

public void write(java.lang.String str,
                  int off,
                  int len)
           throws java.io.IOException
Writes a subset of a string to this output stream.

Overrides:
write in class java.io.Writer
Parameters:
str - A string containing the substring to write.
off - The offset of the first character within the string to write.
len - The number of characters from the substring to write.
Throws:
java.io.IOException - Thrown if an output error occurs, or if this output stream is closed.
Since:
1.1, 2001-06-21

write

public void write(int c)
           throws java.io.IOException
Writes a single character to this output stream.

Overrides:
write in class java.io.Writer
Parameters:
c - A character code to write.
Throws:
java.io.IOException - Thrown if an output error occurs, or if this output stream is closed.
Since:
1.1, 2001-06-21

setOutput

public void setOutput(java.io.Writer out)
Establishes the underlying output stream to which all output for this stream is written.

Parameters:
out - The underlying output stream for this stream.
Since:
1.1, 2001-06-21

getOutput

public java.io.Writer getOutput()
Retrieves the underlying output stream to which all output for this stream is written.

Returns:
The underlying output stream of this stream.
Since:
1.1, 2001-06-21

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalization.

Flushes, but does not close, the underlying output stream (if there is one), and then disassociates it from this output stream.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable - Thrown if an error occurs.
Since:
1.1, 2001-06-21