Interface EncoderFactory<T>

  • Type Parameters:
    T - The encoded items' data type
    All Known Subinterfaces:
    CodecFactory<T>
    All Known Implementing Classes:
    AvroCodecFactory, DelegatingCodecFactory, SimpleEncoderFactory, TxtCodecFactory, TxtEncoderFactory

    public interface EncoderFactory<T>
    Allows creating ItemEncoder instances of some specific type. This is the preferred type to be given to pipes. This allows the pipe to create dynamically as many instances as needed, thus solving threading issues and state issues easily. This interface includes a getByteArrayEncoder(..) method with default implementation. This encoder serves for encoding individual items into separate byte arrays, rather than into an output stream. The default implementation is not very efficient, and sub-classes are encouraged to override it.
    Author:
    Eyal Schneider
    • Method Detail

      • newEncoder

        ItemEncoder<T> newEncoder​(OutputStream os,
                                  FileWriteOptions writeOptions)
                           throws IOException
        Parameters:
        os - The output stream the encoder should be bound to. Not expected to be buffered. The encoder handles buffering.
        writeOptions - The way the output stream should be handled
        Returns:
        The new encoder
        Throws:
        IOException - In case of an IO error while preparing to write to the output stream
      • newEncoder

        default ItemEncoder<T> newEncoder​(OutputStream os)
                                   throws IOException
        Parameters:
        os - The output stream the encoder should be bound to. Not expected to be buffered. The encoder handles buffering.
        Returns:
        The new encoder
        Throws:
        IOException - In case of an IO error while preparing to write to the output stream
      • newByteArrayEncoder

        default ByteArrayEncoder<T> newByteArrayEncoder()
        Returns:
        A new ByteArrayEncoder, able to efficiently encode individual items as byte arrays. The default implementation goes through a ByteArrayOutputStream and is not very efficient, so sub-classes are encouraged to override it when a faster alternative is available.