Class SimpleEncoderFactory<T>

  • Type Parameters:
    T - The data type of the objects to encode
    All Implemented Interfaces:
    EncoderFactory<T>

    public class SimpleEncoderFactory<T>
    extends Object
    implements EncoderFactory<T>
    A simple generic encoder factory implementation. Handles output stream buffering and closing. Uses a simplified stateless output stream encoder function given in the ctor.
    Author:
    Eyal Schneider
    • Constructor Detail

      • SimpleEncoderFactory

        public SimpleEncoderFactory​(FailableBiConsumer<T,​OutputStream,​? extends IOException> statelessEncoder)
        Constructor
        Parameters:
        statelessEncoder - A consumer receiving a (buffered) output stream and a value, writing the value to the stream
      • SimpleEncoderFactory

        public SimpleEncoderFactory​(FailableBiConsumer<T,​OutputStream,​? extends IOException> statelessEncoder,
                                    ByteArrayEncoder<T> byteArrEncoder)
        Constructor
        Parameters:
        statelessEncoder - A consumer receiving a (buffered) output stream and a value, writing the value to the stream
        byteArrEncoder - The byte array encoder to be returned by the newByteArrayEncoder() function.
    • Method Detail

      • newEncoder

        public ItemEncoder<T> newEncoder​(OutputStream os,
                                         FileWriteOptions writeOptions)
                                  throws IOException
        Specified by:
        newEncoder in interface EncoderFactory<T>
        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