Class SimpleEncoderFactory<T>
- java.lang.Object
-
- org.pipecraft.pipes.serialization.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 Summary
Constructors Constructor Description SimpleEncoderFactory(FailableBiConsumer<T,OutputStream,? extends IOException> statelessEncoder)ConstructorSimpleEncoderFactory(FailableBiConsumer<T,OutputStream,? extends IOException> statelessEncoder, ByteArrayEncoder<T> byteArrEncoder)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteArrayEncoder<T>newByteArrayEncoder()ItemEncoder<T>newEncoder(OutputStream os, FileWriteOptions writeOptions)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.pipecraft.pipes.serialization.EncoderFactory
newEncoder
-
-
-
-
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 streambyteArrEncoder- 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:
newEncoderin interfaceEncoderFactory<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
-
newByteArrayEncoder
public ByteArrayEncoder<T> newByteArrayEncoder()
- Specified by:
newByteArrayEncoderin interfaceEncoderFactory<T>- Returns:
- A new
ByteArrayEncoder, able to efficiently encode individual items as byte arrays. The default implementation goes through aByteArrayOutputStreamand is not very efficient, so sub-classes are encouraged to override it when a faster alternative is available.
-
-