FileDocCategorySizeDatePackage
Support_StringWriter.javaAPI DocAndroid 1.5 API5547Wed May 06 22:41:06 BST 2009tests.support

Support_StringWriter

public class Support_StringWriter extends Writer

Fields Summary
private StringBuffer
buf
Constructors Summary
public Support_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.

        super();
        buf = new StringBuffer(16);
        lock = buf;
    
public Support_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.

        if (initialSize >= 0) {
            buf = new StringBuffer(initialSize);
            lock = buf;
        } else {
            throw new IllegalArgumentException();
        }
    
Methods Summary
public voidclose()
Close this Writer. This is the concrete implementation required. This particular implementation does nothing.

exception
java.io.IOException If an IO error occurs closing this StringWriter.

    
public voidflush()
Flush this Writer. This is the concrete implementation required. This particular implementation does nothing.

    
public java.lang.StringBuffergetBuffer()
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.

return
this StringWriters local StringBuffer.

        synchronized (lock) {
            return buf;
        }
    
public java.lang.StringtoString()
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.

return
this StringWriters current contents as a String.

        synchronized (lock) {
            return buf.toString();
        }
    
public voidwrite(java.lang.String str, int offset, int count)
Writes count number of characters starting at offset from the String str to this StringWriter.

param
str the non-null String containing the characters to write.
param
offset the starting point to retrieve characters.
param
count the number of characters to retrieve and write.
exception
java.lang.ArrayIndexOutOfBoundsException If offset or count are outside of bounds.

        String sub = str.substring(offset, offset + count);
        synchronized (lock) {
            buf.append(sub);
        }
    
public voidwrite(char[] buf, int offset, int count)
Writes count characters starting at offset in buf to this StringWriter.

param
buf the non-null array containing characters to write.
param
offset offset in buf to retrieve characters
param
count maximum number of characters to write
exception
java.lang.ArrayIndexOutOfBoundsException If offset or count are outside of bounds.

        // avoid int overflow
        if (0 <= offset && offset <= buf.length && 0 <= count
                && count <= buf.length - offset) {
            synchronized (lock) {
                this.buf.append(buf, offset, count);
            }
        } else {
            throw new ArrayIndexOutOfBoundsException();
        }
    
public voidwrite(int oneChar)
Writes the specified character oneChar to this StringWriter. This implementation writes the low order two bytes to the Stream.

param
oneChar The character to write

        synchronized (lock) {
            buf.append((char) oneChar);
        }
    
public voidwrite(java.lang.String str)
Writes the characters from the String str to this StringWriter.

param
str the non-null String containing the characters to write.

        synchronized (lock) {
            buf.append(str);
        }