Android
java.io
public class

java.io.StringWriter

java.lang.Object
java.io.Writer Closeable Flushable Appendable
java.io.StringWriter

StringWriter is an class for writing Character Streams to a StringBuffer. The characters written can then be returned as a String. This is used for capturing output sent to a Writer by substituting a StringWriter.

See Also

Summary

Fields inherited from class java.io.Writer

Public Constructors

            StringWriter()
Constructs a new StringWriter which has a StringBuffer allocated with the default size of 16 characters.
            StringWriter(int initialSize)
Constructs a new StringWriter which has a StringBuffer allocated with the size of initialSize characters.

Public Methods

          StringWriter  append(CharSequence csq)
Append a CharSequence csq to the StringWriter.
          StringWriter  append(CharSequence csq, int start, int end)
Append a subsequence of a CharSequence csq to the StringWriter.
          StringWriter  append(char c)
Append a char cto the StringWriter.
          void  close()
Close this Writer.
          void  flush()
Flush this Writer.
          StringBuffer  getBuffer()
Answer the contents of this StringWriter as a StringBuffer.
          String  toString()
Answer the contents of this StringWriter as a String.
          void  write(char[] cbuf, int offset, int count)
Writes count characters starting at offset in cbuf to this StringWriter.
          void  write(String str, int offset, int count)
Writes count number of characters starting at offset from the String str to this StringWriter.
          void  write(int oneChar)
Writes the specified character oneChar to this StringWriter.
          void  write(String str)
Writes the characters from the String str to this StringWriter.
Methods inherited from class java.io.Writer
Methods inherited from class java.lang.Object
Methods inherited from interface java.io.Closeable
Methods inherited from interface java.io.Flushable
Methods inherited from interface java.lang.Appendable

Details

Public Constructors

public StringWriter()

Constructs a new StringWriter which has a StringBuffer allocated with the default size of 16 characters. The StringBuffer is also the lock used to synchronize access to this Writer.

public StringWriter(int initialSize)

Constructs a new StringWriter which has a StringBuffer allocated with the size of initialSize characters. The StringBuffer is also the lock used to synchronize access to this Writer.

Parameters

initialSize the intial number of characters

Public Methods

public StringWriter append(CharSequence csq)

Append a CharSequence csq to the StringWriter. The StringWriter.append(csq) works the same way as StringWriter.write(csq.toString()). If csq is null, then "null" will be substituted for csq.

Parameters

csq The CharSequence appended to the StringWriter.

Returns

  • The StringWriter

public StringWriter append(CharSequence csq, int start, int end)

Append a subsequence of a CharSequence csq to the StringWriter. The first char and the last char of the subsequnce is specified by the parameter start and end. The StringWriter.append(csq) works the same way as StringWriter.write(csq.subSequence(start,end).toString).If csq is null, then "null" will be substituted for csq. s

Parameters

csq The CharSequence appended to the StringWriter.
start The index of the first char in the CharSequence appended to the StringWriter.
end The index of the char after the last one in the CharSequence appended to the StringWriter.

Returns

  • The StringWriter.

Throws

IndexOutOfBoundsException If start is less than end, end is greater than the length of the CharSequence, or start or end is negative.

public StringWriter append(char c)

Append a char cto the StringWriter. The StringWriter.append(c) works the same way as StringWriter.write(c).

Parameters

c The character appended to the StringWriter.

Returns

  • The StringWriter.

public void close()

Close this Writer. This is the concrete implementation required. This particular implementation does nothing.

Throws

IOException If an IO error occurs closing this StringWriter.

public void flush()

Flush this Writer. This is the concrete implementation required. This particular implementation does nothing.

public StringBuffer getBuffer()

Answer the contents of this StringWriter as a StringBuffer. Any changes made to the StringBuffer by the receiver or the caller are reflected in this StringWriter.

Returns

  • this StringWriters local StringBuffer.

public String toString()

Answer the contents of this StringWriter as a String. Any changes made to the StringBuffer by the receiver after returning will not be reflected in the String returned to the caller.

Returns

  • this StringWriters current contents as a String.

public void write(char[] cbuf, int offset, int count)

Writes count characters starting at offset in cbuf to this StringWriter.

Parameters

cbuf the non-null array containing characters to write.
offset offset in buf to retrieve characters
count maximum number of characters to write

Throws

ArrayIndexOutOfBoundsException If offset or count are outside of bounds.

public void write(String str, int offset, int count)

Writes count number of characters starting at offset from the String str to this StringWriter.

Parameters

str the non-null String containing the characters to write.
offset the starting point to retrieve characters.
count the number of characters to retrieve and write.

Throws

ArrayIndexOutOfBoundsException If offset or count are outside of bounds.

public void write(int oneChar)

Writes the specified character oneChar to this StringWriter. This implementation writes the low order two bytes to the Stream.

Parameters

oneChar The character to write

public void write(String str)

Writes the characters from the String str to this StringWriter.

Parameters

str the non-null String containing the characters to write.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56