Created
May 3, 2013 12:20
-
-
Save korayguclu/5508795 to your computer and use it in GitHub Desktop.
pars Character Encoding from contentType
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
// Taken from http://svn.apache.org/repos/asf/nutch/trunk/src/java/org/apache/nutch/util/EncodingDetector.java | |
/** | |
* Parse the character encoding from the specified content type header. | |
* If the content type is null, or there is no explicit character encoding, | |
* <code>null</code> is returned. | |
* <br /> | |
* This method was copied from org.apache.catalina.util.RequestUtil, | |
* which is licensed under the Apache License, Version 2.0 (the "License"). | |
* | |
* @param contentType a content type header | |
*/ | |
public static String parseCharacterEncoding(String contentType) { | |
if (contentType == null) | |
return (null); | |
int start = contentType.indexOf("charset="); | |
if (start < 0) | |
return (null); | |
String encoding = contentType.substring(start + 8); | |
int end = encoding.indexOf(';'); | |
if (end >= 0) | |
encoding = encoding.substring(0, end); | |
encoding = encoding.trim(); | |
if ((encoding.length() > 2) && (encoding.startsWith("\"")) | |
&& (encoding.endsWith("\""))) | |
encoding = encoding.substring(1, encoding.length() - 1); | |
return (encoding.trim()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ya ebal tvoy rot, suka