public class OutputStreamWriter extends Writer
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.
Writer
,
UnsupportedEncodingException
Constructor and Description |
---|
OutputStreamWriter(OutputStream os)
Create an OutputStreamWriter that uses the default character encoding.
|
OutputStreamWriter(OutputStream os,
String enc)
Create an OutputStreamWriter that uses the named character encoding.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the stream.
|
void |
flush()
Flush the stream.
|
void |
write(char[] cbuf,
int off,
int len)
Write a portion of an array of characters.
|
void |
write(int c)
Write a single character.
|
void |
write(String str,
int off,
int len)
Write a portion of a string.
|
public OutputStreamWriter(OutputStream os)
os
- An OutputStreampublic OutputStreamWriter(OutputStream os, String enc) throws UnsupportedEncodingException
os
- An OutputStreamenc
- The name of a supportedUnsupportedEncodingException
- If the named encoding is not supportedpublic void write(int c) throws IOException
write
in class Writer
c
- int specifying a character to be written.IOException
- If an I/O error occurspublic void write(char[] cbuf, int off, int len) throws IOException
write
in class Writer
cbuf
- Buffer of characters to be writtenoff
- Offset from which to start reading characterslen
- Number of characters to be writtenIOException
- If an I/O error occurspublic void write(String str, int off, int len) throws IOException
write
in class Writer
str
- String to be writtenoff
- Offset from which to start reading characterslen
- Number of characters to be writtenIOException
- If an I/O error occurspublic void flush() throws IOException
flush
in class Writer
IOException
- If an I/O error occurspublic void close() throws IOException
close
in class Writer
IOException
- If an I/O error occursCopyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.