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.OutputStream
Note: 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 void
close()
We override default implementation to write last characters, which could be lost in buffer otherwise.void
flush()
Flush the stream.void
write(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.IOException
Flush the stream.- Specified by:
flush
in interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.OutputStream
- Throws:
java.io.IOException
- if an I/O error occurs
-
close
public void close() throws java.io.IOException
We override default implementation to write last characters, which could be lost in buffer otherwise.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
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 classjava.io.OutputStream
- Parameters:
b
- next byte from OutputStream to write.- Throws:
java.io.IOException
-
-