⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outputstreamwriter.java

📁 已经移植好的java虚拟机
💻 JAVA
字号:
/* * Copyright 1996-2002 Sun Microsystems, Inc. All Rights Reserved. * * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */package java.io;import com.sun.cldc.i18n.*;/** * 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. * * <p> 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) * @author      Nik Shaylor * @since       CLDC 1.0 */public class OutputStreamWriter extends Writer {    /**     * The underlying character-output stream.     */    private Writer out;    /**     * Create an OutputStreamWriter that uses the default character encoding.     *     * @param  os  An OutputStream     */    public OutputStreamWriter(OutputStream os) {        out = Helper.getStreamWriter(os);    }    /**     * 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     */    public OutputStreamWriter(OutputStream os, String enc)        throws UnsupportedEncodingException    {        out = Helper.getStreamWriter(os, enc);    }    /** Check to make sure that the stream has not been closed */    private void ensureOpen() throws IOException {        if (out == null) {            throw new IOException("Stream closed");        }    }    /**     * Write a single character.     *     * @exception  IOException  If an I/O error occurs     */    public void write(int c) throws IOException {        ensureOpen();        out.write(c);    }    /**     * 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     */    public void write(char cbuf[], int off, int len) throws IOException {        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);    }    /**     * 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     */    public void write(String str, int off, int len) throws IOException {        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);    }    /**     * Flush the stream.     *     * @exception  IOException  If an I/O error occurs     */    public void flush() throws IOException {        ensureOpen();        out.flush();    }    /**     * Close the stream.     *     * @exception  IOException  If an I/O error occurs     */    public void close() throws IOException {        if (out != null) {            out.close();            out = null;        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -