Interface Stream

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      void close()
      Closes the connection.
      ServerAddress getAddress()
      The address that this stream is connected to.
      boolean isClosed()
      Returns the closed state of the connection
      void open()
      Open the stream.
      void openAsync​(AsyncCompletionHandler<java.lang.Void> handler)
      Open the stream asynchronously.
      org.bson.ByteBuf read​(int numBytes)
      Read from the stream, blocking until the requested number of bytes have been read.
      default org.bson.ByteBuf read​(int numBytes, int additionalTimeout)
      Read from the stream, blocking until the requested number of bytes have been read.
      void readAsync​(int numBytes, AsyncCompletionHandler<org.bson.ByteBuf> handler)
      Read from the stream, asynchronously.
      default boolean supportsAdditionalTimeout()
      Gets whether this implementation supports specifying an additional timeout for read operations
      void write​(java.util.List<org.bson.ByteBuf> buffers)
      Write each buffer in the list to the stream in order, blocking until all are completely written.
      void writeAsync​(java.util.List<org.bson.ByteBuf> buffers, AsyncCompletionHandler<java.lang.Void> handler)
      Write each buffer in the list to the stream in order, asynchronously.
    • Method Detail

      • open

        void open()
           throws java.io.IOException
        Open the stream.
        Throws:
        java.io.IOException - if an I/O error occurs
      • openAsync

        void openAsync​(AsyncCompletionHandler<java.lang.Void> handler)
        Open the stream asynchronously.
        Parameters:
        handler - the completion handler for opening the stream
      • write

        void write​(java.util.List<org.bson.ByteBuf> buffers)
            throws java.io.IOException
        Write each buffer in the list to the stream in order, blocking until all are completely written.
        Parameters:
        buffers - the buffers to write
        Throws:
        java.io.IOException - if there are problems writing to the stream
      • read

        org.bson.ByteBuf read​(int numBytes)
                       throws java.io.IOException
        Read from the stream, blocking until the requested number of bytes have been read.
        Parameters:
        numBytes - The number of bytes to read into the returned byte buffer
        Returns:
        a byte buffer filled with number of bytes requested
        Throws:
        java.io.IOException - if there are problems reading from the stream
      • supportsAdditionalTimeout

        default boolean supportsAdditionalTimeout()
        Gets whether this implementation supports specifying an additional timeout for read operations

        The default is to not support specifying an additional timeout

        Returns:
        true if this implementation supports specifying an additional timeouts for reads operations
        Since:
        4.1
        See Also:
        read(int, int)
      • read

        default org.bson.ByteBuf read​(int numBytes,
                                      int additionalTimeout)
                               throws java.io.IOException
        Read from the stream, blocking until the requested number of bytes have been read. If supported by the implementation, adds the given additional timeout to the configured timeout for the stream.

        This method should not be called unless supportsAdditionalTimeout() returns true.

        The default behavior is to throw an UnsupportedOperationException

        Parameters:
        numBytes - The number of bytes to read into the returned byte buffer
        additionalTimeout - additional timeout in milliseconds to add to the configured timeout
        Returns:
        a byte buffer filled with number of bytes requested
        Throws:
        java.io.IOException - if there are problems reading from the stream
        java.lang.UnsupportedOperationException - if this implementation does not support additional timeouts
        Since:
        4.1
        See Also:
        supportsAdditionalTimeout()
      • writeAsync

        void writeAsync​(java.util.List<org.bson.ByteBuf> buffers,
                        AsyncCompletionHandler<java.lang.Void> handler)
        Write each buffer in the list to the stream in order, asynchronously. This method should return immediately, and invoke the given callback on completion.
        Parameters:
        buffers - the buffers to write
        handler - invoked when the read operation has completed
      • readAsync

        void readAsync​(int numBytes,
                       AsyncCompletionHandler<org.bson.ByteBuf> handler)
        Read from the stream, asynchronously. This method should return immediately, and invoke the given callback when the number of requested bytes have been read.
        Parameters:
        numBytes - the number of bytes
        handler - invoked when the read operation has completed
      • getAddress

        ServerAddress getAddress()
        The address that this stream is connected to.
        Returns:
        the address
      • close

        void close()
        Closes the connection.
      • isClosed

        boolean isClosed()
        Returns the closed state of the connection
        Returns:
        true if connection is closed