Last active
September 29, 2018 14:13
-
-
Save sblendorio/8450eafd52e3fbfe980bf51ff5011337 to your computer and use it in GitHub Desktop.
GetBytesEncoding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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