Package gg.jte.output

Class Utf8ByteOutput

  • All Implemented Interfaces:
    TemplateOutput, java.io.Closeable, java.io.Flushable, java.lang.Appendable, java.lang.AutoCloseable

    public final class Utf8ByteOutput
    extends java.io.Writer
    implements TemplateOutput
    Heavily optimized UTF-8 template output, designed to be CPU and memory friendly. You may want to use this class, if you write to a low-level binary output stream and you need the exact content-size of the output. CAUTION: You must enable TemplateEngine.setBinaryStaticContent(boolean), otherwise this class won't provide any benefits over StringOutput!
    • Constructor Detail

      • Utf8ByteOutput

        public Utf8ByteOutput()
        Constructs an output with sane defaults
      • Utf8ByteOutput

        public Utf8ByteOutput​(int chunkSize,
                              int tempBufferSize)
        Constructs an output with custom settings. This output maintains a list of binary chunks. Pre-encoded data is passed as is, while internal buffers are created for dynamic data as needed.
        Parameters:
        chunkSize - The size in bytes for chunks of dynamic data.
        tempBufferSize - The size for the temporary buffer used for intermediate String encoding.
    • Method Detail

      • getContentLength

        public int getContentLength()
        Returns:
        The amount of bytes written to this output.
      • writeTo

        public void writeTo​(java.io.OutputStream os)
                     throws java.io.IOException
        Passes all collected bytes to the given output stream. Does not close the stream.
        Parameters:
        os - the output stream
        Throws:
        java.io.IOException - in case the stream operation fails
      • writeTo

        public void writeTo​(Utf8ByteOutput.DataConsumer dataConsumer)
                     throws java.io.IOException
        Passes all collected bytes to the given data consumer. CAUTION: For performance reasons no copy of the byte arrays is made. It is the consumer's duty to never alter their content!
        Parameters:
        dataConsumer - the data consumer
        Throws:
        java.io.IOException - in case the consume operation fails
      • write

        public void write​(char[] buffer,
                          int off,
                          int len)
        Specified by:
        write in class java.io.Writer
      • write

        public void write​(char c)
      • write

        public void write​(int c)
        Overrides:
        write in class java.io.Writer
      • write

        public void write​(char[] buffer)
        Overrides:
        write in class java.io.Writer
      • write

        public void write​(java.lang.String str)
        Overrides:
        write in class java.io.Writer
      • flush

        public void flush()
        Specified by:
        flush in interface java.io.Flushable
        Specified by:
        flush in class java.io.Writer
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Writer