📄 outputstreamwriter.java
字号:
package java.io;import kaffe.io.CharToByteConverter;/* * Java core library component. * * Copyright (c) 1997, 1998 * Transvirtual Technologies, Inc. All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */public class OutputStreamWriter extends Writer{ private final static int BUFDEFAULT = 1024; private static final int MINMARGIN = 32; private OutputStream strm; private CharToByteConverter encoding; private final byte[] outbuf = new byte[BUFDEFAULT]; private int buflen; private boolean closed;public OutputStreamWriter(OutputStream out) { strm = out; encoding = CharToByteConverter.getDefault();}public OutputStreamWriter(OutputStream out, String enc) throws UnsupportedEncodingException{ strm = out; encoding = CharToByteConverter.getConverter(enc);}public void close() throws IOException{ if (!closed) { flush(); strm.close(); strm = null; closed = true; }}public void flush() throws IOException{ synchronized (lock) { if (closed) { throw new IOException("stream closed"); } if (buflen > 0) { strm.write(outbuf, 0, buflen); buflen = 0; } } strm.flush();}public String getEncoding() { return (encoding.toString());}public void write(String str, int off, int len) throws IOException{ write(str.toCharArray(), off, len);}public void write(char cbuf[], int off, int len) throws IOException{ if (strm == null) { throw new IOException("stream closed"); } synchronized (lock) { if (len > 0) { int outlen = encoding.convert(cbuf, off, len, outbuf, buflen, outbuf.length - buflen); if (outlen == 0) { flush(); outlen = encoding.flush(outbuf, buflen, outbuf.length - buflen); } while (outlen > 0) { buflen += outlen; if (outbuf.length - buflen < MINMARGIN) { flush(); } outlen = encoding.flush(outbuf, buflen, outbuf.length - buflen); } } }}public void write(int c) throws IOException{ write (new char[] { (char)c }, 0, 1);}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -