Class MessageWriter

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

    public class MessageWriter
    extends java.io.Writer
    Combines messages from an OutputStream (hopefully in UTF-8) and a Writer.

    This class is primarily meant for BaseConnection in contexts where a standard error stream from a command execution, as well as messages from a side-band channel, need to be combined together into a buffer to represent the complete set of messages from a remote repository.

    Writes made to the writer are re-encoded as UTF-8 and interleaved into the buffer that getRawStream() also writes to.

    toString() returns all written data, after converting it to a String under the assumption of UTF-8 encoding.

    Internally RawParseUtils.decode(byte[]) is used by toString() tries to work out a reasonably correct character set for the raw data.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.ByteArrayOutputStream buf  
      private java.io.OutputStreamWriter enc  
      • Fields inherited from class java.io.Writer

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      MessageWriter()
      Create an empty writer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      void flush()
      java.io.OutputStream getRawStream()
      Get the underlying byte stream that character writes to this writer drop into.
      java.lang.String toString()
      void write​(char[] cbuf, int off, int len)
      • Methods inherited from class java.io.Writer

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

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

      • buf

        private final java.io.ByteArrayOutputStream buf
      • enc

        private final java.io.OutputStreamWriter enc
    • Constructor Detail

      • MessageWriter

        public MessageWriter()
        Create an empty writer.
    • Method Detail

      • write

        public void write​(char[] cbuf,
                          int off,
                          int len)
                   throws java.io.IOException
        Specified by:
        write in class java.io.Writer
        Throws:
        java.io.IOException
      • getRawStream

        public java.io.OutputStream getRawStream()
        Get the underlying byte stream that character writes to this writer drop into.
        Returns:
        the underlying byte stream that character writes to this writer drop into. Writes to this stream should should be in UTF-8.
      • close

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

        public void flush()
                   throws java.io.IOException
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
        Throws:
        java.io.IOException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object