Skip to content

Instantly share code, notes, and snippets.

@slimane
Last active August 29, 2015 13:56
Show Gist options
  • Save slimane/8855718 to your computer and use it in GitHub Desktop.
Save slimane/8855718 to your computer and use it in GitHub Desktop.
def getEncoding(text: String): Option[String] = {
def checkEncoding(encoding: String): Boolean = {
try{
text == new String(text.getBytes(encoding), encoding)
}catch{
case NonFatal(_) => false
case th: Throtable => throw th
}
}
List("ascii", "iso-2022-jp", "utf-8", "euc-jp", "sjis", "utf-16")
.par
.find(checkEncoding(_))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment