Java 类org.apache.http.message.BasicHeaderValueParser 实例源码

项目:Hotspot-master-devp    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed from the given string
 * using the given character encoding.
 *
 * @param s       text to parse.
 * @param charset Encoding to use when decoding the parameters.
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s, final Charset charset) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(
                    decodeFormFields(nvp.getName(), charset),
                    decodeFormFields(nvp.getValue(), charset)));
        }
    }
    return list;
}
项目:lams    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string
 * using the given character encoding.
 *
 * @param s
 *            text to parse.
 * @param charset
 *            Encoding to use when decoding the parameters.
 *
 * @since 4.2
 */
public static List<NameValuePair> parse (final String s, final Charset charset) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(
                    decodeFormFields(nvp.getName(), charset),
                    decodeFormFields(nvp.getValue(), charset)));
        }
    }
    return list;
}
项目:rockscript    文件:ClientResponse.java   
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;
}
项目:ROKO.Stickers-Android    文件:HttpUtils.java   
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");
    }
}
项目:BigApp_Discuz_Android    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed.
 *
 * @param s text to parse.
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(nvp.getName(), nvp.getValue()));
        }
    }
    return list;
}
项目:RenewPass    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string
 * using the given character encoding.
 *
 * @param s
 *            text to parse.
 * @param charset
 *            Encoding to use when decoding the parameters.
 *
 * @since 4.2
 */
public static List<NameValuePair> parse (final String s, final Charset charset) {
    if (s == null)
        return Collections.emptyList();
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0)
            list.add(new BasicNameValuePair(
                    decodeFormFields(nvp.getName(), charset),
                    decodeFormFields(nvp.getValue(), charset)));
    }
    return list;
}
项目:android-open-project-demo-master    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed.
 *
 * @param s text to parse.
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(nvp.getName(), nvp.getValue()));
        }
    }
    return list;
}
项目:AndroidDevFramework    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed.
 *
 * @param s text to parse.
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(nvp.getName(), nvp.getValue()));
        }
    }
    return list;
}
项目:CouldBooks    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed.
 *
 * @param s text to parse.
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(nvp.getName(), nvp.getValue()));
        }
    }
    return list;
}
项目:cs-actions    文件:HttpResponseConsumer.java   
public void consume(Map<String, String> result) throws IOException {
    if (httpResponse.getEntity() != null) {
        if (responseCharacterSet == null || responseCharacterSet.isEmpty()) {
            Header contentType = httpResponse.getEntity().getContentType();
            if (contentType != null) {
                String value = contentType.getValue();
                NameValuePair[] nameValuePairs = BasicHeaderValueParser.parseParameters(value, BasicHeaderValueParser.INSTANCE);
                for (NameValuePair nameValuePair : nameValuePairs) {
                    if (nameValuePair.getName().equalsIgnoreCase("charset")) {
                        responseCharacterSet = nameValuePair.getValue();
                        break;
                    }
                }
            }
            if (responseCharacterSet == null || responseCharacterSet.isEmpty()) {
                responseCharacterSet = Consts.ISO_8859_1.name();
            }
        }
        consumeResponseContent(result);
    }
}
项目:android-open-project-demo    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed.
 *
 * @param s text to parse.
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(nvp.getName(), nvp.getValue()));
        }
    }
    return list;
}
项目:RoboZombie    文件:URLEncodedUtils.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as deserialized from the given string
 * using the given character encoding.
 *
 * @param s
 *            text to parse.
 * @param charset
 *            Encoding to use when decoding the parameters.
 *
 * @since 4.2
 */
public static List<NameValuePair> parse (final String s, final Charset charset) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser deserializer = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = deserializer.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(
                    decodeFormFields(nvp.getName(), charset),
                    decodeFormFields(nvp.getValue(), charset)));
        }
    }
    return list;
}
项目:box-java-sdk-v2    文件:HttpClientURLEncodedUtils.java   
/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string using the given character encoding.
 * 
 * @param s
 *            text to parse.
 * @param charset
 *            Encoding to use when decoding the parameters.
 * 
 * @since 4.2
 */
