當前位置: 首頁>>代碼示例>>Java>>正文


Java HeaderElement類代碼示例

本文整理匯總了Java中org.apache.http.HeaderElement的典型用法代碼示例。如果您正苦於以下問題:Java HeaderElement類的具體用法?Java HeaderElement怎麽用?Java HeaderElement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HeaderElement類屬於org.apache.http包,在下文中一共展示了HeaderElement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getFileNameFromHttpResponse

import org.apache.http.HeaderElement; //導入依賴的package包/類
public static String getFileNameFromHttpResponse(final HttpResponse response) {
    if (response == null) return null;
    String result = null;
    Header header = response.getFirstHeader("Content-Disposition");
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair fileNamePair = element.getParameterByName("filename");
            if (fileNamePair != null) {
                result = fileNamePair.getValue();
                // try to get correct encoding str
                result = CharsetUtils.toCharset(result, HTTP.UTF_8, result.length());
                break;
            }
        }
    }
    return result;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:18,代碼來源:OtherUtils.java

示例2: getCharsetFromHttpResponse

import org.apache.http.HeaderElement; //導入依賴的package包/類
public static String getCharsetFromHttpResponse(final HttpResponse response) {
    if (response == null) return null;
    String result = null;
    Header header = response.getEntity().getContentType();
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair charsetPair = element.getParameterByName("charset");
            if (charsetPair != null) {
                result = charsetPair.getValue();
                break;
            }
        }
    }

    boolean isSupportedCharset = false;
    if (!TextUtils.isEmpty(result)) {
        try {
            isSupportedCharset = Charset.isSupported(result);
        } catch (Throwable e) {
        }
    }

    return isSupportedCharset ? result : null;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:25,代碼來源:OtherUtils.java

示例3: parseHeader

import org.apache.http.HeaderElement; //導入依賴的package包/類
public HeaderElement parseHeader(
        final CharArrayBuffer buffer,
        final ParserCursor cursor) throws ParseException {
    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");
    }
    NameValuePair nvp = parseNameValuePair(buffer, cursor);
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair param = parseNameValuePair(buffer, cursor);
        params.add(param);
    }
    return new BasicHeaderElement(
            nvp.getName(),
            nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:NetscapeDraftHeaderParser.java

示例4: 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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:DefaultConnectionKeepAliveStrategy.java

示例5: getContentCharSet

import org.apache.http.HeaderElement; //導入依賴的package包/類
/**
 * Obtains character set of the entity, if known.
 *
 * @param entity must not be null
 * @return the character set, or null if not found
 * @throws ParseException if header elements cannot be parsed
 * @throws IllegalArgumentException if entity is null
 *
 * @deprecated (4.1.3) use {@link ContentType#getOrDefault(HttpEntity)}
 */
@Deprecated
public static String getContentCharSet(final HttpEntity entity) throws ParseException {
    if (entity == null) {
        throw new IllegalArgumentException("HTTP entity may not be null");
    }
    String charset = null;
    if (entity.getContentType() != null) {
        HeaderElement values[] = entity.getContentType().getElements();
        if (values.length > 0) {
            NameValuePair param = values[0].getParameterByName("charset");
            if (param != null) {
                charset = param.getValue();
            }
        }
    }
    return charset;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:28,代碼來源:EntityUtils.java

示例6: getAllowedMethods

import org.apache.http.HeaderElement; //導入依賴的package包/類
public Set<String> getAllowedMethods(final HttpResponse response) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    HeaderIterator it = response.headerIterator("Allow");
    Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        Header header = it.nextHeader();
        HeaderElement[] elements = header.getElements();
        for (HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:17,代碼來源:HttpOptions.java

示例7: parse

import org.apache.http.HeaderElement; //導入依賴的package包/類
@Override
public List<Cookie> parse(
        final Header header,
        CookieOrigin origin) throws MalformedCookieException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    if (origin == null) {
        throw new IllegalArgumentException("Cookie origin may not be null");
    }
    if (!header.getName().equalsIgnoreCase(SM.SET_COOKIE2)) {
        throw new MalformedCookieException("Unrecognized cookie header '"
                + header.toString() + "'");
    }
    origin = adjustEffectiveHost(origin);
    HeaderElement[] elems = header.getElements();
    return createCookies(elems, origin);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:RFC2965Spec.java

示例8: create

import org.apache.http.HeaderElement; //導入依賴的package包/類
private static ContentType create(final HeaderElement helem) {
    String mimeType = helem.getName();
    String charset = null;
    NameValuePair param = helem.getParameterByName("charset");
    if (param != null) {
        charset = param.getValue();
    }
    return create(mimeType, charset);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:ContentType.java

示例9: 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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:BasicHeaderValueFormatter.java

示例10: parseElements

import org.apache.http.HeaderElement; //導入依賴的package包/類
/**
 * Parses elements with the given parser.
 *
 * @param value     the header value to parse
 * @param parser    the parser to use, or <code>null</code> for default
 *
 * @return  array holding the header elements, never <code>null</code>
 */
public final static
    HeaderElement[] parseElements(final String value,
                                  HeaderValueParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null");
    }

    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseElements(buffer, cursor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BasicHeaderValueParser.java

示例11: parseHeaderElement

import org.apache.http.HeaderElement; //導入依賴的package包/類
/**
 * Parses an element with the given parser.
 *
 * @param value     the header element to parse
 * @param parser    the parser to use, or <code>null</code> for default
 *
 * @return  the parsed header element
 */
public final static
    HeaderElement parseHeaderElement(final String value,
                                     HeaderValueParser parser)
    throws ParseException {

    if (value == null) {
        throw new IllegalArgumentException
            ("Value to parse may not be null");
    }

    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;

    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseHeaderElement(buffer, cursor);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:BasicHeaderValueParser.java

示例12: getContentTypeCharset

import org.apache.http.HeaderElement; //導入依賴的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;
}
 
開發者ID:rockscript,項目名稱:rockscript,代碼行數:16,代碼來源:ClientResponse.java

示例13: 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;
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:19,代碼來源:WebhookMsgHandler.java

示例14: getCharsetFromHttpRequest

import org.apache.http.HeaderElement; //導入依賴的package包/類
public static Charset getCharsetFromHttpRequest(final HttpRequestBase request) {
    if (request == null) return null;
    String charsetName = null;
    Header header = request.getFirstHeader("Content-Type");
    if (header != null) {
        for (HeaderElement element : header.getElements()) {
            NameValuePair charsetPair = element.getParameterByName("charset");
            if (charsetPair != null) {
                charsetName = charsetPair.getValue();
                break;
            }
        }
    }

    boolean isSupportedCharset = false;
    if (!TextUtils.isEmpty(charsetName)) {
        try {
            isSupportedCharset = Charset.isSupported(charsetName);
        } catch (Throwable e) {
        }
    }

    return isSupportedCharset ? Charset.forName(charsetName) : null;
}
 
開發者ID:jacklongway,項目名稱:LiteSDK,代碼行數:25,代碼來源:OtherUtils.java

示例15: 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;
}
 
開發者ID:SparkTC,項目名稱:stocator,代碼行數:21,代碼來源:SwiftConnectionManager.java


注:本文中的org.apache.http.HeaderElement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。