com.sun.javatest.util
Class WriterStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.sun.javatest.util.WriterStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class WriterStream
extends java.io.OutputStream

Note: this class should be JDK 1.1 compatible


Constructor Summary
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
 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.
 
Methods inherited from class java.io.OutputStream
write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 writer
charsetName - 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 interface java.io.Flushable
Overrides:
flush in class java.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 interface java.io.Closeable
Overrides:
close in class java.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 class java.io.OutputStream
Parameters:
b - next byte from OutputStream to write.
Throws:
java.io.IOException


Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.