Class MockStreamBufferPool

  • All Implemented Interfaces:
    java.lang.AutoCloseable, StreamBufferPool<java.nio.ByteBuffer>

    public class MockStreamBufferPool
    extends java.lang.Object
    implements StreamBufferPool<java.nio.ByteBuffer>
    Author:
    Daniel Sagenschneider
    • Constructor Detail

      • MockStreamBufferPool

        public MockStreamBufferPool()
        Instantiate with default buffer size for testing.
    • Method Detail

      • createInputStream

        public static java.io.InputStream createInputStream​(StreamBuffer<java.nio.ByteBuffer> headBuffer)
        Creates an InputStream to the content of the StreamBuffer instances.
        Parameters:
        headBuffer - Head StreamBuffer of linked list of StreamBuffer instances.
        Returns:
        InputStream to read the data from the StreamBuffer instances.
      • getContent

        public static java.lang.String getContent​(StreamBuffer<java.nio.ByteBuffer> headBuffer,
                                                  java.nio.charset.Charset charset)
        Convenience method to obtain the contents of the buffers as a string.
        Parameters:
        headBuffer - Head StreamBuffer of linked list of StreamBuffer instances.
        charset - Charset of underlying data.
        Returns:
        Content of buffers as string.
      • isActiveBuffers

        public boolean isActiveBuffers()
        Indicates if there are active StreamBuffer instances.
        Returns:
        true if there are active StreamBuffer instances not released back to this StreamBufferPool.
      • assertAllBuffersReturned

        public void assertAllBuffersReturned()
        Asserts that all StreamBuffer instances have been released.
      • getUnpooledStreamBuffer

        public StreamBuffer<java.nio.ByteBuffer> getUnpooledStreamBuffer​(java.nio.ByteBuffer byteBuffer)
        Description copied from interface: StreamBufferPool

        Obtains an StreamBuffer that is not pooled. This is for ByteBuffer instances that are managed outside the BufferPool.

        Typical use is to create StreamBuffer for some read-only cached content within a ByteBuffer.

        Specified by:
        getUnpooledStreamBuffer in interface StreamBufferPool<java.nio.ByteBuffer>
        Parameters:
        byteBuffer - ByteBuffer.
        Returns:
        StreamBuffer for the unpooled ByteBuffer.
      • getFileStreamBuffer

        public StreamBuffer<java.nio.ByteBuffer> getFileStreamBuffer​(java.nio.channels.FileChannel file,
                                                                     long position,
                                                                     long count,
                                                                     FileCompleteCallback callback)
        Description copied from interface: StreamBufferPool

        Obtains a StreamBuffer for the FileChannel content.

        This enables efficient writing (ie DMA) of FileChannel content.

        To write the entire FileChannel contents, invoke write(file, 0, -1).

        Note that the underlying implementation will need to support FileChannel efficiencies.

        Specified by:
        getFileStreamBuffer in interface StreamBufferPool<java.nio.ByteBuffer>
        Parameters:
        file - FileChannel.
        position - Position within the FileChannel to start writing content. Must be non-negative number.
        count - Count of bytes to write from the FileChannel. A negative value (typically -1) indicates to write the remaining FileChannel content from the position.
        callback - Optional FileCompleteCallback. May be null.
        Returns:
        StreamBuffer for the FileChannel.
      • close

        public void close()
        Description copied from interface: StreamBufferPool
        Closes pool releasing all StreamBuffer instances.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface StreamBufferPool<java.nio.ByteBuffer>