OutputStreamWriter
open class OutputStreamWriter : Writer
kotlin.Any | ||
↳ | java.io.Writer | |
↳ | java.io.OutputStreamWriter |
An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified . The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.
Each invocation of a write() method causes the encoding converter to be invoked on the given character(s). The resulting bytes are accumulated in a buffer before being written to the underlying output stream. Note that the characters passed to the write() methods are not buffered.
For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent converter invocations. For example:
Writer out = new BufferedWriter(new OutputStreamWriter(System.out));
A surrogate pair is a character represented by a sequence of two char
values: A high surrogate in the range '\uD800' to '\uDBFF' followed by a low surrogate in the range '\uDC00' to '\uDFFF'.
A malformed surrogate element is a high surrogate that is not followed by a low surrogate or a low surrogate that is not preceded by a high surrogate.
This class always replaces malformed surrogate elements and unmappable character sequences with the charset's default substitution sequence. The java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.
Summary
Public constructors | |
---|---|
OutputStreamWriter(out: OutputStream!, charsetName: String!) Creates an OutputStreamWriter that uses the named charset. |
|
OutputStreamWriter(out: OutputStream!) Creates an OutputStreamWriter that uses the default character encoding. |
|
OutputStreamWriter(out: OutputStream!, cs: Charset!) Creates an OutputStreamWriter that uses the given charset. |
|
OutputStreamWriter(out: OutputStream!, enc: CharsetEncoder!) Creates an OutputStreamWriter that uses the given charset encoder. |
Public methods | |
---|---|
open Writer |
append(csq: CharSequence?, start: Int, end: Int) |
open Writer |
append(csq: CharSequence?) |
open Unit |
close() |
open Unit |
flush() Flushes the stream. |
open String! |
Returns the name of the character encoding being used by this stream. |
open Unit |
Writes a single character. |
open Unit |
Writes a portion of an array of characters. |
open Unit |
Writes a portion of a string. |
Inherited functions | |
---|---|
Inherited properties | |
---|---|
Public constructors
OutputStreamWriter
OutputStreamWriter(
out: OutputStream!,
charsetName: String!)
Creates an OutputStreamWriter that uses the named charset.
Parameters | |
---|---|
out |
OutputStream!: An OutputStream |
charsetName |
String!: The name of a supported charset |
Exceptions | |
---|---|
java.io.UnsupportedEncodingException |
If the named encoding is not supported |
OutputStreamWriter
OutputStreamWriter(out: OutputStream!)
Creates an OutputStreamWriter that uses the default character encoding.
Parameters | |
---|---|
out |
OutputStream!: An OutputStream |
OutputStreamWriter
OutputStreamWriter(
out: OutputStream!,
cs: Charset!)
Creates an OutputStreamWriter that uses the given charset.
Parameters | |
---|---|
out |
OutputStream!: An OutputStream |
cs |
Charset!: A charset |
OutputStreamWriter
OutputStreamWriter(
out: OutputStream!,
enc: CharsetEncoder!)
Creates an OutputStreamWriter that uses the given charset encoder.
Parameters | |
---|---|
out |
OutputStream!: An OutputStream |
enc |
CharsetEncoder!: A charset encoder |
Public methods
append
open fun append(
csq: CharSequence?,
start: Int,
end: Int
): Writer
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 | |
---|---|
Writer |
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(csq: CharSequence?): Writer
Parameters | |
---|---|
csq |
CharSequence?: The character sequence to append. If csq is null , then the four characters "null" are appended to this writer. |
Return | |
---|---|
Writer |
This writer |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
close
open fun close(): Unit
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
If an I/O error occurs |
flush
open fun flush(): Unit
Flushes the stream.
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
getEncoding
open fun getEncoding(): String!
Returns the name of the character encoding being used by this stream.
If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned.
If this instance was created with the OutputStreamWriter(java.io.OutputStream,java.lang.String)
constructor then the returned name, being unique for the encoding, may differ from the name passed to the constructor. This method may return null
if the stream has been closed.
Return | |
---|---|
String! |
The historical name of this encoding, or possibly null if the stream has been closed |
See Also
write
open fun write(c: Int): Unit
Writes 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
Writes a portion of an array of characters.
Parameters | |
---|---|
cbuf |
CharArray!: Buffer 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!,
off: Int,
len: Int
): Unit
Writes a portion of a string.
Parameters | |
---|---|
str |
String!: A String |
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 |