Added in API level 1

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. The size of this buffer may be specified, but by default it is large enough for most purposes. 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.

Creates an OutputStreamWriter that uses the default character encoding.

Creates an OutputStreamWriter that uses the given charset.

Creates an OutputStreamWriter that uses the given charset encoder.

Public methods
open Unit

open Unit

Flushes the stream.

open String!

Returns the name of the character encoding being used by this stream.

open Unit
write(c: Int)

Writes a single character.

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

Writes a portion of an array of characters.

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

Writes a portion of a string.

Inherited functions
Inherited properties

Public constructors

OutputStreamWriter

Added in API level 1
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

Added in API level 1
OutputStreamWriter(out: OutputStream!)

Creates an OutputStreamWriter that uses the default character encoding.

Parameters
out OutputStream!: An OutputStream

OutputStreamWriter

Added in API level 1
OutputStreamWriter(
    out: OutputStream!,
    cs: Charset!)

Creates an OutputStreamWriter that uses the given charset.

Parameters
out OutputStream!: An OutputStream
cs Charset!: A charset

OutputStreamWriter

Added in API level 1
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

close

Added in API level 1
open fun close(): Unit
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

Flushes the stream.

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

getEncoding

Added in API level 1
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

write

Added in API level 1
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
java.io.IOException If an I/O error occurs

write

Added in API level 1
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 Implementations should throw this exception 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
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

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 Implementations should throw this exception 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
java.io.IOException If an I/O error occurs