Package com.sun.javatest.util
Class WriterStream
java.lang.Object
java.io.OutputStream
com.sun.javatest.util.WriterStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
Note: this class should be JDK 1.1 compatible
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a stream that writes to a writer.WriterStream
(Writer w, String charsetName) Create a stream that writes to a writer. -
Method Summary
Methods inherited from class java.io.OutputStream
nullOutputStream, write, write
-
Constructor Details
-
WriterStream
Create a stream that writes to a writer.- Parameters:
w
- the writer
-
WriterStream
Create a stream that writes to a writer.- Parameters:
w
- the writercharsetName
- name of encoding to be used when decode byte stream (instead of default one)
-
-
Method Details
-
flush
Flush the stream.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- if an I/O error occurs
-
close
We override default implementation to write last characters, which could be lost in buffer otherwise.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
write
OutputStream's implementation. Our goal is to convert encoded byte stream form OutputStream to char stream, which can be written using specified writer. We perform this by collecting bytes in buffer and checking with PERIOD_SIZE interval if this buffer represents some char sequence. If so, we write to writer all chars, except last one. We don't write last char, because there still not enough bytes could be collected for it.- Specified by:
write
in classOutputStream
- Parameters:
b
- next byte from OutputStream to write.- Throws:
IOException
-