org.apache.http.message.BasicHeaderValueParser Java Examples
The following examples show how to use
org.apache.http.message.BasicHeaderValueParser.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: URLEncodedUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
/** * 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; }
Example #2
Source File: HttpResponseConsumer.java From cs-actions with Apache License 2.0 | 6 votes |
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); } }
Example #3
Source File: URLEncodedUtils.java From android-open-project-demo with Apache License 2.0 | 6 votes |
/** * 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; }
Example #4
Source File: URLEncodedUtils.java From RoboZombie with Apache License 2.0 | 6 votes |
/** * 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; }
Example #5
Source File: ClientResponse.java From rockscript with Apache License 2.0 | 5 votes |
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; }
Example #6
Source File: AwsHttpServletRequest.java From aws-serverless-java-container with Apache License 2.0 | 5 votes |
/** * Protected constructors for implementing classes. This should be called first with the context received from * AWS Lambda * @param lambdaContext The Lambda function context. This object is used for utility methods such as log */ AwsHttpServletRequest(Context lambdaContext) { this.lambdaContext = lambdaContext; attributes = new HashMap<>(); headerParser = new BasicHeaderValueParser(); setAttribute(DISPATCHER_TYPE_ATTRIBUTE, DispatcherType.REQUEST); }
Example #7
Source File: ContentType.java From RoboZombie with Apache License 2.0 | 5 votes |
/** * 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); } }
Example #8
Source File: VersionParser.java From james-project with Apache License 2.0 | 4 votes |
private Stream<NameValuePair> extractValueParameters(String value) { return Arrays.stream(BasicHeaderValueParser.parseParameters(value, BasicHeaderValueParser.INSTANCE)); }