|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.Writer com.novell.io.EncodingStreamWriter
This class provides the same functionality as java.io.OutputStreamWriter but also allows unencodable characters to be handled with other than a replacement character.
Via the CharEncoder-derived classes, it current provides implementations of the following encodings: ASCII, UTF-8, UTF-16, ISO-8859-1 though -9, -15 and -15.
This class has been updated to use java.nio.charset.CharsetEncoder instances for encodings not supported directly by this package.
When a character that is output cannot be encoded in the underlying encoding, this class throws com.novell.io.CharacterEncodingException to allow callers to handle the character. Note that wrapping this class in a java.io.BufferedWriter will not allow the use of this mechanism, since the actual encoding of the characters will likely happen after the calls that write the characters. However this Writer class has an internal buffer that is used to store the encoded bytes and the encoded bytes will therefore not be written to the underlying stream immediately.
This class is initially designed for use with XML serialization which has an escape mechanism for outputting characters that cannot be encoded in a particular scheme
Field Summary |
Fields inherited from class java.io.Writer |
lock |
Constructor Summary | |
EncodingStreamWriter(OutputStream stream,
CharEncoder encoder)
Construct an EncodingStreamWriter with the passed encoder |
|
EncodingStreamWriter(OutputStream stream,
String encoding)
Construct an EncodingStreamWriter that supports the passed encoding scheme |
Method Summary | |
void |
close()
Close the stream, flushing it first. |
void |
flush()
Flush the stream |
int |
getBufferSize()
Return the size of the internal buffer |
String |
getEncoding()
Return the encoding used by this EncodingStreamWriter |
void |
setBufferSize(int size)
Set the buffer size of this Writer |
protected boolean |
tryFlush()
|
void |
write(char[] buf)
Write characters to the stream |
void |
write(char[] buf,
int off,
int len)
Write characters to the stream |
void |
write(int c)
Write a single character to the stream |
void |
write(String str)
Write characters to the stream |
void |
write(String str,
int off,
int len)
Write characters to the stream |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public EncodingStreamWriter(OutputStream stream, String encoding) throws UnsupportedEncodingException
stream
- The underlying stream to which to output the bytesencoding
- The desired encoding
UnsupportedEncodingException
- Thrown if the desired encoding
is not available.public EncodingStreamWriter(OutputStream stream, CharEncoder encoder)
stream
- The underlying stream to which to output the bytesencoder
- the CharEncoder to useMethod Detail |
public void setBufferSize(int size) throws IOException
size
- The desired size, in bytes of the buffer
IOException
public int getBufferSize()
public String getEncoding()
public void close() throws IOException
IOException
public void flush() throws IOException
IOException
public void write(int c) throws IOException
c
- The char to be written (upper 16 bits ignored)
IOException
public void write(char[] buf) throws IOException
buf
- The array of characters to write
IOException
public void write(char[] buf, int off, int len) throws IOException
buf
- The array of charactersoff
- The starting offset within the arraylen
- The number of characters to write, starting at off
IOException
public void write(String str) throws IOException
str
- The characters to write
IOException
public void write(String str, int off, int len) throws IOException
str
- The characters to writeoff
- The starting offset within the stringlen
- The number of characters to write, starting at off
IOException
protected boolean tryFlush() throws IOException
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |