Interface InstanceWriter


public interface InstanceWriter
A writer dedicated to a specific instance. Method write(java.io.OutputStream) will write the instance to the output stream, method instanceBytes() will provide all the bytes of entity. The caller decided which method to call depending on results of alwaysInMemory() and contentLength().
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Whether the byte array is always available.
    If we can determine the number of bytes to be written to the stream, provide the information here.
    byte[]
    Get the instance as byte array.
    void
    Write the instance to the output stream.
  • Method Details

    • contentLength

      OptionalLong contentLength()
      If we can determine the number of bytes to be written to the stream, provide the information here. The returned number must be a valid content length (content-length >= 0)
      Returns:
      number of bytes or empty if not possible (or too expensive) to find out
    • alwaysInMemory

      boolean alwaysInMemory()
      Whether the byte array is always available. If true instanceBytes() will ALWAYS be called.
      Returns:
      whether the bytes will always be materialized in memory
    • write

      void write(OutputStream stream)
      Write the instance to the output stream. This method is NEVER called if alwaysInMemory() is true, otherwise this method is ALWAYS called if contentLength() returns empty. This method MAY be called if contentLength() returns a value.
      Parameters:
      stream - to write to
    • instanceBytes

      byte[] instanceBytes()
      Get the instance as byte array. This method is always called if alwaysInMemory() returns true. This method is NEVER called if contentLength() returns empty. This method MAY be called if contentLength() returns a value.
      Returns:
      bytes of the instance