org.xins.common.io
Class FastStringWriter

java.lang.Object
  extended byjava.io.Writer
      extended byorg.xins.common.io.FastStringWriter

public class FastStringWriter
extends Writer

A non-synchronized equivalent of StringWriter. This class implements a character stream that collects its output in a fast, unsynchronized string buffer, which can then be used to construct a string.

Instances of this class are not thread-safe.

Since:
XINS 1.0.0
Version:
$Revision: 1.16 $ $Date: 2006/08/28 09:12:34 $
Author:
Ernst de Haan

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
FastStringWriter()
          Creates a new FastStringWriter using a default initial internal buffer size.
FastStringWriter(int initialSize)
          Creates a new FastStringWriter using a specified initial string buffer size.
 
Method Summary
 void close()
          Closes this writer.
 void flush()
          Flushes this writer.
 FastStringBuffer getBuffer()
          Returns the underlying string buffer itself.
 String toString()
          Returns the current value of the underlying buffer as a string.
 void write(char[] cbuf)
          Writes an array of characters.
 void write(char[] cbuf, int off, int len)
          Writes a portion of an array of characters.
 void write(int c)
          Writes a single character.
 void write(String str)
          Writes a character string.
 void write(String str, int off, int len)
          Writes a portion of a character string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastStringWriter

public FastStringWriter()
Creates a new FastStringWriter using a default initial internal buffer size.


FastStringWriter

public FastStringWriter(int initialSize)
                 throws IllegalArgumentException
Creates a new FastStringWriter using a specified initial string buffer size.

Parameters:
initialSize - the initial size of the buffer, must be >= 0.
Throws:
IllegalArgumentException - if initialSize < 0.
Method Detail

write

public void write(int c)
           throws IOException
Writes a single character.

Parameters:
c - the character to write.
Throws:
IOException - if this writer has been closed (see close()).

write

public void write(char[] cbuf)
           throws IOException,
                  IllegalArgumentException
Writes an array of characters.

Parameters:
cbuf - the array of characters to write, cannot be null.
Throws:
IOException - if this writer has been closed (see close()).
IllegalArgumentException - if cbuf == null.

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IllegalArgumentException,
                  IOException,
                  IndexOutOfBoundsException
Writes a portion of an array of characters.

Parameters:
cbuf - the array of characters to write a portion of, cannot be null.
off - offset from which to start writing characters, must be >= 0 and < sbuf.length.
len - the number of characters to write.
Throws:
IOException - if this writer has been closed (see close()).
IllegalArgumentException - if cbuf == null.
IndexOutOfBoundsException - if the offset and/or the length is invalid.

write

public void write(String str)
           throws IOException,
                  IllegalArgumentException
Writes a character string.

Parameters:
str - the character string to write, cannot be null.
Throws:
IOException - if this writer has been closed (see close()).
IllegalArgumentException - if str == null.

write

public void write(String str,
                  int off,
                  int len)
           throws IllegalArgumentException,
                  IOException,
                  IndexOutOfBoundsException
Writes a portion of a character string.

Parameters:
str - the character string to write a portion of, cannot be null.
off - offset from which to start writing characters, must be >= 0 and < str.length().
len - the number of characters to write.
Throws:
IOException - if this writer has been closed (see close()).
IllegalArgumentException - if str == null.
IndexOutOfBoundsException - if the offset and/or the length is invalid.

flush

public void flush()
           throws IOException
Flushes this writer.

The implementation of this method does not nothing except checking that this writer is not yet closed.

Throws:
IOException - if this writer has been closed (see close()).

close

public void close()
Closes this writer. If this writer was already closed, then nothing happens. After calling this method, the write and flush methods will throw an IOException if called.

Calling this method on a FastStringWriter after use is really optional.


toString

public String toString()
Returns the current value of the underlying buffer as a string.

Returns:
the current string, not null.

getBuffer

public FastStringBuffer getBuffer()
Returns the underlying string buffer itself.

Returns:
the underlying string buffer, not null.


See http://www.xins.org/.