OutputStreamWriterpublic 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. |
Fields Summary |
---|
private Writer | outThe underlying character-output stream. |
Constructors Summary |
---|
public OutputStreamWriter(OutputStream os)Create an OutputStreamWriter that uses the default character encoding.
out = Helper.getStreamWriter(os);
| public OutputStreamWriter(OutputStream os, String enc)Create an OutputStreamWriter that uses the named character encoding.
out = Helper.getStreamWriter(os, enc);
|
Methods Summary |
---|
public void | close()Close the stream.
if (out != null) {
out.close();
out = null;
}
| private void | ensureOpen()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 void | flush()Flush the stream.
ensureOpen();
out.flush();
| public void | write(int c)Write a single character.
ensureOpen();
out.write(c);
| public void | write(char[] cbuf, int off, int len)Write a portion of an array of characters.
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 void | write(java.lang.String str, int off, int len)Write a portion of a string.
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);
|
|