Package net.officefloor.server.http.mock
Class MockStreamBufferPool
- java.lang.Object
-
- net.officefloor.server.http.mock.MockStreamBufferPool
-
- All Implemented Interfaces:
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 voidassertAllBuffersReturned()Asserts that allStreamBufferinstances have been released.static java.io.InputStreamcreateInputStream(StreamBuffer<java.nio.ByteBuffer> headBuffer)Creates anInputStreamto the content of theStreamBufferinstances.static java.lang.StringgetContent(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 aStreamBufferfor theFileChannelcontent.StreamBuffer<java.nio.ByteBuffer>getPooledStreamBuffer()Obtains aStreamBuffer.StreamBuffer<java.nio.ByteBuffer>getUnpooledStreamBuffer(java.nio.ByteBuffer byteBuffer)Obtains anStreamBufferthat is not pooled.booleanisActiveBuffers()Indicates if there are activeStreamBufferinstances.static voidreleaseStreamBuffers(StreamBuffer<java.nio.ByteBuffer> headBuffer)Releases theStreamBufferinstances.
-
-
-
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 theStreamBufferinstances.- Parameters:
headBuffer- HeadStreamBufferof linked list ofStreamBufferinstances.
-
createInputStream
public static java.io.InputStream createInputStream(StreamBuffer<java.nio.ByteBuffer> headBuffer)
Creates anInputStreamto the content of theStreamBufferinstances.- Parameters:
headBuffer- HeadStreamBufferof linked list ofStreamBufferinstances.- Returns:
InputStreamto read the data from theStreamBufferinstances.
-
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- 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
public StreamBuffer<java.nio.ByteBuffer> getPooledStreamBuffer()
Description copied from interface:StreamBufferPoolObtains aStreamBuffer.- Specified by:
getPooledStreamBufferin interfaceStreamBufferPool<java.nio.ByteBuffer>- Returns:
StreamBuffer.
-
getUnpooledStreamBuffer
public StreamBuffer<java.nio.ByteBuffer> getUnpooledStreamBuffer(java.nio.ByteBuffer byteBuffer)
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<java.nio.ByteBuffer>- Parameters:
byteBuffer-ByteBuffer.- Returns:
StreamBufferfor the unpooledByteBuffer.
-
getFileStreamBuffer
public StreamBuffer<java.nio.ByteBuffer> getFileStreamBuffer(java.nio.channels.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<java.nio.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.
-
-