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

All Implemented Interfaces:
    Flushable, Closeable, Appendable

A character stream that collects its output in a string buffer, which can then be used to construct a string.

Closing a StringWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Fields inherited from java.io.Writer:
lock
Constructor:
 public StringWriter() 
 public StringWriter(int initialSize) 
Method from java.io.StringWriter Summary:
append,   append,   append,   close,   flush,   getBuffer,   toString,   write,   write,   write,   write
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.StringWriter Detail:
 public StringWriter 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 StringWriter 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 StringWriter 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() throws IOException 
    Closing a StringWriter has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
 public  void flush() 
    Flush the stream.
 public StringBuffer getBuffer() 
    Return the string buffer itself.
 public String toString() 
    Return the buffer's current value as a string.
 public  void write(int c) 
    Write a single character.
 public  void write(String str) 
    Write a string.
 public  void write(char[] cbuf,
    int off,
    int len) 
    Write a portion of an array of characters.
 public  void write(String str,
    int off,
    int len) 
    Write a portion of a string.