- 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 enableTemplateEngine.setBinaryStaticContent(boolean), otherwise this class won't provide any benefits overStringOutput!
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceUtf8ByteOutput.DataConsumer
-
Constructor Summary
Constructors Constructor Description Utf8ByteOutput()Constructs an output with sane defaultsUtf8ByteOutput(int chunkSize, int tempBufferSize)Constructs an output with custom settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidflush()intgetContentLength()WritergetWriter()voidwrite(char c)voidwrite(char[] buffer)voidwrite(char[] buffer, int off, int len)voidwrite(int c)voidwrite(String str)voidwriteBinaryContent(byte[] value)voidwriteContent(String s)voidwriteTo(Utf8ByteOutput.DataConsumer dataConsumer)Passes all collected bytes to the given data consumer.voidwriteTo(OutputStream os)Passes all collected bytes to the given output stream.voidwriteUserContent(boolean value)voidwriteUserContent(byte value)voidwriteUserContent(char value)voidwriteUserContent(double value)voidwriteUserContent(float value)voidwriteUserContent(int value)voidwriteUserContent(long value)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gg.jte.TemplateOutput
writeUserContent, writeUserContent, writeUserContent, writeUserContent
-
-
-
-
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(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:
getWriterin interfaceTemplateOutput
-
writeContent
public void writeContent(String s)
- Specified by:
writeContentin interfaceTemplateOutput
-
writeBinaryContent
public void writeBinaryContent(byte[] value)
- Specified by:
writeBinaryContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(boolean value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(byte value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(char value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(int value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(long value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(float value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
writeUserContent
public void writeUserContent(double value)
- Specified by:
writeUserContentin interfaceTemplateOutput
-
write
public void write(char c)
-
flush
public void flush()
-
-