public class EncodedStreamWriter extends Writer
file.encoding
.
The only encodings that are guaranteed to be available are "8859_1"
(the Latin-1 character set) and "UTF8". Unfortunately, Java does not
provide a mechanism for listing the encodings that are supported in
a given implementation.
An application can install a named Codec using Io.addCodec() and this class is able to access that codec via the name supplied to addCodec(). The java.io.OutputStreamWriter however will not be able to access these codecs when run under a Java VM. Therefore if you must use a specific Codec then you should use this class instead.
Constructor and Description |
---|
EncodedStreamWriter(OutputStream out)
This method initializes a new instance of
EncodedStreamWriter
to write to the specified stream using the default encoding. |
EncodedStreamWriter(OutputStream out,
String encoding_name)
This method initializes a new instance of
EncodedStreamWriter
to write to the specified stream using a caller supplied character
encoding scheme. |
EncodedStreamWriter(OutputStream out,
TextCodec codec) |
Modifier and Type | Method and Description |
---|---|
void |
close()
This method closes this stream, and the underlying
OutputStream |
void |
flush()
This method flushes any buffered bytes to the underlying output sink.
|
TextCodec |
getCodec()
This method returns the name of the character encoding scheme currently
in use by this stream.
|
void |
write(char[] chars,
int offset,
int length)
This method writes
count characters from the specified
array to the output stream starting at position offset
into the array. |
public EncodedStreamWriter(OutputStream out, String encoding_name) throws UnsupportedEncodingException
EncodedStreamWriter
to write to the specified stream using a caller supplied character
encoding scheme. Note that due to a deficiency in the Java language
design, there is no way to determine which encodings are supported.out
- The OutputStream
to write toencoding_name
- The name of the encoding scheme to use for
character to byte translationUnsupportedEncodingException
- If the named encoding is
not available.public EncodedStreamWriter(OutputStream out, TextCodec codec)
public EncodedStreamWriter(OutputStream out)
EncodedStreamWriter
to write to the specified stream using the default encoding.out
- The OutputStream
to write topublic void close() throws IOException
OutputStream
close
in class Writer
IOException
- If an error occurspublic TextCodec getCodec()
null
.public void flush() throws IOException
flush
in class Writer
IOException
- If an error occurspublic void write(char[] chars, int offset, int length) throws IOException
count
characters from the specified
array to the output stream starting at position offset
into the array.write
in class Writer
buf
- The array of character to write fromoffset
- The offset into the array to start writing chars fromcount
- The number of chars to write.IOException
- If an error occurs