All Packages Class Hierarchy This Package Previous Next Index

Class java.io.OutputStreamWriter

java.lang.Object | +----java.io.Writer | +----java.io.OutputStreamWriter
public class OutputStreamWriter
extends Writer
Write characters to an output stream, translating characters into bytes according to a specified character encoding. Each OutputStreamWriter incorporates its own CharToByteConverter, and is thus a bridge from character streams to byte streams.

The encoding used by an OutputStreamWriter may be specified by name, by providing a CharToByteConverter, or by accepting the default encoding, which is defined by the system property file.encoding.

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));

See Also:
BufferedWriter, OutputStream

Constructor Index

 o OutputStreamWriter(OutputStream)
Create an OutputStreamWriter that uses the default character encoding.
 o OutputStreamWriter(OutputStream, String)
Create an OutputStreamWriter that uses the named character encoding.

Method Index

 o close()
Close the stream.
 o flush()
Flush the stream.
 o getEncoding()
Return the name of the encoding being used by this stream.
 o write(char[], int, int)
Write a portion of an array of characters.
 o write(int)
Write a single character.
 o write(String, int, int)
Write a portion of a string.

Constructors

 o OutputStreamWriter public OutputStreamWriter(OutputStream out, String enc) throws UnsupportedEncodingException
Create an OutputStreamWriter that uses the named character encoding.

Parameters:
out - An OutputStream
enc - Name of the encoding to be used
Throws: UnsupportedEncodingException
If the named encoding is not supported
 o OutputStreamWriter public OutputStreamWriter(OutputStream out)
Create an OutputStreamWriter that uses the default character encoding.

Parameters:
out - An OutputStream

Methods

 o getEncoding public String getEncoding()
Return the name of the encoding being used by this stream. May return null if the stream has been closed.

 o write public void write(int c) throws IOException
Write a single character.

Throws: IOException
If an I/O error occurs
Overrides:
write in class Writer
 o write public void write(char cbuf[], int off, int len) throws IOException
Write a portion of an array of characters.

Parameters:
cbuf - Buffer of characters
off - Offset from which to start writing characters
len - Number of characters to write
Throws: IOException
If an I/O error occurs
Overrides:
write in class Writer
 o write public void write(String str, int off, int len) throws IOException
Write a portion of a string.

Parameters:
str - A String
off - Offset from which to start writing characters
len - Number of characters to write
Throws: IOException
If an I/O error occurs
Overrides:
write in class Writer
 o flush public void flush() throws IOException
Flush the stream.

Throws: IOException
If an I/O error occurs
Overrides:
flush in class Writer
 o close public void close() throws IOException
Close the stream.

Throws: IOException
If an I/O error occurs
Overrides:
close in class Writer

All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature