Package gg.jte.output
Class Utf8ByteOutput
java.lang.Object
java.io.Writer
gg.jte.output.Utf8ByteOutput
- All Implemented Interfaces:
TemplateOutput,Closeable,Flushable,Appendable,AutoCloseable
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!-
Nested Class Summary
Nested Classes -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an output with sane defaultsUtf8ByteOutput(int chunkSize, int tempBufferSize) Constructs an output with custom settings. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()intvoidwrite(char c) voidwrite(char[] buffer) voidwrite(char[] buffer, int off, int len) voidwrite(int c) voidvoidwriteBinaryContent(byte[] value) voidvoidwriteTo(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, waitMethods inherited from interface gg.jte.TemplateOutput
writeUnsafeContent, writeUserContent, writeUserContent, writeUserContent, writeUserContent, writeUserContent, writeUserContent, writeUserContent
-
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
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
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
- Specified by:
getWriterin interfaceTemplateOutput
-
writeContent
- 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) -
write
public void write(char c) -
write
public void write(int c) -
write
public void write(char[] buffer) -
write
-
flush
public void flush() -
close
public void close()
-