Package net.officefloor.server.http.mock
Class MockStreamBufferPool
java.lang.Object
net.officefloor.server.http.mock.MockStreamBufferPool
- All Implemented Interfaces:
AutoCloseable,StreamBufferPool<ByteBuffer>
Mock
StreamBufferPool.- Author:
- Daniel Sagenschneider
-
Constructor Summary
ConstructorsConstructorDescriptionInstantiate with default buffer size for testing.MockStreamBufferPool(ByteBufferFactory byteBufferFactory) Instantiate. -
Method Summary
Modifier and TypeMethodDescriptionvoidAsserts that allStreamBufferinstances have been released.voidclose()Closes pool releasing allStreamBufferinstances.static InputStreamcreateInputStream(StreamBuffer<ByteBuffer> headBuffer) Creates anInputStreamto the content of theStreamBufferinstances.static StringgetContent(StreamBuffer<ByteBuffer> headBuffer, Charset charset) Convenience method to obtain the contents of the buffers as a string.getFileStreamBuffer(FileChannel file, long position, long count, FileCompleteCallback callback) Obtains aStreamBufferfor theFileChannelcontent.Obtains aStreamBuffer.getUnpooledStreamBuffer(ByteBuffer byteBuffer) Obtains anStreamBufferthat is not pooled.booleanIndicates if there are activeStreamBufferinstances.static voidreleaseStreamBuffers(StreamBuffer<ByteBuffer> headBuffer) Releases theStreamBufferinstances.
-
Constructor Details
-
MockStreamBufferPool
public MockStreamBufferPool()Instantiate with default buffer size for testing. -
MockStreamBufferPool
Instantiate.- Parameters:
byteBufferFactory-ByteBufferFactory.
-
-
Method Details
-
releaseStreamBuffers
Releases theStreamBufferinstances.- Parameters:
headBuffer- HeadStreamBufferof linked list ofStreamBufferinstances.
-
createInputStream
Creates anInputStreamto the content of theStreamBufferinstances.- Parameters:
headBuffer- HeadStreamBufferof linked list ofStreamBufferinstances.- Returns:
InputStreamto read the data from theStreamBufferinstances.
-
getContent
Convenience method to obtain the contents of the buffers as a string.- Parameters:
headBuffer- HeadStreamBufferof linked list ofStreamBufferinstances.charset-Charsetof underlying data.- Returns:
- Content of buffers as string.
-
isActiveBuffers
public boolean isActiveBuffers()Indicates if there are activeStreamBufferinstances.- Returns:
trueif there are activeStreamBufferinstances not released back to thisStreamBufferPool.
-
assertAllBuffersReturned
public void assertAllBuffersReturned()Asserts that allStreamBufferinstances have been released. -
getPooledStreamBuffer
Description copied from interface:StreamBufferPoolObtains aStreamBuffer.- Specified by:
getPooledStreamBufferin interfaceStreamBufferPool<ByteBuffer>- Returns:
StreamBuffer.
-
getUnpooledStreamBuffer
Description copied from interface:StreamBufferPoolObtains an
StreamBufferthat is not pooled. This is forByteBufferinstances that are managed outside the BufferPool.Typical use is to create
StreamBufferfor some read-only cached content within aByteBuffer.- Specified by:
getUnpooledStreamBufferin interfaceStreamBufferPool<ByteBuffer>- Parameters:
byteBuffer-ByteBuffer.- Returns:
StreamBufferfor the unpooledByteBuffer.
-
getFileStreamBuffer
public StreamBuffer<ByteBuffer> getFileStreamBuffer(FileChannel file, long position, long count, FileCompleteCallback callback) Description copied from interface:StreamBufferPoolObtains a
StreamBufferfor theFileChannelcontent.This enables efficient writing (ie DMA) of
FileChannelcontent.To write the entire
FileChannelcontents, invokewrite(file, 0, -1).Note that the underlying implementation will need to support
FileChannelefficiencies.- Specified by:
getFileStreamBufferin interfaceStreamBufferPool<ByteBuffer>- Parameters:
file-FileChannel.position- Position within theFileChannelto 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 remainingFileChannelcontent from the position.callback- OptionalFileCompleteCallback. May benull.- Returns:
StreamBufferfor theFileChannel.
-
close
public void close()Description copied from interface:StreamBufferPoolCloses pool releasing allStreamBufferinstances.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStreamBufferPool<ByteBuffer>
-