Class 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 Details

  • Constructor Details

    • ArrayOfByteArraysOutput

      public ArrayOfByteArraysOutput(ContentType contentType, String charsetName)
    • ArrayOfByteArraysOutput

      public ArrayOfByteArraysOutput(ContentType contentType, Charset charset)
  • Method Details

    • getArrays

      public List<byte[]> getArrays()
    • w

      public ArrayOfByteArraysOutput w(String string) throws IOException
      Description copied from interface: RockerOutput
      Writes 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:
      IOException - Thrown on exception.
    • w

      public ArrayOfByteArraysOutput w(byte[] bytes) throws IOException
      Throws:
      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 String toString()
      Specified by:
      toString in interface RockerOutput<AbstractRockerOutput>
      Overrides:
      toString in class Object
    • asReadableByteChannel

      public ReadableByteChannel asReadableByteChannel()
    • asInputStream

      public InputStream asInputStream()