Package org.zkoss.zk.au

## Interface AuWriter

- All Known Implementing Classes:
    `HttpAuWriter`, `WSAuWriter`

      public interface AuWriter

  Represents a writer that is used to send the output back to the client, when processing `AuRequest`.

  To use the writer, `open(java.lang.Object, java.lang.Object)` must be called first. And, `close(java.lang.Object, java.lang.Object)` after all responses are written.

  Since:
    3.0.1
  Author:
    tomyeh
  See Also:
    `AuWriters.setImplementationClass(java.lang.Class)`

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `close​(java.lang.Object request, java.lang.Object response)` | Closes the writer and flush the result to client.
    `java.lang.Object` | `complete()` | Indicates the writing has been completed.
    `AuWriter` | `open​(java.lang.Object request, java.lang.Object response)` | Initializes the writer.
    `void` | `resend​(java.lang.Object prevContent)` | Resend the content of the previous request returned by `complete()`.
    `void` | `setCompress​(boolean compress)` | Sets whether to compress the output with GZIP.
    `void` | `write​(java.util.Collection<AuResponse> responses)` | Generates a list of responses to the output.
    `void` | `write​(AuResponse response)` | Generates the specified the response to the output.
    `void` | `writeResponseId​(int resId)` | Generates the response ID to the output.

- - ### Method Detail

    - #### setCompress

          void setCompress​(boolean compress)

      Sets whether to compress the output with GZIP.

      Default: true.

      Since:
        3.6.3

    - #### open

          AuWriter open​(java.lang.Object request,
                        java.lang.Object response)
                 throws java.io.IOException

      Initializes the writer.
      Parameters:
        `request` - the request (HttpServletRequest if HTTP)
        `response` - the response (HttpServletResponse if HTTP)
      Returns:
        this object
      Throws:
        `java.io.IOException`
      Since:
        6.0.0 (the signature is simplified)

    - #### close

          void close​(java.lang.Object request,
                     java.lang.Object response)
              throws java.io.IOException

      Closes the writer and flush the result to client.
      Parameters:
        `request` - the request (HttpServletRequest if HTTP)
        `response` - the response (HttpServletResponse if HTTP)
      Throws:
        `java.io.IOException`

    - #### complete

          java.lang.Object complete()
                             throws java.io.IOException

      Indicates the writing has been completed. Invokes this method before `close(java.lang.Object, java.lang.Object)`, if the caller supports the resend mechanism. The caller usually stores the return value to a desktop by `DesktopCtrl.responseSent(java.lang.String, java.lang.Object)`).

      Unlike `close(java.lang.Object, java.lang.Object)`, this method must be called in an activated execution.

      Once this method is called, the caller shall not invoke any other write method. It shall invoke only `close(java.lang.Object, java.lang.Object)` to end the writer.

      Throws:
        `java.io.IOException`
      Since:
        5.0.4

    - #### resend

          void resend​(java.lang.Object prevContent)
               throws java.io.IOException

      Resend the content of the previous request returned by `complete()`.

      The content is usually stored to a desktop by `DesktopCtrl.responseSent(java.lang.String, java.lang.Object)`, and retrieved by `DesktopCtrl.getLastResponse(java.lang.String)`.

      Once this method is called, the caller shall not invoke any other write method nor `complete()`. It shall invoke only `close(java.lang.Object, java.lang.Object)` to end the writer.

      Parameters:
        `prevContent` - the previous content returned by `close(java.lang.Object, java.lang.Object)` of the previous `AuWriter`.
      Throws:
        `java.lang.IllegalArgumentException` - if prevContent is null.
        `java.lang.IllegalStateException` - if any of write methods (such as `write(org.zkoss.zk.au.AuResponse)`) is called.
        `java.io.IOException`
      Since:
        5.0.4

    - #### writeResponseId

          void writeResponseId​(int resId)
                        throws java.io.IOException

      Generates the response ID to the output.
      Throws:
        `java.io.IOException`
      Since:
        3.5.0
      See Also:
        `DesktopCtrl.getResponseId(boolean)`

    - #### write

          void write​(AuResponse response)
              throws java.io.IOException

      Generates the specified the response to the output.
      Throws:
        `java.io.IOException`

    - #### write

          void write​(java.util.Collection<AuResponse> responses)
              throws java.io.IOException

      Generates a list of responses to the output.
      Throws:
        `java.io.IOException`