Package gg.jte.output

Class Utf8ByteOutput

java.lang.Object
java.io.Writer
gg.jte.output.Utf8ByteOutput
All Implemented Interfaces:
TemplateOutput, Closeable, Flushable, Appendable, AutoCloseable

public final class Utf8ByteOutput extends 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 Details

    • 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 Details

    • getContentLength

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

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

      public void writeTo(Utf8ByteOutput.DataConsumer dataConsumer) throws 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:
      IOException - in case the consume operation fails
    • getWriter

      public Writer getWriter()
      Specified by:
      getWriter in interface TemplateOutput
    • writeContent

      public void writeContent(String s)
      Specified by:
      writeContent in interface TemplateOutput
    • writeBinaryContent

      public void writeBinaryContent(byte[] value)
      Specified by:
      writeBinaryContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(boolean value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(byte value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(char value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(int value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(long value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(float value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • writeUserContent

      public void writeUserContent(double value)
      Specified by:
      writeUserContent in interface TemplateOutput
    • write

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

      public void write(char c)
    • write

      public void write(int c)
      Overrides:
      write in class Writer
    • write

      public void write(char[] buffer)
      Overrides:
      write in class Writer
    • write

      public void write(String str)
      Overrides:
      write in class Writer
    • flush

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

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer