Detect the encoding using chardet

Instead of always assuming utf-8 (which is typically
ok) switch to using the chardet library and use it to
detect the incoming files encoding in a more accurate
manner.

Change-Id: I907c8f4e1a6682138b220b49fcfcff6eef85a0b3