ch.qos.logback.core.encoder

## Interface Encoder<E>

Type Parameters:
  `E` - event type

All Superinterfaces:
  ContextAware, LifeCycle

All Known Implementing Classes:
  EchoEncoder, EncoderBase, LayoutWrappingEncoder, ObjectStreamEncoder, PatternLayoutEncoder, PatternLayoutEncoderBase

    public interface Encoder<E>
    extends ContextAware, LifeCycle

Encoders are responsible for transform an incoming event into a byte array *and* writing out the byte array onto the appropriate `OutputStream`. Thus, encoders have total control of what and when gets written to the `OutputStream` maintained by the owning appender.

Since:
  0.9.19
Author:
  Ceki Gülcü, Joen Huxhorn, Maarten Bosteels

### Method Summary

Methods
`void` `close()` This method is called prior to the closing of the underling `OutputStream`.
`void` `doEncode(E event)` Encode and write an event to the appropriate `OutputStream`.
`void` `init(java.io.OutputStream os)` This method is called when the owning appender starts or whenever output needs to be directed to a new OutputStream, for instance as a result of a rollover.

### Methods inherited from interface ch.qos.logback.core.spi.ContextAware

`addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext`

### Methods inherited from interface ch.qos.logback.core.spi.LifeCycle

`isStarted, start, stop`

### Method Detail

#### init

    void init(java.io.OutputStream os)
              throws java.io.IOException

This method is called when the owning appender starts or whenever output needs to be directed to a new OutputStream, for instance as a result of a rollover. Implementing encoders should at the very least remember the OutputStream passed as argument and use it in future operations.

Parameters:
  `os` -
Throws:
  `java.io.IOException`

#### doEncode

    void doEncode(E event)
                  throws java.io.IOException

Encode and write an event to the appropriate `OutputStream`. Implementations are free to differ writing out of the encoded event and instead write in batches.

Parameters:
  `event` -
Throws:
  `java.io.IOException`

#### close

    void close()
               throws java.io.IOException

This method is called prior to the closing of the underling `OutputStream`. Implementations MUST not close the underlying `OutputStream` which is the responsibility of the owning appender.

Throws:
  `java.io.IOException`