本文整理汇总了Java中org.apache.http.HeaderElement.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java HeaderElement.getValue方法的具体用法?Java HeaderElement.getValue怎么用?Java HeaderElement.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HeaderElement
的用法示例。
在下文中一共展示了HeaderElement.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(NumberFormatException ignore) {
}
}
}
return -1;
}
示例2: estimateHeaderElementLen
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
/**
* Estimates the length of a formatted header element.
*
* @param elem the header element to format, or <code>null</code>
*
* @return a length estimate, in number of characters
*/
protected int estimateHeaderElementLen(final HeaderElement elem) {
if (elem == null)
return 0;
int result = elem.getName().length(); // name
final String value = elem.getValue();
if (value != null) {
// assume quotes, but no escaped characters
result += 3 + value.length(); // ="value"
}
final int parcnt = elem.getParameterCount();
if (parcnt > 0) {
for (int i=0; i<parcnt; i++) {
result += 2 + // ; <param>
estimateNameValuePairLen(elem.getParameter(i));
}
}
return result;
}
示例3: parseElements
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public HeaderElement[] parseElements(final CharArrayBuffer buffer,
final ParserCursor cursor) {
if (buffer == null) {
throw new IllegalArgumentException("Char array buffer may not be null");
}
if (cursor == null) {
throw new IllegalArgumentException("Parser cursor may not be null");
}
List<HeaderElement> elements = new ArrayList<HeaderElement>();
while (!cursor.atEnd()) {
HeaderElement element = parseHeaderElement(buffer, cursor);
if (!(element.getName().length() == 0 && element.getValue() == null)) {
elements.add(element);
}
}
return elements.toArray(new HeaderElement[elements.size()]);
}
示例4: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
long timeout = Long.parseLong(value) * 1000;
if (timeout > 20 * 1000) {
return 20 * 1000;
} else {
return timeout;
}
}
}
return 5 * 1000;
}
示例5: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
// Honor 'keep-alive' header
HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (NumberFormatException ignore) {
// Do nothing
}
}
}
// otherwise keep alive for 30 seconds
return 30 * 1000;
}
示例6: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (final NumberFormatException ignore) {
LOGGER.warn("keep alive timeout could not be parsed: param=" + param + " value:" + value, ignore);
}
}
}
return DEFAULT_KEEP_ALIVE;
}
示例7: estimateHeaderElementLen
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
/**
* Estimates the length of a formatted header element.
*
* @param elem the header element to format, or <code>null</code>
*
* @return a length estimate, in number of characters
*/
protected int estimateHeaderElementLen(final HeaderElement elem) {
if (elem == null) {
return 0;
}
int result = elem.getName().length(); // name
final String value = elem.getValue();
if (value != null) {
// assume quotes, but no escaped characters
result += 3 + value.length(); // ="value"
}
final int parcnt = elem.getParameterCount();
if (parcnt > 0) {
for (int i=0; i<parcnt; i++) {
result += 2 + // ; <param>
estimateNameValuePairLen(elem.getParameter(i));
}
}
return result;
}
示例8: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(final NumberFormatException ignore) {
}
}
}
return -1;
}
示例9: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
if (response == null) {
throw new IllegalArgumentException("HTTP response may not be null");
}
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch (NumberFormatException ignore) {
}
}
}
return DEFAULT_KEEP_ALIVE_DURATION;
}
示例10: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Override
public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) {
HeaderElementIterator headerElementIterator = new BasicHeaderElementIterator(httpResponse.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (headerElementIterator.hasNext()) {
HeaderElement headerElement = headerElementIterator.nextElement();
String name = headerElement.getName();
String value = headerElement.getValue();
if (value != null && name.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// Set own keep alive duration if server does not have it
return applicationConfiguration.getRptConnectionPoolCustomKeepAliveTimeout() * 1000;
}
示例11: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(final NumberFormatException ignore) {
}
}
}
return -1;
}
示例12: getKeepAliveDuration
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(NumberFormatException ignore) {
}
}
}
return 30 * 1000; //默认30秒
}
示例13: parse
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin)
throws MalformedCookieException {
List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
for (HeaderElement headerelement : elems) {
String name = headerelement.getName();
String value = headerelement.getValue();
if (name == null || name.length() == 0) {
throw new MalformedCookieException("Cookie name may not be empty");
}
BasicClientCookie cookie = new BasicClientCookie(name, value);
cookie.setPath(getDefaultPath(origin));
cookie.setDomain(getDefaultDomain(origin));
// cycle through the parameters
NameValuePair[] attribs = headerelement.getParameters();
for (int j = attribs.length - 1; j >= 0; j--) {
NameValuePair attrib = attribs[j];
String s = attrib.getName().toLowerCase(Locale.ENGLISH);
cookie.setAttribute(s, attrib.getValue());
CookieAttributeHandler handler = findAttribHandler(s);
if (handler != null) {
handler.parse(cookie, attrib.getValue());
}
}
cookies.add(cookie);
}
return cookies;
}
示例14: parseNextElement
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
private void parseNextElement() {
// loop while there are headers left to parse
while (this.headerIt.hasNext() || this.cursor != null) {
if (this.cursor == null || this.cursor.atEnd()) {
// get next header value
bufferHeaderValue();
}
// Anything buffered?
if (this.cursor != null) {
// loop while there is data in the buffer
while (!this.cursor.atEnd()) {
HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor);
if (!(e.getName().length() == 0 && e.getValue() == null)) {
// Found something
this.currentElement = e;
return;
}
}
// if at the end of the buffer
if (this.cursor.atEnd()) {
// discard it
this.cursor = null;
this.buffer = null;
}
}
}
}
示例15: parseElements
import org.apache.http.HeaderElement; //导入方法依赖的package包/类
public HeaderElement[] parseElements(final CharArrayBuffer buffer,
final ParserCursor cursor) {
Args.notNull(buffer, "Char array buffer");
Args.notNull(cursor, "Parser cursor");
final List<HeaderElement> elements = new ArrayList<HeaderElement>();
while (!cursor.atEnd()) {
final HeaderElement element = parseHeaderElement(buffer, cursor);
if (!(element.getName().length() == 0 && element.getValue() == null)) {
elements.add(element);
}
}
return elements.toArray(new HeaderElement[elements.size()]);
}