Class WriterOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class WriterOutputStream
    extends java.io.OutputStream
    Redirects an OutputStream to a Writer by decoding the data using the specified Charset.

    Note: This class should only be used if it is necessary to redirect an OutputStream to a Writer for compatibility purposes. It is much more efficient to write to the Writer directly.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.charset.CharsetDecoder decoder  
      private java.nio.ByteBuffer decoderIn  
      private java.nio.CharBuffer decoderOut  
      private java.io.Writer out  
    • Constructor Summary

      Constructors 
      Constructor Description
      WriterOutputStream​(java.io.Writer out, java.nio.charset.Charset charset)  
      WriterOutputStream​(java.io.Writer out, java.nio.charset.CharsetDecoder decoder)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void flush()  
      private void flushOutput()
      Flush the output.
      private void processInput​(boolean endOfInput)
      Decode the contents of the input ByteBuffer into a CharBuffer.
      void write​(byte[] b)  
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • out

        private final java.io.Writer out
      • decoder

        private final java.nio.charset.CharsetDecoder decoder
      • decoderIn

        private final java.nio.ByteBuffer decoderIn
      • decoderOut

        private final java.nio.CharBuffer decoderOut
    • Constructor Detail

      • WriterOutputStream

        public WriterOutputStream​(java.io.Writer out,
                                  java.nio.charset.Charset charset)
      • WriterOutputStream

        public WriterOutputStream​(java.io.Writer out,
                                  java.nio.charset.CharsetDecoder decoder)
    • Method Detail

      • write

        public void write​(int b)
                   throws java.io.IOException
        Specified by:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • write

        public void write​(byte[] b,
                          int off,
                          int len)
                   throws java.io.IOException
        Overrides:
        write in class java.io.OutputStream
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.OutputStream
        Throws:
        java.io.IOException
      • processInput

        private void processInput​(boolean endOfInput)
                           throws java.io.IOException
        Decode the contents of the input ByteBuffer into a CharBuffer.
        Parameters:
        endOfInput - indicates end of input
        Throws:
        java.io.IOException - if an I/O error occurs
      • flushOutput

        private void flushOutput()
                          throws java.io.IOException
        Flush the output.
        Throws:
        java.io.IOException - if an I/O error occurs