Package gg.jte.output
Class Utf8ByteOutput
- java.lang.Object
-
- java.io.Writer
-
- gg.jte.output.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 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()java.io.WritergetWriter()voidwrite(char c)voidwrite(char[] buffer)voidwrite(char[] buffer, int off, int len)voidwrite(int c)voidwrite(java.lang.String str)voidwriteBinaryContent(byte[] value)voidwriteContent(java.lang.String s)voidwriteTo(Utf8ByteOutput.DataConsumer dataConsumer)Passes all collected bytes to the given data consumer.voidwriteTo(java.io.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, 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(java.io.OutputStream os) throws java.io.IOExceptionPasses 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
-
getWriter
public java.io.Writer getWriter()
- Specified by:
getWriterin interfaceTemplateOutput
-
writeContent
public void writeContent(java.lang.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[] buffer, int off, int len)- Specified by:
writein classjava.io.Writer
-
write
public void write(char c)
-
write
public void write(int c)
- Overrides:
writein classjava.io.Writer
-
write
public void write(char[] buffer)
- Overrides:
writein classjava.io.Writer
-
write
public void write(java.lang.String str)
- Overrides:
writein classjava.io.Writer
-
flush
public void flush()
- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer
-
-