Class VertxBufferPool
java.lang.Object
net.officefloor.server.stream.StreamBuffer<io.vertx.core.buffer.Buffer>
net.officefloor.server.http.vertx.VertxBufferPool
- All Implemented Interfaces:
AutoCloseable,StreamBufferPool<io.vertx.core.buffer.Buffer>
public class VertxBufferPool
extends StreamBuffer<io.vertx.core.buffer.Buffer>
implements StreamBufferPool<io.vertx.core.buffer.Buffer>
Vertx StreamBufferPool.- Author:
- Daniel Sagenschneider
-
Nested Class Summary
Nested classes/interfaces inherited from class net.officefloor.server.stream.StreamBuffer
StreamBuffer.FileBuffer -
Field Summary
Fields inherited from class net.officefloor.server.stream.StreamBuffer
fileBuffer, next, pooledBuffer, unpooledByteBuffer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes pool releasing allStreamBufferinstances.StreamBuffer<io.vertx.core.buffer.Buffer>getFileStreamBuffer(FileChannel file, long position, long count, FileCompleteCallback callback) Obtains aStreamBufferfor theFileChannelcontent.StreamBuffer<io.vertx.core.buffer.Buffer>Obtains aStreamBuffer.StreamBuffer<io.vertx.core.buffer.Buffer>getUnpooledStreamBuffer(ByteBuffer buffer) Obtains anStreamBufferthat is not pooled.voidrelease()Releases thisStreamBufferfor re-use.booleanwrite(byte datum) Writes a byte to the pooled buffer.intwrite(byte[] data, int offset, int length) Writes the data to the pooled buffer.Methods inherited from class net.officefloor.server.stream.StreamBuffer
getAppendable, getWriteStreamBuffer, write, write, write, write, write, write, writeByte
-
Constructor Details
-
VertxBufferPool
public VertxBufferPool()Instantiate.
-
-
Method Details
-
getPooledStreamBuffer
Description copied from interface:StreamBufferPoolObtains aStreamBuffer.- Specified by:
getPooledStreamBufferin interfaceStreamBufferPool<io.vertx.core.buffer.Buffer>- 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<io.vertx.core.buffer.Buffer>- Parameters:
buffer-ByteBuffer.- Returns:
StreamBufferfor the unpooledByteBuffer.
-
getFileStreamBuffer
public StreamBuffer<io.vertx.core.buffer.Buffer> getFileStreamBuffer(FileChannel file, long position, long count, FileCompleteCallback callback) throws IOException 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<io.vertx.core.buffer.Buffer>- 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.- Throws:
IOException- If fails to create theStreamBufferfor theFileChannel. Typically, this is because the underlying implementation does not support DMA and copies the data from theFileChannel.
-
close
public void close()Description copied from interface:StreamBufferPoolCloses pool releasing allStreamBufferinstances.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceStreamBufferPool<io.vertx.core.buffer.Buffer>
-
write
public boolean write(byte datum) Description copied from class:StreamBufferWrites a byte to the pooled buffer.- Specified by:
writein classStreamBuffer<io.vertx.core.buffer.Buffer>- Parameters:
datum- Byte value.- Returns:
trueif written value to buffer.falseindicates the pooled buffer is full.
-
write
public int write(byte[] data, int offset, int length) Description copied from class:StreamBufferWrites the data to the pooled buffer.- Specified by:
writein classStreamBuffer<io.vertx.core.buffer.Buffer>- Parameters:
data- Data to write to the pooled buffer.offset- Offset within the data to write the data.length- Length of data to write the data.- Returns:
- Number of bytes written.
-
release
public void release()Description copied from class:StreamBufferReleases thisStreamBufferfor re-use.- Specified by:
releasein classStreamBuffer<io.vertx.core.buffer.Buffer>
-