Search in sources :

Example 1 with BasicHeaderValueParser

use of org.apache.http.message.BasicHeaderValueParser in project xUtils by wyouflf.

the class URLEncodedUtils method parse.

/**
     * 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;
}
Also used : ParserCursor(org.apache.http.message.ParserCursor) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) BasicHeaderValueParser(org.apache.http.message.BasicHeaderValueParser)

Example 2 with BasicHeaderValueParser

use of org.apache.http.message.BasicHeaderValueParser in project android-delicious by lexs.

the class Response method getCharset.

public String getCharset() {
    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();
            }
        }
    }
    // No encoding specified
    return HTTP.DEFAULT_CONTENT_CHARSET;
}
Also used : NameValuePair(org.apache.http.NameValuePair) HeaderElement(org.apache.http.HeaderElement) HeaderValueParser(org.apache.http.message.HeaderValueParser) BasicHeaderValueParser(org.apache.http.message.BasicHeaderValueParser) BasicHeaderValueParser(org.apache.http.message.BasicHeaderValueParser)

Example 3 with BasicHeaderValueParser

use of org.apache.http.message.BasicHeaderValueParser in project RoboZombie by sahan.

the class URLEncodedUtils method parse.

/**
 * 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;
}
Also used : ParserCursor(org.apache.http.message.ParserCursor) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) ArrayList(java.util.ArrayList) BasicHeaderValueParser(org.apache.http.message.BasicHeaderValueParser)

Aggregations

NameValuePair (org.apache.http.NameValuePair)3 BasicHeaderValueParser (org.apache.http.message.BasicHeaderValueParser)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)2 ParserCursor (org.apache.http.message.ParserCursor)2 CharArrayBuffer (org.apache.http.util.CharArrayBuffer)2 ArrayList (java.util.ArrayList)1 HeaderElement (org.apache.http.HeaderElement)1 HeaderValueParser (org.apache.http.message.HeaderValueParser)1