Class SideBandOutputStream

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

    public class SideBandOutputStream
    extends java.io.OutputStream
    Multiplexes data and progress messages.

    This stream is buffered at packet sizes, so the caller doesn't need to wrap it in yet another buffered stream.

    Since:
    2.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer  
      static int CH_DATA
      Channel used for pack data.
      static int CH_ERROR
      Channel used for error messages.
      static int CH_PROGRESS
      Channel used for progress messages.
      private int cnt
      Number of bytes in buffer that are valid data.
      (package private) static int HDR_SIZE  
      static int MAX_BUF
      Maximum buffer size for a single packet of sideband data.
      private java.io.OutputStream out  
      static int SMALL_BUF
      Default buffer size for a small amount of data.
    • Constructor Summary

      Constructors 
      Constructor Description
      SideBandOutputStream​(int chan, int sz, java.io.OutputStream os)
      Create a new stream to write side band packets.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flush()
      (package private) void flushBuffer()  
      void write​(byte[] b, int off, int len)
      void write​(int b)
      private void writeBuffer()  
      • Methods inherited from class java.io.OutputStream

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

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

      • CH_PROGRESS

        public static final int CH_PROGRESS
        Channel used for progress messages.
        See Also:
        Constant Field Values
      • CH_ERROR

        public static final int CH_ERROR
        Channel used for error messages.
        See Also:
        Constant Field Values
      • SMALL_BUF

        public static final int SMALL_BUF
        Default buffer size for a small amount of data.
        See Also:
        Constant Field Values
      • MAX_BUF

        public static final int MAX_BUF
        Maximum buffer size for a single packet of sideband data.
        See Also:
        Constant Field Values
      • out

        private final java.io.OutputStream out
      • buffer

        private final byte[] buffer
      • cnt

        private int cnt
        Number of bytes in buffer that are valid data.

        Initialized to HDR_SIZE if there is no application data in the buffer, as the packet header always appears at the start of the buffer.

    • Constructor Detail

      • SideBandOutputStream

        public SideBandOutputStream​(int chan,
                                    int sz,
                                    java.io.OutputStream os)
        Create a new stream to write side band packets.
        Parameters:
        chan - channel number to prefix all packets with, so the remote side can demultiplex the stream and get back the original data. Must be in the range [1, 255].
        sz - maximum size of a data packet within the stream. The remote side needs to agree to the packet size to prevent buffer overflows. Must be in the range [HDR_SIZE + 1, MAX_BUF).
        os - stream that the packets are written onto. This stream should be attached to a SideBandInputStream on the remote side.
    • Method Detail

      • flushBuffer

        void flushBuffer()
                  throws java.io.IOException
        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
      • 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
      • write

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

        private void writeBuffer()
                          throws java.io.IOException
        Throws:
        java.io.IOException