Added in API level 1

CharArrayWriter

open class CharArrayWriter : Writer
kotlin.Any
   ↳ java.io.Writer
   ↳ java.io.CharArrayWriter

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.

Summary

Public constructors

Creates a new CharArrayWriter.

CharArrayWriter(initialSize: Int)

Creates a new CharArrayWriter with the specified initial size.

Public methods
open CharArrayWriter

Appends the specified character sequence to this writer.

open CharArrayWriter
append(csq: CharSequence?, start: Int, end: Int)

Appends a subsequence of the specified character sequence to this writer.

open CharArrayWriter

Appends the specified character to this writer.

open Unit

Close the stream.

open Unit

Flush the stream.

open Unit

Resets the buffer so that you can use it again without throwing away the already allocated buffer.

open Int

Returns the current size of the buffer.

open CharArray!

Returns a copy of the input data.

open String

Converts input data to a string.

open Unit
write(c: Int)

Writes a character to the buffer.

open Unit
write(c: CharArray!, off: Int, len: Int)

Writes characters to the buffer.

open Unit
write(str: String!, off: Int, len: Int)

Write a portion of a string to the buffer.

open Unit
writeTo(out: Writer!)

Writes the contents of the buffer to another character stream.

Inherited functions
Properties
CharArray!

The buffer where data is stored.

Int

The number of chars in the buffer.

Inherited properties

Public constructors

CharArrayWriter

Added in API level 1
CharArrayWriter()

Creates a new CharArrayWriter.

CharArrayWriter

Added in API level 1
CharArrayWriter(initialSize: Int)

Creates a new CharArrayWriter with the specified initial size.

Parameters
initialSize Int: an int specifying the initial buffer size.
Exceptions
java.lang.IllegalArgumentException if initialSize is negative

Public methods

append

Added in API level 1
open fun append(csq: CharSequence?): CharArrayWriter

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.

Parameters
csq CharSequence?: The character sequence to append. If csq is null, then the four characters "null" are appended to this writer.
Return
CharArrayWriter This writer
Exceptions
java.io.IOException If an I/O error occurs

append

Added in API level 1
open fun append(
    csq: CharSequence?,
    start: Int,
    end: Int
): CharArrayWriter

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()) 
Parameters
csq CharSequence?: The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
start Int: The index of the first character in the subsequence
end Int: The index of the character following the last character in the subsequence
Return
CharArrayWriter This writer
Exceptions
java.lang.IndexOutOfBoundsException If start or end are negative, start is greater than end, or end is greater than csq.length()
java.io.IOException If an I/O error occurs

append

Added in API level 1
open fun append(c: Char): CharArrayWriter

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) 
Parameters
c Char: The 16-bit character to append
Return
CharArrayWriter This writer
Exceptions
java.io.IOException If an I/O error occurs

close

Added in API level 1
open fun close(): Unit

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.

Exceptions
java.lang.Exception if this resource cannot be closed
java.io.IOException If an I/O error occurs

flush

Added in API level 1
open fun flush(): Unit

Flush the stream.

Exceptions
java.io.IOException If an I/O error occurs

reset

Added in API level 1
open fun reset(): Unit

Resets the buffer so that you can use it again without throwing away the already allocated buffer.

size

Added in API level 1
open fun size(): Int

Returns the current size of the buffer.

Return
Int an int representing the current size of the buffer.

toCharArray

Added in API level 1
open fun toCharArray(): CharArray!

Returns a copy of the input data.

Return
CharArray! an array of chars copied from the input data.

toString

Added in API level 1
open fun toString(): String

Converts input data to a string.

Return
String the string.

write

Added in API level 1
open fun write(c: Int): Unit

Writes a character to the buffer.

Parameters
c Int: int specifying a character to be written
Exceptions
java.io.IOException If an I/O error occurs

write

Added in API level 1
open fun write(
    c: CharArray!,
    off: Int,
    len: Int
): Unit

Writes characters to the buffer.

Parameters
cbuf Array of characters
off Int: the start offset in the data
len Int: the number of chars that are written
c CharArray!: the data to be written
Exceptions
java.lang.IndexOutOfBoundsException If off is negative, or len is negative, or off + len is negative or greater than the length of the given array
java.io.IOException If an I/O error occurs

write

Added in API level 1
open fun write(
    str: String!,
    off: Int,
    len: Int
): Unit

Write a portion of a string to the buffer.

Parameters
str String!: String to be written from
off Int: Offset from which to start reading characters
len Int: Number of characters to be written
Exceptions
java.lang.IndexOutOfBoundsException If off is negative, or len is negative, or off + len is negative or greater than the length of the given string
java.io.IOException If an I/O error occurs

writeTo

Added in API level 1
open fun writeTo(out: Writer!): Unit

Writes the contents of the buffer to another character stream.

Parameters
out Writer!: the output stream to write to
Exceptions
java.io.IOException If an I/O error occurs.

Properties

buf

Added in API level 1
protected var buf: CharArray!

The buffer where data is stored.

count

Added in API level 1
protected var count: Int

The number of chars in the buffer.