本文整理汇总了Java中org.apache.http.message.BasicHeaderValueParser.parseElements方法的典型用法代码示例。如果您正苦于以下问题:Java BasicHeaderValueParser.parseElements方法的具体用法?Java BasicHeaderValueParser.parseElements怎么用?Java BasicHeaderValueParser.parseElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.message.BasicHeaderValueParser
的用法示例。
在下文中一共展示了BasicHeaderValueParser.parseElements方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContentTypeCharset
import org.apache.http.message.BasicHeaderValueParser; //导入方法依赖的package包/类
public String getContentTypeCharset(String defaultCharset) {
List<String> values = getHeader(Http.Headers.CONTENT_TYPE);
if (values!=null) {
for (String value: values) {
HeaderElement[] headerElements = BasicHeaderValueParser.parseElements(value, (HeaderValueParser) null);
if (headerElements!=null && headerElements.length>0) {
NameValuePair charsetPair = headerElements[0].getParameterByName("charset");
if (charsetPair!=null) {
return charsetPair.getValue();
}
}
}
}
return defaultCharset;
}
示例2: getCharSet
import org.apache.http.message.BasicHeaderValueParser; //导入方法依赖的package包/类
public static String getCharSet(URLConnection connection) throws IOException {
String contentType = connection.getContentType();
if (contentType != null) {
HeaderValueParser parser = new BasicHeaderValueParser();
HeaderElement[] values = BasicHeaderValueParser.parseElements(contentType, parser);
if (values.length > 0) {
NameValuePair param = values[0].getParameterByName("charset");
if (param != null) {
return param.getValue();
}
}
}
if (connection instanceof HttpURLConnection) {
return "UTF-8";
} else {
throw new IOException("Unabled to determine character encoding");
}
}
示例3: parse
import org.apache.http.message.BasicHeaderValueParser; //导入方法依赖的package包/类
/**
* Parses textual representation of <code>Content-Type</code> value.
*
* @param s text
* @return content type
* @throws ParseException if the given text does not represent a valid
* <code>Content-Type</code> value.
*/
public static ContentType parse(
final String s) throws ParseException, UnsupportedCharsetException {
if (s == null) {
throw new IllegalArgumentException("Content type may not be null");
}
HeaderElement[] elements = BasicHeaderValueParser.parseElements(s, null);
if (elements.length > 0) {
return create(elements[0]);
} else {
throw new ParseException("Invalid content type: " + s);
}
}
示例4: extractFileNameFrom
import org.apache.http.message.BasicHeaderValueParser; //导入方法依赖的package包/类
private String extractFileNameFrom(String contentDisposition) {
HeaderElement[] elements = BasicHeaderValueParser.parseElements(contentDisposition, null);
return Arrays.stream(elements)
.filter(element -> "attachment".equalsIgnoreCase(element.getName()))
.findAny()
.map(element -> element.getParameterByName("filename"))
.map(NameValuePair::getValue)
.orElse("");
}
示例5: parseAuthResponse
import org.apache.http.message.BasicHeaderValueParser; //导入方法依赖的package包/类
private static Map<String, String> parseAuthResponse(final Header authResponse) {
final String s = authResponse.getValue();
if (!s.startsWith("Digest ")) {
return null;
}
final HeaderElement[] elements = BasicHeaderValueParser.parseElements(s.substring(7), null);
final Map<String, String> map = new HashMap<String, String>(elements.length);
for (final HeaderElement element : elements) {
map.put(element.getName(), element.getValue());
}
return map;
}
示例6: getBoundary
import org.apache.http.message.BasicHeaderValueParser; //导入方法依赖的package包/类
public String getBoundary() {
String contentTypeValue = getType();
HeaderElement[] contentType = BasicHeaderValueParser.parseElements(contentTypeValue, new BasicHeaderValueParser());
if (contentType.length != 1)
throw new IllegalArgumentException("Multipart response appears to have a bad Content-Type: header value: "
+ contentTypeValue);
NameValuePair boundaryNV = contentType[0].getParameterByName("boundary");
if (boundaryNV == null)
return null;
return unescapeBoundary(boundaryNV.getValue());
}