From http://osmanov-dev-notes.blogspot.com/2010/07/how-to-handle-filename-encodings-in.html