Refactored encoder into common base class and interface to be used by file & stream producers/consumers