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;
}
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;
}
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;
}
Aggregations