Package net.officefloor.server.stream
Class StreamBuffer<B>
- java.lang.Object
-
- net.officefloor.server.stream.StreamBuffer<B>
-
- Type Parameters:
B- Type of buffer.
- Direct Known Subclasses:
AbstractStreamBufferPool.FileStreamBuffer,AbstractStreamBufferPool.UnpooledStreamBuffer,NettyBufferPool
public abstract class StreamBuffer<B> extends java.lang.ObjectBuffer that is part of a stream.- Author:
- Daniel Sagenschneider
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStreamBuffer.FileBufferFileChannelcontent buffer.
-
Field Summary
Fields Modifier and Type Field Description StreamBuffer.FileBufferfileBufferObtains theStreamBuffer.FileBuffer.StreamBuffer<B>nextNextStreamBufferin the stream.BpooledBufferObtains the pooled buffer.java.nio.ByteBufferunpooledByteBufferObtains the non-pooledByteBuffer.
-
Constructor Summary
Constructors Constructor Description StreamBuffer(B pooledBuffer, java.nio.ByteBuffer unpooledByteBuffer, StreamBuffer.FileBuffer fileBuffer)Instantiate.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static <B> java.lang.AppendablegetAppendable(StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Obtains anAppendableto write to theStreamBufferstream.static <B> StreamBuffer<B>getWriteStreamBuffer(StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Obtains theStreamBufferto use for writing.abstract voidrelease()Releases thisStreamBufferfor re-use.abstract booleanwrite(byte datum)Writes a byte to the pooled buffer.intwrite(byte[] data)Writes all the data to the pooled buffer.abstract intwrite(byte[] data, int offset, int length)Writes the data to the pooled buffer.static <B> voidwrite(byte[] bytes, int offset, int length, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes the bytes to theStreamBufferstream.static <B> voidwrite(byte[] bytes, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes all the bytes to theStreamBufferstream.static <B> voidwrite(long value, StreamBuffer<B> head, StreamBufferPool<B> bufferPool)Writes a long value to theStreamBuffer.static <B> voidwrite(java.lang.CharSequence characters, int offset, int length, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes theCharSequenceto theStreamBufferstream.static <B> voidwrite(java.lang.CharSequence characters, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes all theCharSequenceto theStreamBufferstream.static <B> StreamBuffer<B>writeByte(byte character, StreamBuffer<B> writeBuffer, StreamBufferPool<B> bufferPool)Writes a HTTP encoded character.
-
-
-
Field Detail
-
pooledBuffer
public final B pooledBuffer
Obtains the pooled buffer. Will benullif not pooled.
-
unpooledByteBuffer
public final java.nio.ByteBuffer unpooledByteBuffer
Obtains the non-pooledByteBuffer. Will benullif non-pooled.
-
fileBuffer
public final StreamBuffer.FileBuffer fileBuffer
Obtains theStreamBuffer.FileBuffer. Will benullif not file.
-
next
public StreamBuffer<B> next
Next
StreamBufferin the stream.This allows chaining
StreamBufferinstances into a linked list (and avoids memory management overheads of creating/destroying lists).
-
-
Constructor Detail
-
StreamBuffer
public StreamBuffer(B pooledBuffer, java.nio.ByteBuffer unpooledByteBuffer, StreamBuffer.FileBuffer fileBuffer)
Instantiate.- Parameters:
pooledBuffer- Pooled buffer. Must benullif another buffer provided.unpooledByteBuffer- UnpooledByteBuffer. Must benullif another buffer provided.fileBuffer-StreamBuffer.FileBuffer. Must benullif another buffer provided.- Throws:
java.lang.IllegalArgumentException- If not providing the one buffer.
-
-
Method Detail
-
write
public static <B> void write(byte[] bytes, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes all the bytes to theStreamBufferstream.- Type Parameters:
B- Buffer type.- Parameters:
bytes- Bytes to be written to theStreamBufferstream.headBuffer- HeadStreamBufferin the linked list ofStreamBufferinstances.bufferPool-StreamBufferPoolshould additionalStreamBufferinstances be required in writing the bytes.
-
write
public static <B> void write(byte[] bytes, int offset, int length, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes the bytes to theStreamBufferstream.- Type Parameters:
B- Buffer type.- Parameters:
bytes- Bytes to be written to theStreamBufferstream.offset- Offset into the bytes to start writing.length- Length of bytes to write.headBuffer- HeadStreamBufferin the linked list ofStreamBufferinstances.bufferPool-StreamBufferPoolshould additionalStreamBufferinstances be required in writing the bytes.
-
write
public static <B> void write(java.lang.CharSequence characters, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes all theCharSequenceto theStreamBufferstream.- Type Parameters:
B- Buffer type.- Parameters:
characters- Characters to be written to theStreamBufferstream.headBuffer- HeadStreamBufferin the linked list ofStreamBufferinstances.bufferPool-StreamBufferPoolshould additionalStreamBufferinstances be required in writing the bytes.
-
write
public static <B> void write(java.lang.CharSequence characters, int offset, int length, StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)Writes theCharSequenceto theStreamBufferstream.- Type Parameters:
B- Buffer type.- Parameters:
characters- Characters to be written to theStreamBufferstream.offset- Offset into theCharSequenceto start writing.length- Length of characters to write.headBuffer- HeadStreamBufferin the linked list ofStreamBufferinstances.bufferPool-StreamBufferPoolshould additionalStreamBufferinstances be required in writing the bytes.
-
write
public static <B> void write(long value, StreamBuffer<B> head, StreamBufferPool<B> bufferPool)Writes a long value to theStreamBuffer.- Type Parameters:
B- Buffer type.- Parameters:
value- Long value to write to theStreamBuffer.head- HeadStreamBufferof linked list ofStreamBufferinstances.bufferPool-StreamBufferPool.
-
getAppendable
public static <B> java.lang.Appendable getAppendable(StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)
Obtains an
Appendableto write to theStreamBufferstream.Typical use of this is for the
DateTimeFormatter.- Type Parameters:
B- Buffer type.- Parameters:
headBuffer- HeadStreamBufferin the linked list ofStreamBufferinstances.bufferPool-StreamBufferPoolshould additionalStreamBufferinstances be required in writing the bytes.- Returns:
Appendableto write to theStreamBufferstream.
-
getWriteStreamBuffer
public static <B> StreamBuffer<B> getWriteStreamBuffer(StreamBuffer<B> headBuffer, StreamBufferPool<B> bufferPool)
Obtains theStreamBufferto use for writing.- Type Parameters:
B- Buffer type.- Parameters:
headBuffer- HeadStreamBufferin the linked list ofStreamBufferinstances.bufferPool-StreamBufferPoolshould additionalStreamBufferinstances be required in writing the bytes.- Returns:
StreamBufferwithin the linked list to next write data.
-
writeByte
public static <B> StreamBuffer<B> writeByte(byte character, StreamBuffer<B> writeBuffer, StreamBufferPool<B> bufferPool)
Writes a HTTP encoded character.- Type Parameters:
B- Buffer type.- Parameters:
character- Character to write.writeBuffer- WriteStreamBuffer.bufferPool-StreamBufferPool.- Returns:
- Next write
StreamBuffer.
-
write
public abstract boolean write(byte datum)
Writes a byte to the pooled buffer.- Parameters:
datum- Byte value.- Returns:
trueif written value to buffer.falseindicates the pooled buffer is full.
-
write
public abstract int write(byte[] data, int offset, int length)Writes the data to the pooled 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.
-
write
public int write(byte[] data)
Writes all the data to the pooled buffer.- Parameters:
data- Data to write to the pooled buffer.- Returns:
- Number of bytes written.
-
release
public abstract void release()
Releases thisStreamBufferfor re-use.
-
-