Class StreamBuffer<B>

    • Field Detail

      • pooledBuffer

        public final B pooledBuffer
        Obtains the pooled buffer. Will be null if not pooled.
      • unpooledByteBuffer

        public final java.nio.ByteBuffer unpooledByteBuffer
        Obtains the non-pooled ByteBuffer. Will be null if non-pooled.
      • next

        public StreamBuffer<B> next

        Next StreamBuffer in the stream.

        This allows chaining StreamBuffer instances 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 be null if another buffer provided.
        unpooledByteBuffer - Unpooled ByteBuffer. Must be null if another buffer provided.
        fileBuffer - StreamBuffer.FileBuffer. Must be null if another buffer provided.
        Throws:
        java.lang.IllegalArgumentException - If not providing the one buffer.
    • Method Detail

      • write

        public static <B> void write​(byte[] bytes,
                                     int offset,
                                     int length,
                                     StreamBuffer<B> headBuffer,
                                     StreamBufferPool<B> bufferPool)
        Writes the bytes to the StreamBuffer stream.
        Type Parameters:
        B - Buffer type.
        Parameters:
        bytes - Bytes to be written to the StreamBuffer stream.
        offset - Offset into the bytes to start writing.
        length - Length of bytes to write.
        headBuffer - Head StreamBuffer in the linked list of StreamBuffer instances.
        bufferPool - StreamBufferPool should additional StreamBuffer instances 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 the CharSequence to the StreamBuffer stream.
        Type Parameters:
        B - Buffer type.
        Parameters:
        characters - Characters to be written to the StreamBuffer stream.
        offset - Offset into the CharSequence to start writing.
        length - Length of characters to write.
        headBuffer - Head StreamBuffer in the linked list of StreamBuffer instances.
        bufferPool - StreamBufferPool should additional StreamBuffer instances be required in writing the bytes.
      • getAppendable

        public static <B> java.lang.Appendable getAppendable​(StreamBuffer<B> headBuffer,
                                                             StreamBufferPool<B> bufferPool)

        Obtains an Appendable to write to the StreamBuffer stream.

        Typical use of this is for the DateTimeFormatter.

        Type Parameters:
        B - Buffer type.
        Parameters:
        headBuffer - Head StreamBuffer in the linked list of StreamBuffer instances.
        bufferPool - StreamBufferPool should additional StreamBuffer instances be required in writing the bytes.
        Returns:
        Appendable to write to the StreamBuffer stream.
      • write

        public abstract boolean write​(byte datum)
        Writes a byte to the pooled buffer.
        Parameters:
        datum - Byte value.
        Returns:
        true if written value to buffer. false indicates 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 this StreamBuffer for re-use.