Class LimitedQueueBuffer<T>

  • All Implemented Interfaces:
    IoBuffer<T>, Input<T>, Output<T>, java.io.Closeable, java.lang.AutoCloseable

    public class LimitedQueueBuffer<T>
    extends java.lang.Object
    implements IoBuffer<T>
    The blocking queue wrapped in order to act as output from the tail and as input from the head.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.concurrent.BlockingQueue<T> queue  
      • Fields inherited from interface com.github.akurilov.commons.io.Input

        DELIMITER
    • Constructor Summary

      Constructors 
      Constructor Description
      LimitedQueueBuffer​(java.util.concurrent.BlockingQueue<T> queue)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Does nothing
      T get()
      Non-blocking get implementation
      int get​(java.util.List<T> buffer, int maxCount)
      Non-blocking bulk get implementation
      LimitedQueueBuffer<T> getInput()
      Make a Input instance from this.
      boolean isEmpty()  
      int put​(java.util.List<T> items)  
      int put​(java.util.List<T> buffer, int from, int to)
      Non-blocking bulk put implementation
      boolean put​(T item)
      Non-blocking put implementation
      void reset()
      Does nothing
      int size()  
      long skip​(long itemsCount)
      Skip some items.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • queue

        protected final java.util.concurrent.BlockingQueue<T> queue
    • Constructor Detail

      • LimitedQueueBuffer

        public LimitedQueueBuffer​(java.util.concurrent.BlockingQueue<T> queue)
    • Method Detail

      • put

        public boolean put​(T item)
        Non-blocking put implementation
        Specified by:
        put in interface Output<T>
        Parameters:
        item - the item to put
      • put

        public int put​(java.util.List<T> buffer,
                       int from,
                       int to)
                throws java.io.IOException
        Non-blocking bulk put implementation
        Specified by:
        put in interface Output<T>
        Parameters:
        buffer - the buffer containing the items to put
        Returns:
        the count of the items been written, may return less count than specified if not enough free capacity is in the queue
        Throws:
        java.io.IOException - doesn't throw
      • put

        public final int put​(java.util.List<T> items)
                      throws java.io.IOException
        Specified by:
        put in interface Output<T>
        Throws:
        java.io.IOException
      • getInput

        public LimitedQueueBuffer<T> getInput()
                                       throws java.io.IOException
        Description copied from interface: Output
        Make a Input instance from this.
        Specified by:
        getInput in interface Output<T>
        Returns:
        self
        Throws:
        java.io.IOException - doesn't throw
      • get

        public T get()
              throws java.io.IOException
        Non-blocking get implementation
        Specified by:
        get in interface Input<T>
        Returns:
        the item or null if the buffer is empty
        Throws:
        java.io.IOException - doesn't throw
      • get

        public int get​(java.util.List<T> buffer,
                       int maxCount)
                throws java.io.IOException
        Non-blocking bulk get implementation
        Specified by:
        get in interface Input<T>
        Parameters:
        maxCount - the count limit
        buffer - buffer for the items
        Returns:
        the count of the items been get
        Throws:
        java.io.IOException - if something goes wrong
      • skip

        public long skip​(long itemsCount)
                  throws java.io.IOException
        Description copied from interface: Input
        Skip some items.
        Specified by:
        skip in interface Input<T>
        Parameters:
        itemsCount - count of items should be skipped from the input stream
        Throws:
        java.io.IOException - if failed to skip such amount of bytes
      • isEmpty

        public final boolean isEmpty()
        Specified by:
        isEmpty in interface IoBuffer<T>
        Returns:
        true if the buffer is empty
      • size

        public final int size()
        Specified by:
        size in interface IoBuffer<T>
        Returns:
        count of the items in the buffer
      • reset

        public void reset()
                   throws java.io.IOException
        Does nothing
        Specified by:
        reset in interface Input<T>
        Throws:
        java.io.IOException - doesn't throw
      • close

        public void close()
                   throws java.io.IOException
        Does nothing
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException - doesn't throw
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object