Class MockSocketChannel

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.GatheringByteChannel, java.nio.channels.InterruptibleChannel, java.nio.channels.NetworkChannel, java.nio.channels.ReadableByteChannel, java.nio.channels.ScatteringByteChannel, java.nio.channels.WritableByteChannel

    public class MockSocketChannel
    extends java.nio.channels.SocketChannel
    A mock SocketChannel for testing
    Since:
    3.6.5
    Author:
    Bela Ban
    • Constructor Summary

      Constructors 
      Constructor Description
      MockSocketChannel()  
      MockSocketChannel​(java.nio.channels.spi.SelectorProvider provider)
      Initializes a new instance of this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.nio.channels.SocketChannel bind​(java.net.SocketAddress local)  
      java.nio.ByteBuffer bytesToRead()  
      MockSocketChannel bytesToRead​(byte[] buf)  
      MockSocketChannel bytesToRead​(java.nio.ByteBuffer buf)  
      MockSocketChannel bytesToWrite​(int num)  
      boolean connect​(java.net.SocketAddress remote)  
      void doClose()  
      boolean finishConnect()  
      java.net.SocketAddress getLocalAddress()  
      <T> T getOption​(java.net.SocketOption<T> name)  
      java.net.SocketAddress getRemoteAddress()  
      protected void implCloseSelectableChannel()  
      protected void implConfigureBlocking​(boolean block)  
      boolean isConnected()  
      boolean isConnectionPending()  
      int read​(java.nio.ByteBuffer dst)  
      long read​(java.nio.ByteBuffer[] dsts, int offset, int length)  
      java.nio.ByteBuffer recorder()  
      MockSocketChannel recorder​(java.nio.ByteBuffer buf)  
      <T> java.nio.channels.SocketChannel setOption​(java.net.SocketOption<T> name, T value)  
      java.nio.channels.SocketChannel shutdownInput()  
      java.nio.channels.SocketChannel shutdownOutput()  
      java.net.Socket socket()  
      java.util.Set<java.net.SocketOption<?>> supportedOptions()  
      int write​(java.nio.ByteBuffer buf)  
      long write​(java.nio.ByteBuffer[] srcs, int offset, int length)  
      • Methods inherited from class java.nio.channels.SocketChannel

        open, open, read, validOps, write
      • Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel

        blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
      • Methods inherited from class java.nio.channels.SelectableChannel

        register
      • Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel

        begin, close, end, isOpen
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.nio.channels.Channel

        isOpen
    • Field Detail

      • bytes_to_write

        protected int bytes_to_write
      • bytes_to_read

        protected java.nio.ByteBuffer bytes_to_read
      • closed

        protected boolean closed
      • recorder

        protected java.nio.ByteBuffer recorder
    • Constructor Detail

      • MockSocketChannel

        public MockSocketChannel()
      • MockSocketChannel

        public MockSocketChannel​(java.nio.channels.spi.SelectorProvider provider)
        Initializes a new instance of this class.
        Parameters:
        provider - The provider that created this channel
    • Method Detail

      • bytesToRead

        public java.nio.ByteBuffer bytesToRead()
      • recorder

        public java.nio.ByteBuffer recorder()
      • bind

        public java.nio.channels.SocketChannel bind​(java.net.SocketAddress local)
                                             throws java.io.IOException
        Specified by:
        bind in interface java.nio.channels.NetworkChannel
        Specified by:
        bind in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • doClose

        public void doClose()
      • setOption

        public <T> java.nio.channels.SocketChannel setOption​(java.net.SocketOption<T> name,
                                                             T value)
                                                      throws java.io.IOException
        Specified by:
        setOption in interface java.nio.channels.NetworkChannel
        Specified by:
        setOption in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • getOption

        public <T> T getOption​(java.net.SocketOption<T> name)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • supportedOptions

        public java.util.Set<java.net.SocketOption<?>> supportedOptions()
      • shutdownInput

        public java.nio.channels.SocketChannel shutdownInput()
                                                      throws java.io.IOException
        Specified by:
        shutdownInput in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • shutdownOutput

        public java.nio.channels.SocketChannel shutdownOutput()
                                                       throws java.io.IOException
        Specified by:
        shutdownOutput in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • socket

        public java.net.Socket socket()
        Specified by:
        socket in class java.nio.channels.SocketChannel
      • isConnected

        public boolean isConnected()
        Specified by:
        isConnected in class java.nio.channels.SocketChannel
      • isConnectionPending

        public boolean isConnectionPending()
        Specified by:
        isConnectionPending in class java.nio.channels.SocketChannel
      • connect

        public boolean connect​(java.net.SocketAddress remote)
                        throws java.io.IOException
        Specified by:
        connect in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • finishConnect

        public boolean finishConnect()
                              throws java.io.IOException
        Specified by:
        finishConnect in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • getRemoteAddress

        public java.net.SocketAddress getRemoteAddress()
                                                throws java.io.IOException
        Specified by:
        getRemoteAddress in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Specified by:
        read in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • read

        public long read​(java.nio.ByteBuffer[] dsts,
                         int offset,
                         int length)
                  throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ScatteringByteChannel
        Specified by:
        read in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • write

        public int write​(java.nio.ByteBuffer buf)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Specified by:
        write in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • write

        public long write​(java.nio.ByteBuffer[] srcs,
                          int offset,
                          int length)
                   throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.GatheringByteChannel
        Specified by:
        write in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • getLocalAddress

        public java.net.SocketAddress getLocalAddress()
                                               throws java.io.IOException
        Specified by:
        getLocalAddress in interface java.nio.channels.NetworkChannel
        Specified by:
        getLocalAddress in class java.nio.channels.SocketChannel
        Throws:
        java.io.IOException
      • implCloseSelectableChannel

        protected void implCloseSelectableChannel()
                                           throws java.io.IOException
        Specified by:
        implCloseSelectableChannel in class java.nio.channels.spi.AbstractSelectableChannel
        Throws:
        java.io.IOException
      • implConfigureBlocking

        protected void implConfigureBlocking​(boolean block)
                                      throws java.io.IOException
        Specified by:
        implConfigureBlocking in class java.nio.channels.spi.AbstractSelectableChannel
        Throws:
        java.io.IOException