check if encoding has been set before using it