added detectFileEncoding function and new test cases