Save This Page
Home » openjdk-7 » java » io » [javadoc | source]
java.io
public class: CharArrayWriter [javadoc | source]
java.lang.Object
   java.io.Writer
      java.io.CharArrayWriter

All Implemented Interfaces:
    Flushable, Closeable, Appendable

This class implements a character buffer that can be used as an Writer. The buffer automatically grows when data is written to the stream. The data can be retrieved using toCharArray() and toString().

Note: Invoking close() on this class has no effect, and methods of this class can be called after the stream has closed without generating an IOException.

Field Summary
protected  char[] buf    The buffer where data is stored. 
protected  int count    The number of chars in the buffer. 
Fields inherited from java.io.Writer:
lock
Constructor:
 public CharArrayWriter() 
 public CharArrayWriter(int initialSize) 
Method from java.io.CharArrayWriter Summary:
append,   append,   append,   close,   flush,   reset,   size,   toCharArray,   toString,   write,   write,   write,   writeTo
Methods from java.io.Writer:
append,   append,   append,   close,   flush,   write,   write,   write,   write,   write
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from java.io.CharArrayWriter Detail:
 public CharArrayWriter append(CharSequence csq) 
    Appends the specified character sequence to this writer.

    An invocation of this method of the form out.append(csq) behaves in exactly the same way as the invocation

        out.write(csq.toString()) 

    Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

 public CharArrayWriter append(char c) 
    Appends the specified character to this writer.

    An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

        out.write(c) 
 public CharArrayWriter append(CharSequence csq,
    int start,
    int end) 
    Appends a subsequence of the specified character sequence to this writer.

    An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

        out.write(csq.subSequence(start, end).toString()) 
 public  void close() 
    Close the stream. This method does not release the buffer, since its contents might still be required. Note: Invoking this method in this class will have no effect.
 public  void flush() 
    Flush the stream.
 public  void reset() 
    Resets the buffer so that you can use it again without throwing away the already allocated buffer.
 public int size() 
    Returns the current size of the buffer.
 public char[] toCharArray() 
    Returns a copy of the input data.
 public String toString() 
    Converts input data to a string.
 public  void write(int c) 
    Writes a character to the buffer.
 public  void write(char[] c,
    int off,
    int len) 
    Writes characters to the buffer.
 public  void write(String str,
    int off,
    int len) 
    Write a portion of a string to the buffer.
 public  void writeTo(Writer out) throws IOException 
    Writes the contents of the buffer to another character stream.