Add encoding support for both template file and output stream