Package gg.jte.output

Class Utf8ByteOutput

java.lang.Object
gg.jte.output.Utf8ByteOutput
All Implemented Interfaces:
TemplateOutput

public final class Utf8ByteOutput extends Object implements TemplateOutput
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()
    • Utf8ByteOutput

      public Utf8ByteOutput(int initialCapacity)
  • 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
    • toByteArray

      public byte[] toByteArray()
    • writeContent

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

      public void writeContent(String s, int beginIndex, int endIndex)
      Specified by:
      writeContent in interface TemplateOutput
    • writeBinaryContent

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