Package com.sun.javatest.util
Class WriterStream
- java.lang.Object
-
- java.io.OutputStream
-
- com.sun.javatest.util.WriterStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class WriterStream extends java.io.OutputStreamNote: this class should be JDK 1.1 compatible
-
-
Constructor Summary
Constructors Constructor Description WriterStream(java.io.Writer w)Create a stream that writes to a writer.WriterStream(java.io.Writer w, java.lang.String charsetName)Create a stream that writes to a writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()We override default implementation to write last characters, which could be lost in buffer otherwise.voidflush()Flush the stream.voidwrite(int b)OutputStream's implementation.
-
-
-
Constructor Detail
-
WriterStream
public WriterStream(java.io.Writer w)
Create a stream that writes to a writer.- Parameters:
w- the writer
-
WriterStream
public WriterStream(java.io.Writer w, java.lang.String charsetName)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 Detail
-
flush
public void flush() throws java.io.IOExceptionFlush the stream.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException- if an I/O error occurs
-
close
public void close() throws java.io.IOExceptionWe override default implementation to write last characters, which could be lost in buffer otherwise.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOExceptionOutputStream'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:
writein classjava.io.OutputStream- Parameters:
b- next byte from OutputStream to write.- Throws:
java.io.IOException
-
-