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 to this writer. |
open CharArrayWriter |
append(csq: CharSequence?) 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 Unit |
close() Close the stream. |
open Unit |
flush() Flush the stream. |
open Unit |
reset() Resets the buffer so that you can use it again without throwing away the already allocated buffer. |
open Int |
size() Returns the current size of the buffer. |
open CharArray! |
Returns a copy of the input data. |
open String |
toString() Converts input data to a string. |
open Unit |
Writes characters to the buffer. |
open Unit |
Writes a character to the buffer. |
open Unit |
Write a portion of a string to the buffer. |
open Unit |
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
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
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 |
append
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
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 |
close
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
open fun flush(): Unit
Flush the stream.
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
reset
open fun reset(): Unit
Resets the buffer so that you can use it again without throwing away the already allocated buffer.
size
open fun size(): Int
Returns the current size of the buffer.
Return | |
---|---|
Int |
an int representing the current size of the buffer. |
toCharArray
open fun toCharArray(): CharArray!
Returns a copy of the input data.
Return | |
---|---|
CharArray! |
an array of chars copied from the input data. |
toString
open fun toString(): String
Converts input data to a string.
Return | |
---|---|
String |
the string. |
write
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
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
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
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. |