Package com.fizzed.rocker.runtime
Class ArrayOfByteArraysOutput
- java.lang.Object
-
- com.fizzed.rocker.runtime.AbstractRockerOutput<ArrayOfByteArraysOutput>
-
- com.fizzed.rocker.runtime.ArrayOfByteArraysOutput
-
- All Implemented Interfaces:
RockerOutput<AbstractRockerOutput>
public class ArrayOfByteArraysOutput extends AbstractRockerOutput<ArrayOfByteArraysOutput>
Output stores a list of references to byte arrays. Extremely optimized for taking static byte arrays (e.g. plain text) and just saving a pointer to it rather than copying it. Optimized for writing bytes vs. Strings. Strings are converted to bytes using the specified charset on each write and then that byte array is internally stored as part of the underlying list. Thus, the output will consist of reused byte arrays as well as new ones when Strings are written to this output.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<byte[]>arraysstatic RockerOutputFactory<ArrayOfByteArraysOutput>FACTORY-
Fields inherited from class com.fizzed.rocker.runtime.AbstractRockerOutput
byteLength, charset, contentType
-
-
Constructor Summary
Constructors Constructor Description ArrayOfByteArraysOutput(ContentType contentType, java.lang.String charsetName)ArrayOfByteArraysOutput(ContentType contentType, java.nio.charset.Charset charset)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.InputStreamasInputStream()java.nio.channels.ReadableByteChannelasReadableByteChannel()java.util.List<byte[]>getArrays()byte[]toByteArray()Expensive operation of allocating a byte array to hold the entire contents of this output and then copying each underlying byte array into this new byte array.java.lang.StringtoString()ArrayOfByteArraysOutputw(byte[] bytes)ArrayOfByteArraysOutputw(java.lang.String string)Writes a String to the output.-
Methods inherited from class com.fizzed.rocker.runtime.AbstractRockerOutput
getByteLength, getCharset, getContentType
-
-
-
-
Field Detail
-
FACTORY
public static RockerOutputFactory<ArrayOfByteArraysOutput> FACTORY
-
arrays
private final java.util.List<byte[]> arrays
-
-
Constructor Detail
-
ArrayOfByteArraysOutput
public ArrayOfByteArraysOutput(ContentType contentType, java.lang.String charsetName)
-
ArrayOfByteArraysOutput
public ArrayOfByteArraysOutput(ContentType contentType, java.nio.charset.Charset charset)
-
-
Method Detail
-
getArrays
public java.util.List<byte[]> getArrays()
-
w
public ArrayOfByteArraysOutput w(java.lang.String string) throws java.io.IOException
Description copied from interface:RockerOutputWrites a String to the output. Implementations are responsible for handling the conversion to the correct charset. Note that underlying implementations may be optimized to handle Strings vs. Bytes.- Parameters:
string- The string to write- Returns:
- This output (so builder pattern can be used)
- Throws:
java.io.IOException- Thrown on exception.
-
w
public ArrayOfByteArraysOutput w(byte[] bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
toByteArray
public byte[] toByteArray()
Expensive operation of allocating a byte array to hold the entire contents of this output and then copying each underlying byte array into this new byte array. Lots of memory copying...- Returns:
- A new byte array
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfaceRockerOutput<AbstractRockerOutput>- Overrides:
toStringin classjava.lang.Object
-
asReadableByteChannel
public java.nio.channels.ReadableByteChannel asReadableByteChannel()
-
asInputStream
public java.io.InputStream asInputStream()
-
-