FileDocCategorySizeDatePackage
OutputStreamWriter.javaAPI DocphoneME MR2 API (J2ME)4939Wed May 02 17:59:54 BST 2007java.io

OutputStreamWriter

public class OutputStreamWriter extends Writer
An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are translated into bytes. The encoding that it uses may be specified by name, or the platform's default encoding 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.

version
1.0, 12/15/99 (CLDC 1.0, Spring 2000)

Fields Summary
private Writer
out
The underlying character output stream.
Constructors Summary
public OutputStreamWriter(OutputStream os)
Create an OutputStreamWriter that uses the default character encoding.

param
os An OutputStream

        out = Helper.getStreamWriter(os);
    
public OutputStreamWriter(OutputStream os, String enc)
Create an OutputStreamWriter that uses the named character encoding.

param
os An OutputStream
param
enc The name of a supported
exception
UnsupportedEncodingException If the named encoding is not supported

        out = Helper.getStreamWriter(os, enc);
    
Methods Summary
public voidclose()
Close the stream.

exception
IOException If an I/O error occurs

        if (out != null) {
            out.close();
            out = null;
        }
    
private voidensureOpen()
Check to make sure that the stream has not been closed

        if (out == null) {
            throw new IOException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped                       "Stream closed"
/* #endif */
            );
        }
    
public voidflush()
Flush the stream.

exception
IOException If an I/O error occurs

        ensureOpen();
        out.flush();
    
public voidwrite(int c)
Write a single character.

exception
IOException If an I/O error occurs

        ensureOpen();
        out.write(c);
    
public voidwrite(char[] cbuf, int off, int len)
Write a portion of an array of characters.

param
cbuf Buffer of characters to be written
param
off Offset from which to start reading characters
param
len Number of characters to be written
exception
IOException If an I/O error occurs

        ensureOpen();
        if ((off < 0) || (off > cbuf.length) || (len < 0) ||
            ((off + len) > cbuf.length) || ((off + len) < 0)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return;
        }
        out.write(cbuf, off, len);
    
public voidwrite(java.lang.String str, int off, int len)
Write a portion of a string.

param
str String to be written
param
off Offset from which to start reading characters
param
len Number of characters to be written
exception
IOException If an I/O error occurs

        ensureOpen();
        if ((off < 0) || (off > str.length()) || (len < 0) ||
            ((off + len) > str.length()) || ((off + len) < 0)) {
            throw new IndexOutOfBoundsException();
        } else if (len == 0) {
            return;
        }
        out.write(str, off, len);