Android
java.io
public class

java.io.CharArrayWriter

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

CharArrayWriter is used as a character output stream on a character array. The buffer used to store the written characters will grow as needed to accommodate more characters as they are written.

Summary

Fields

protected      char[]  buf  Buffer for characters  
protected      int  count  The ending index of the buffer. 
Fields inherited from class java.io.Writer

Public Constructors

            CharArrayWriter()
Constructs a new CharArrayWriter which has a buffer allocated with the default size of 32 characters.
            CharArrayWriter(int initialSize)
Constructs a new CharArrayWriter which has a buffer allocated with the size of initialSize characters.

Public Methods

          CharArrayWriter  append(char c)
Append a char cto the CharArrayWriter.
          CharArrayWriter  append(CharSequence csq)
Append a CharSequence csq to the CharArrayWriter.
          CharArrayWriter  append(CharSequence csq, int start, int end)
Append a subsequence of a CharSequence csq to the CharArrayWriter.
          void  close()
Close this Writer.
          void  flush()
Flush this Writer.
          void  reset()
Reset this Writer.
          int  size()
Answer the size of this Writer in characters.
          char[]  toCharArray()
Answer the contents of the receiver as a char array.
          String  toString()
Answer the contents of this CharArrayWriter as a String.
          void  write(String str, int offset, int len)
Writes count number of characters starting at offset from the String str to this CharArrayWriter.
          void  write(int oneChar)
Writes the specified character oneChar to this CharArrayWriter.
          void  write(char[] c, int offset, int len)
Writes count characters starting at offset in buf to this CharArrayWriter.
          void  writeTo(Writer out)
Writes the contents of this CharArrayWriter to another Writer.
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

Fields

protected char[] buf

Buffer for characters

protected int count

The ending index of the buffer.

Public Constructors

public CharArrayWriter()

Constructs a new CharArrayWriter which has a buffer allocated with the default size of 32 characters. The buffer is also the lock used to synchronize access to this Writer.

public CharArrayWriter(int initialSize)

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

Parameters

initialSize the initial size of this CharArrayWriters buffer.

Public Methods

public CharArrayWriter append(char c)

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

Parameters

c The character appended to the CharArrayWriter.

Returns

  • The CharArrayWriter.

public CharArrayWriter append(CharSequence csq)

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

Parameters

csq The CharSequence appended to the CharArrayWriter.

Returns

  • The CharArrayWriter

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

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

Parameters

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

Returns

  • The CharArrayWriter.

Throws

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

public void close()

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

public void flush()

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

public void reset()

Reset this Writer. The current write position is reset to the beginning of the buffer. All written characters are lost and the size of this writer is now 0.

public int size()

Answer the size of this Writer in characters. This number changes if this Writer is reset or as more characters are written to it.

Returns

  • int this CharArrayWriters current size in characters.

public char[] toCharArray()

Answer the contents of the receiver as a char array. The array returned is a copy and any modifications made to this Writer after are not reflected in the result.

Returns

  • char[] this CharArrayWriters contents as a new char array.

public String toString()

Answer the contents of this CharArrayWriter as a String. The String returned is a copy and any modifications made to this Writer after are not reflected in the result.

Returns

  • String this CharArrayWriters contents as a new String.

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

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

Parameters

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

public void write(int oneChar)

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

Parameters

oneChar The character to write

public void write(char[] c, int offset, int len)

Writes count characters starting at offset in buf to this CharArrayWriter.

Parameters

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

public void writeTo(Writer out)

Writes the contents of this CharArrayWriter to another Writer. The output is all the characters that have been written to the receiver since the last reset or since the creation.

Parameters

out the non-null Writer on which to write the contents.

Throws

IOException If an error occurs attempting to write the contents out.
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48