Class ForwardingOutputStream

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

    public class ForwardingOutputStream
    extends java.io.ByteArrayOutputStream
    This class is a simple output-stream that can be used by a PrintStream to buffer up printed output. When this stream is flushed, it causes the accumulated contents to be sent across an ObjectOutputStream. This allows the underlying ObjectOutputStream to be used both for sending data objects, and strings of printed output.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.ObjectOutputStream objectOutput
      The underlying output stream over which objects are serialized.
      • Fields inherited from class java.io.ByteArrayOutputStream

        buf, count
    • Constructor Summary

      Constructors 
      Constructor Description
      ForwardingOutputStream​(java.io.ObjectOutputStream objectOutput)
      Construct a forwarding output-stream that will send objects over the specified object output-stream when flushed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flush()
      When called, this output stream will convert its accumulated data into a String object, which will then be sent over the underlying object output-stream.
      • Methods inherited from class java.io.ByteArrayOutputStream

        close, reset, size, toByteArray, toString, toString, toString, toString, write, write, writeBytes, writeTo
      • Methods inherited from class java.io.OutputStream

        nullOutputStream, write
      • Methods inherited from class java.lang.Object

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

      • objectOutput

        private java.io.ObjectOutputStream objectOutput
        The underlying output stream over which objects are serialized.
    • Constructor Detail

      • ForwardingOutputStream

        public ForwardingOutputStream​(java.io.ObjectOutputStream objectOutput)
        Construct a forwarding output-stream that will send objects over the specified object output-stream when flushed.
    • Method Detail

      • flush

        public void flush()
                   throws java.io.IOException
        When called, this output stream will convert its accumulated data into a String object, which will then be sent over the underlying object output-stream. Once this is completed, the buffered string data is cleared.
        Specified by:
        flush in interface java.io.Flushable
        Overrides:
        flush in class java.io.OutputStream
        Throws:
        java.io.IOException - if an error occurs while sending the string data