org.apache.http.message.ParserCursor Java Examples
The following examples show how to use
org.apache.http.message.ParserCursor.
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: 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 #3
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 #4
Source File: AbstractWarcReader.java From BUbiNG with Apache License 2.0 | 5 votes |
private ProtocolVersion parseHead() throws IOException { this.line.clear(); int read = this.buffer.readLine(this.line); if (LOGGER.isTraceEnabled()) LOGGER.trace("Protocol header '{}'.", new String(this.line.toCharArray())); if (read == -1) return null; ParserCursor cursor = new ParserCursor(0, this.line.length()); try { return parser.parseProtocolVersion(this.line, cursor); } catch (ParseException e) { throw new WarcFormatException("Can't parse WARC version header.", e); } }
Example #5
Source File: ExtendedHttpClientBuilder.java From lavaplayer with Apache License 2.0 | 5 votes |
@Override public ProtocolVersion parseProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) { int index = cursor.getPos(); int bound = cursor.getUpperBound(); if (bound >= index + 4 && "ICY ".equals(buffer.substring(index, index + 4))) { cursor.updatePos(index + 4); return ICY_PROTOCOL; } return super.parseProtocolVersion(buffer, cursor); }
Example #6
Source File: ExtendedHttpClientBuilder.java From lavaplayer with Apache License 2.0 | 5 votes |
@Override public boolean hasProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) { int index = cursor.getPos(); int bound = cursor.getUpperBound(); if (bound >= index + 4 && "ICY ".equals(buffer.substring(index, index + 4))) { return true; } return super.hasProtocolVersion(buffer, cursor); }
Example #7
Source File: HttpUtils.java From MediaPlayerProxy with Apache License 2.0 | 5 votes |
@Override public boolean hasProtocolVersion(CharArrayBuffer buffer, ParserCursor cursor) { boolean superFound = super.hasProtocolVersion(buffer, cursor); if (superFound) { return true; } int index = cursor.getPos(); final int protolength = ICY_PROTOCOL_NAME.length(); if (buffer.length() < protolength) return false; // not long enough for "HTTP/1.1" if (index < 0) { // end of line, no tolerance for trailing whitespace // this works only for single-digit major and minor version index = buffer.length() - protolength; } else if (index == 0) { // beginning of line, tolerate leading whitespace while ((index < buffer.length()) && HTTP.isWhitespace(buffer.charAt(index))) { index++; } } // else within line, don't tolerate whitespace return index + protolength <= buffer.length() && buffer.substring(index, index + protolength).equals(ICY_PROTOCOL_NAME); }
Example #8
Source File: HttpUtils.java From MediaPlayerProxy with Apache License 2.0 | 5 votes |
@Override public ProtocolVersion parseProtocolVersion(CharArrayBuffer buffer, 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"); } final int protolength = ICY_PROTOCOL_NAME.length(); int indexFrom = cursor.getPos(); int indexTo = cursor.getUpperBound(); skipWhitespace(buffer, cursor); int i = cursor.getPos(); // long enough for "HTTP/1.1"? if (i + protolength + 4 > indexTo) { throw new ParseException("Not a valid protocol version: " + buffer.substring(indexFrom, indexTo)); } // check the protocol name and slash if (!buffer.substring(i, i + protolength).equals(ICY_PROTOCOL_NAME)) { return super.parseProtocolVersion(buffer, cursor); } cursor.updatePos(i + protolength); return createProtocolVersion(1, 0); }
Example #9
Source File: HttpUtils.java From MediaPlayerProxy with Apache License 2.0 | 4 votes |
@Override public StatusLine parseStatusLine(CharArrayBuffer buffer, ParserCursor cursor) throws ParseException { return super.parseStatusLine(buffer, cursor); }