Class WriteBuffer


  • public class WriteBuffer
    extends java.lang.Object
    Provides an expandable set of buffers for writes. Non-blocking writes can be of any size and may not be able to be written immediately or wholly contained in the buffer used to perform the writes to the next layer. This class provides a buffering capability to allow such writes to return immediately and also allows for the user provided buffers to be re-used / recycled as required.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  WriteBuffer.Sink
      Interface implemented by clients of the WriteBuffer to enable data to be written back out from the buffer.
    • Constructor Summary

      Constructors 
      Constructor Description
      WriteBuffer​(int bufferSize)
      Constructs a new WriteBuffer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(java.nio.ByteBuffer from)
      Adds data from a ByteBuffer to this write buffer.
      boolean isEmpty()
      Returns whether this write buffer is empty.
      boolean write​(WriteBuffer.Sink sink, boolean blocking)
      Writes data from this buffer to the given sink.
      • Methods inherited from class java.lang.Object

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

      • WriteBuffer

        public WriteBuffer​(int bufferSize)
        Constructs a new WriteBuffer.
        Parameters:
        bufferSize - The size of internal buffers
    • Method Detail

      • add

        public void add​(java.nio.ByteBuffer from)
        Adds data from a ByteBuffer to this write buffer.
        Parameters:
        from - The source ByteBuffer
      • isEmpty

        public boolean isEmpty()
        Returns whether this write buffer is empty.
        Returns:
        true if empty
      • write

        public boolean write​(WriteBuffer.Sink sink,
                             boolean blocking)
                      throws java.io.IOException
        Writes data from this buffer to the given sink.
        Parameters:
        sink - The sink to write to
        blocking - Whether to use blocking writes
        Returns:
        true if data is left unwritten, false otherwise
        Throws:
        java.io.IOException - If an I/O error occurs