public static List<NameValuePair> parse(final String s, final Charset charset) {
    if (s == null) {
        return Collections.emptyList();
    }
    BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(s.length());
    buffer.append(s);
    ParserCursor cursor = new ParserCursor(0, buffer.length());
    List<NameValuePair> list = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, DELIM);
        if (nvp.getName().length() > 0) {
            list.add(new BasicNameValuePair(decodeFormFields(nvp.getName(), charset), decodeFormFields(nvp.getValue(), charset)));
        }
    }
    return list;
}
项目:lams    文件:RFC2617Scheme.java   
@Override
protected void parseChallenge(
        final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException {
    HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    ParserCursor cursor = new ParserCursor(pos, buffer.length());
    HeaderElement[] elements = parser.parseElements(buffer, cursor);
    if (elements.length == 0) {
        throw new MalformedChallengeException("Authentication challenge is empty");
    }
    this.params.clear();
    for (HeaderElement element : elements) {
        this.params.put(element.getName(), element.getValue());
    }
}
项目:lams    文件:ContentType.java   
/**
 * 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);
    }
}
项目:infoarchive-sip-sdk    文件:ContentResultFactory.java   
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("");
}
项目:RenewPass    文件:ContentType.java   
/**
 * 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);
    }
}
项目:purecloud-iot    文件:RFC2617Scheme.java   
@Override
protected void parseChallenge(
        final CharArrayBuffer buffer, final int pos, final int len) throws MalformedChallengeException {
    final HeaderValueParser parser = BasicHeaderValueParser.INSTANCE;
    final ParserCursor cursor = new ParserCursor(pos, buffer.length());
    final HeaderElement[] elements = parser.parseElements(buffer, cursor);
    this.params.clear();
    for (final HeaderElement element : elements) {
        this.params.put(element.getName().toLowerCase(Locale.ROOT), element.getValue());
    }
}
项目:purecloud-iot    文件:TestDigestScheme.java   
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;
}
项目:cJUnit-mc626    文件:RFC2617Scheme.java   
@Override
protected void parseChallenge(
        final CharArrayBuffer buffer, int pos, int len) throws MalformedChallengeException {
    HeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    ParserCursor cursor = new ParserCursor(pos, buffer.length()); 
    HeaderElement[] elements = parser.parseElements(buffer, cursor);
    if (elements.length == 0) {
        throw new MalformedChallengeException("Authentication challenge is empty");
    }

    this.params = new HashMap<String, String>(elements.length);
    for (HeaderElement element : elements) {
        this.params.put(element.getName(), element.getValue());
    }
}
项目:MAKEYOURFACE    文件:ContentType.java   
/**
 * 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);
    }
}
项目:RoboZombie    文件:ContentType.java   
/**
 * 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);
    }
}
项目:dozer-rets-client    文件:GetObjectResponse.java   
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());
}
项目:dozer-rets-client    文件:GetObjectResponse.java   
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());
}
项目:LDN4IIIF    文件:InboxChecker.java   
public String checkForInbox(String sourceUrl, InboxDiscoveryMethod source) throws InterruptedException, IOException {
        if(source==null) {
            String ret=checkForInbox(sourceUrl, InboxDiscoveryMethod.HTTP_HEADER);
            if(ret==null)
                ret=checkForInbox(sourceUrl, InboxDiscoveryMethod.RDF_MICRODATA);
            return ret;
        }

        FetchRequest fetched = httpFetcher.fetch(new UrlRequest(sourceUrl));
//      for(Header h: fetched.getResponse().getAllHeaders()) {
//          System.out.println(h.getName()+" - "+h.getValue());
//      }
        if(source!=null) {
            switch (source) {
            case HTTP_HEADER:
                for(Header h: fetched.getResponse().getHeaders("Link")) {
//                  System.out.println(h.getName()+" - "+h.getValue());
                    HeaderElement[] hElements = BasicHeaderValueParser.INSTANCE.parseElements(h.getValue(), null);
                    for(HeaderElement hEl: hElements) {
//                      System.out.println( "v "+hEl.getValue());
//                      System.out.println( "n "+hEl.getName());
//                      System.out.println( hEl.getParameterCount());
                        NameValuePair hElParam=hEl.getParameterByName("rel");
                        if(hElParam!=null && hElParam.getValue().equals("http://www.w3.org/ns/ldp#inbox")) {
//                          System.out.println( hElParam.getName()+" -- "+hElParam.getValue() );
                            return hEl.getName().replaceFirst("^\\s*<\\s*", "").replaceFirst("\\s*>\\s*$", "");
                        }
                    }

                }
                System.out.println();
                break;
            case RDF_MICRODATA:
                try {

                    String[] inboxUrl=new String[1];
                    any23.extract(fetched.getContent().asString(), sourceUrl, fetched.getContent().getType().getMimeType(), fetched.getContent().getType().getCharset().name(), new CountingTripleHandler() {
                        @Override
                        public void receiveTriple(Resource arg0, IRI arg1, Value arg2, IRI arg3, ExtractionContext arg4)
                                throws TripleHandlerException {
                            if(inboxUrl[0]!=null)
                                return;
//                          System.out.println("Triple: "+ arg0.toString());
//                          System.out.println("1 : "+ arg1.toString());
//                          System.out.println("2: "+ arg2.toString());
//                          System.out.println("3: "+ arg3);
                            if(arg1!=null && arg1.stringValue().equals("http://www.w3.org/ns/ldp#inbox")) 
                                inboxUrl[0]=arg2.stringValue();
                        }
                    });
                    return inboxUrl[0];
                } catch (ExtractionException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
//              System.out.println(
//              fetched.getContent().asString()
//              );
                break;
            }
        } else {

        }
        return null;
    }
项目:cJUnit-mc626    文件:NetscapeDraftHeaderParser.java   
public NetscapeDraftHeaderParser() {
    super();
    this.nvpParser = BasicHeaderValueParser.DEFAULT;
}