Class NbChannelOutputStream

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

    public class NbChannelOutputStream
    extends java.io.OutputStream
    Output stream connected to a non-blocking writable channel.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.ByteBuffer bb
      The internal byte buffer.
      private java.nio.channels.WritableByteChannel channel
      The channel to write to.
      private java.nio.channels.SelectableChannel selectableChannel
      The selectable channel to write to.
      private java.nio.channels.SelectionKey selectionKey
      The selection key.
      private java.nio.channels.Selector selector
      The selector.
    • Constructor Summary

      Constructors 
      Constructor Description
      NbChannelOutputStream​(java.nio.channels.WritableByteChannel channel)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void doWrite()
      Effectively write the current byte buffer.
      void write​(byte[] b, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.OutputStream

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

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

      • bb

        private final java.nio.ByteBuffer bb
        The internal byte buffer.
      • channel

        private final java.nio.channels.WritableByteChannel channel
        The channel to write to.
      • selectableChannel

        private final java.nio.channels.SelectableChannel selectableChannel
        The selectable channel to write to.
      • selectionKey

        private volatile java.nio.channels.SelectionKey selectionKey
        The selection key.
      • selector

        private volatile java.nio.channels.Selector selector
        The selector.
    • Constructor Detail

      • NbChannelOutputStream

        public NbChannelOutputStream​(java.nio.channels.WritableByteChannel channel)
        Constructor.
        Parameters:
        channel - The wrapped channel.
    • Method Detail

      • doWrite

        private void doWrite()
                      throws java.io.IOException
        Effectively write the current byte buffer.
        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