Skip to content

Instantly share code, notes, and snippets.

@sblendorio
Last active September 29, 2018 14:13
Show Gist options
  • Save sblendorio/8450eafd52e3fbfe980bf51ff5011337 to your computer and use it in GitHub Desktop.
Save sblendorio/8450eafd52e3fbfe980bf51ff5011337 to your computer and use it in GitHub Desktop.
GetBytesEncoding.java
import org.apache.tika.parser.txt.CharsetDetector;
public class GetBytesEncoding {
public static String getBytesEncoding(final byte[] data) {
final CharsetDetector detector = new CharsetDetector();
detector.setDeclaredEncoding("UTF-8");
detector.setText(data);
return detector.detect().getName();
}
}
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.18</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment