charset
. The charset that it uses
may be specified by name or may be given explicitly, or the
default charset 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. Note that the characters passed to the write() methods are not buffered.
For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent converter invocations. For example:
Writer out = new BufferedWriter(new OutputStreamWriter(anOutputStream));
A surrogate pair is a character represented by a sequence of two
char
values: A high surrogate in the range '\uD800' to
'\uDBFF' followed by a low surrogate in the range '\uDC00' to
'\uDFFF'.
A malformed surrogate element is a high surrogate that is not followed by a low surrogate or a low surrogate that is not preceded by a high surrogate.
This class always replaces malformed surrogate elements and unmappable character sequences with the charset's default substitution sequence. The CharsetEncoder class should be used when more control over the encoding process is required.
BufferedWriter
, OutputStream
, Charset
Modifier and Type | Field and Description |
---|---|
private final StreamEncoder |
Access | Constructor and Description |
---|---|
public | OutputStreamWriter(OutputStream
An OutputStream out, String The name of a supported charsetName)charset Creates an OutputStreamWriter that uses the named charset. |
public | OutputStreamWriter(OutputStream
An OutputStream out)Creates an OutputStreamWriter that uses the default character encoding, or
where |
public | OutputStreamWriter(OutputStream
An OutputStream out, Charset A charset cs)Creates an OutputStreamWriter that uses the given charset. |
public | OutputStreamWriter(OutputStream
An OutputStream out, CharsetEncoder A charset encoder enc)Creates an OutputStreamWriter that uses the given charset encoder. |
Modifier and Type | Method and Description |
---|---|
public Writer | append(CharSequence
The character sequence from which a subsequence will be
appended. If csq, int csq is null , then characters
will be appended as if csq contained the four
characters "null" .The index of the first character in the subsequence start, int The index of the character following the last character in the
subsequence end)Overrides java. Implements java. Appends a subsequence of the specified character sequence to this writer. |
public Writer | append(CharSequence
The character sequence to append. If csq)csq is
null , then the four characters "null" are
appended to this writer.Overrides java. Implements java. Appends the specified character sequence to this writer. |
public void | close()
Implements abstract java. Implements java. Closes the stream, flushing it first. |
public void | flush()
Implements abstract java. Implements java. Flushes the stream. |
pack-priv void | flushBuffer()
Flushes the output buffer to the underlying byte stream, without flushing the byte stream itself. |
public String | Returns: The historical name of this encoding, or possiblynull if the stream has been closedReturns the name of the character encoding being used by this stream. |
private static Object | |
public void | write(int
int specifying a character to be written c)Overrides java. Writes a single character. |
public void | write(char[]
Buffer of characters cbuf, int Offset from which to start writing characters off, int Number of characters to write len)Implements abstract java. Writes a portion of an array of characters. |
public void | write(String
A String str, int Offset from which to start writing characters off, int Number of characters to write len)Overrides java. Writes a portion of a string. |
se | back to summary |
---|---|
private final StreamEncoder se |
OutputStreamWriter | back to summary |
---|---|
public OutputStreamWriter(OutputStream out, String charsetName) throws UnsupportedEncodingException Creates an OutputStreamWriter that uses the named charset.
|
OutputStreamWriter | back to summary |
---|---|
public OutputStreamWriter(OutputStream out) Creates an OutputStreamWriter that uses the default character encoding, or
where
|
OutputStreamWriter | back to summary |
---|---|
public OutputStreamWriter(OutputStream out, Charset cs) Creates an OutputStreamWriter that uses the given charset.
|
OutputStreamWriter | back to summary |
---|---|
public OutputStreamWriter(OutputStream out, CharsetEncoder enc) Creates an OutputStreamWriter that uses the given charset encoder.
|
append | back to summary |
---|---|
public Writer append(CharSequence csq, int start, int end) throws IOException Overrides java. Implements java. Doc from java. Appends a subsequence of the specified character sequence to this writer.
An invocation of this method of the form
out.write(csq.subSequence(start, end).toString())
|
append | back to summary |
---|---|
public Writer append(CharSequence csq) throws IOException Overrides java. Implements java. Doc from java. Appends the specified character sequence to this writer. An invocation of this method of the form out.write(csq.toString()) Depending on the specification of
|
close | back to summary |
---|---|
public void close() throws IOException Implements abstract java. Implements java. Doc from java. Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.
|
flush | back to summary |
---|---|
public void flush() throws IOException Implements abstract java. Implements java. Flushes the stream.
|
flushBuffer | back to summary |
---|---|
pack-priv void flushBuffer() throws IOException Flushes the output buffer to the underlying byte stream, without flushing the byte stream itself. This method is non-private only so that it may be invoked by PrintStream. |
getEncoding | back to summary |
---|---|
public String getEncoding() Returns the name of the character encoding being used by this stream. If the encoding has an historical name then that name is returned; otherwise the encoding's canonical name is returned. If this instance was created with the |
lockFor | back to summary |
---|---|
private static Object lockFor(OutputStreamWriter writer) Return the lock object for the given writer's stream encoder. If the writer type is trusted then an internal lock can be used. If the writer type is not trusted then the writer object is the lock. |
write | back to summary |
---|---|
public void write(int c) throws IOException Overrides java. Writes a single character.
|
write | back to summary |
---|---|
public void write(char[] cbuf, int off, int len) throws IOException Implements abstract java. Writes a portion of an array of characters.
|
write | back to summary |
---|---|
public void write(String str, int off, int len) throws IOException Overrides java. Writes a portion of a string.
|