StringWriter
open class StringWriter : Writer
kotlin.Any | ||
↳ | java.io.Writer | |
↳ | java.io.StringWriter |
A character stream that collects its output in a string buffer, which can then be used to construct a string.
Closing a StringWriter
has no effect. The methods in this class can be called after the stream has been closed without generating an IOException
.
Summary
Public constructors | |
---|---|
Create a new string writer using the default initial string-buffer size. |
|
StringWriter(initialSize: Int) Create a new string writer using the specified initial string-buffer size. |
Public methods | |
---|---|
open StringWriter |
append(csq: CharSequence?) Appends the specified character sequence to this writer. |
open StringWriter |
append(csq: CharSequence?, start: Int, end: Int) Appends a subsequence of the specified character sequence to this writer. |
open StringWriter |
Appends the specified character to this writer. |
open Unit |
close() Closing a |
open Unit |
flush() Flush the stream. |
open StringBuffer! |
Return the string buffer itself. |
open String |
toString() Return the buffer's current value as a string. |
open Unit |
Write a single character. |
open Unit |
Write a portion of an array of characters. |
open Unit |
Write a string. |
open Unit |
Write a portion of a string. |
Inherited functions | |
---|---|
Inherited properties | |
---|---|
Public constructors
StringWriter
StringWriter()
Create a new string writer using the default initial string-buffer size.
StringWriter
StringWriter(initialSize: Int)
Create a new string writer using the specified initial string-buffer size.
Parameters | |
---|---|
initialSize |
Int: The number of char values that will fit into this buffer before it is automatically expanded |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If initialSize is negative |
Public methods
append
open fun append(csq: CharSequence?): StringWriter
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 | |
---|---|
StringWriter |
This writer |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
append
open fun append(
csq: CharSequence?,
start: Int,
end: Int
): StringWriter
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
<code>out.write(csq.subSequence(start, end).toString()) </code>
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 | |
---|---|
StringWriter |
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
open fun append(c: Char): StringWriter
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 | |
---|---|
StringWriter |
This writer |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
close
open fun close(): Unit
Closing a StringWriter
has no effect. The methods in this class can be called after the stream has been closed without generating an IOException
.
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 |
getBuffer
open fun getBuffer(): StringBuffer!
Return the string buffer itself.
Return | |
---|---|
StringBuffer! |
StringBuffer holding the current buffer value. |
toString
open fun toString(): String
Return the buffer's current value as a string.
Return | |
---|---|
String |
a string representation of the object. |
write
open fun write(c: Int): Unit
Write a single character.
Parameters | |
---|---|
c |
Int: int specifying a character to be written |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
write
open fun write(
cbuf: CharArray!,
off: Int,
len: Int
): Unit
Write a portion of an array of characters.
Parameters | |
---|---|
cbuf |
CharArray!: Array of characters |
off |
Int: Offset from which to start writing characters |
len |
Int: Number of characters to write |
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(str: String!): Unit
Write a string.
Parameters | |
---|---|
str |
String!: String 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.
Parameters | |
---|---|
str |
String!: String to be written |
off |
Int: Offset from which to start writing characters |
len |
Int: Number of characters to write |
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 |