Package net.officefloor.server.http.mock
Class MockStreamBufferPool
- java.lang.Object
-
- net.officefloor.server.http.mock.MockStreamBufferPool
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,StreamBufferPool<java.nio.ByteBuffer>
public class MockStreamBufferPool extends java.lang.Object implements StreamBufferPool<java.nio.ByteBuffer>
MockStreamBufferPool
.- Author:
- Daniel Sagenschneider
-
-
Constructor Summary
Constructors Constructor Description MockStreamBufferPool()
Instantiate with default buffer size for testing.MockStreamBufferPool(ByteBufferFactory byteBufferFactory)
Instantiate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertAllBuffersReturned()
Asserts that allStreamBuffer
instances have been released.void
close()
Closes pool releasing allStreamBuffer
instances.static java.io.InputStream
createInputStream(StreamBuffer<java.nio.ByteBuffer> headBuffer)
Creates anInputStream
to the content of theStreamBuffer
instances.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.StreamBuffer<java.nio.ByteBuffer>
getFileStreamBuffer(java.nio.channels.FileChannel file, long position, long count, FileCompleteCallback callback)
Obtains aStreamBuffer
for theFileChannel
content.StreamBuffer<java.nio.ByteBuffer>
getPooledStreamBuffer()
Obtains aStreamBuffer
.StreamBuffer<java.nio.ByteBuffer>
getUnpooledStreamBuffer(java.nio.ByteBuffer byteBuffer)
Obtains anStreamBuffer
that is not pooled.boolean
isActiveBuffers()
Indicates if there are activeStreamBuffer
instances.static void
releaseStreamBuffers(StreamBuffer<java.nio.ByteBuffer> headBuffer)
Releases theStreamBuffer
instances.
-
-
-
Constructor Detail
-
MockStreamBufferPool
public MockStreamBufferPool()
Instantiate with default buffer size for testing.
-
MockStreamBufferPool
public MockStreamBufferPool(ByteBufferFactory byteBufferFactory)
Instantiate.- Parameters:
byteBufferFactory
-ByteBufferFactory
.
-
-
Method Detail
-
releaseStreamBuffers
public static void releaseStreamBuffers(StreamBuffer<java.nio.ByteBuffer> headBuffer)
Releases theStreamBuffer
instances.- Parameters:
headBuffer
- HeadStreamBuffer
of linked list ofStreamBuffer
instances.
-
createInputStream
public static java.io.InputStream createInputStream(StreamBuffer<java.nio.ByteBuffer> headBuffer)
Creates anInputStream
to the content of theStreamBuffer
instances.- Parameters:
headBuffer
- HeadStreamBuffer
of linked list ofStreamBuffer
instances.- Returns:
InputStream
to read the data from theStreamBuffer
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
- HeadStreamBuffer
of linked list ofStreamBuffer
instances.charset
-Charset
of underlying data.- Returns:
- Content of buffers as string.
-
isActiveBuffers
public boolean isActiveBuffers()
Indicates if there are activeStreamBuffer
instances.- Returns:
true
if there are activeStreamBuffer
instances not released back to thisStreamBufferPool
.
-
assertAllBuffersReturned
public void assertAllBuffersReturned()
Asserts that allStreamBuffer
instances have been released.
-
getPooledStreamBuffer
public StreamBuffer<java.nio.ByteBuffer> getPooledStreamBuffer()
Description copied from interface:StreamBufferPool
Obtains aStreamBuffer
.- Specified by:
getPooledStreamBuffer
in interfaceStreamBufferPool<java.nio.ByteBuffer>
- Returns:
StreamBuffer
.
-
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 forByteBuffer
instances that are managed outside the BufferPool.Typical use is to create
StreamBuffer
for some read-only cached content within aByteBuffer
.- Specified by:
getUnpooledStreamBuffer
in interfaceStreamBufferPool<java.nio.ByteBuffer>
- Parameters:
byteBuffer
-ByteBuffer
.- Returns:
StreamBuffer
for the unpooledByteBuffer
.
-
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 theFileChannel
content.This enables efficient writing (ie DMA) of
FileChannel
content.To write the entire
FileChannel
contents, invokewrite(file, 0, -1)
.Note that the underlying implementation will need to support
FileChannel
efficiencies.- Specified by:
getFileStreamBuffer
in interfaceStreamBufferPool<java.nio.ByteBuffer>
- Parameters:
file
-FileChannel
.position
- Position within theFileChannel
to start writing content. Must be non-negative number.count
- Count of bytes to write from theFileChannel
. A negative value (typically-1
) indicates to write the remainingFileChannel
content from the position.callback
- OptionalFileCompleteCallback
. May benull
.- Returns:
StreamBuffer
for theFileChannel
.
-
close
public void close()
Description copied from interface:StreamBufferPool
Closes pool releasing allStreamBuffer
instances.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceStreamBufferPool<java.nio.ByteBuffer>
-
-