本文整理汇总了Java中org.apache.http.message.ParserCursor类的典型用法代码示例。如果您正苦于以下问题:Java ParserCursor类的具体用法?Java ParserCursor怎么用?Java ParserCursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserCursor类属于org.apache.http.message包,在下文中一共展示了ParserCursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseHeader
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
public HeaderElement parseHeader(
final CharArrayBuffer buffer,
final 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");
}
NameValuePair nvp = parseNameValuePair(buffer, cursor);
List<NameValuePair> params = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
NameValuePair param = parseNameValuePair(buffer, cursor);
params.add(param);
}
return new BasicHeaderElement(
nvp.getName(),
nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
示例2: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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;
}
示例3: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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.
* @param parameterSeparator
* The characters used to separate parameters, by convention, {@code '&'} and {@code ';'}.
* @return a list of {@link NameValuePair} as built from the URI's query portion.
*
* @since 4.3
*/
public static List<NameValuePair> parse(final String s, final Charset charset, final char... parameterSeparator) {
if (s == null) {
return Collections.emptyList();
}
final BasicHeaderValueParserHC4 parser = BasicHeaderValueParserHC4.INSTANCE;
final CharArrayBuffer buffer = new CharArrayBuffer(s.length());
buffer.append(s);
final ParserCursor cursor = new ParserCursor(0, buffer.length());
final List<NameValuePair> list = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
final NameValuePair nvp = parser.parseNameValuePair(buffer, cursor, parameterSeparator);
if (nvp.getName().length() > 0) {
list.add(new BasicNameValuePair(
decodeFormFields(nvp.getName(), charset),
decodeFormFields(nvp.getValue(), charset)));
}
}
return list;
}
示例4: parseToken
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* Extracts from the sequence of chars a token terminated with any of the given delimiters
* discarding semantically insignificant whitespace characters.
*
* @param buf buffer with the sequence of chars to be parsed
* @param cursor defines the bounds and current position of the buffer
* @param delimiters set of delimiting characters. Can be <code>null</code> if the token
* is not delimited by any character.
*/
public String parseToken(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters) {
final StringBuilder dst = new StringBuilder();
boolean whitespace = false;
while (!cursor.atEnd()) {
final char current = buf.charAt(cursor.getPos());
if (delimiters != null && delimiters.get(current)) {
break;
} else if (isWhitespace(current)) {
skipWhiteSpace(buf, cursor);
whitespace = true;
} else {
if (whitespace && dst.length() > 0) {
dst.append(' ');
}
copyContent(buf, cursor, delimiters, dst);
whitespace = false;
}
}
return dst.toString();
}
示例5: copyContent
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* Transfers content into the destination buffer until a whitespace character or any of
* the given delimiters is encountered.
*
* @param buf buffer with the sequence of chars to be parsed
* @param cursor defines the bounds and current position of the buffer
* @param delimiters set of delimiting characters. Can be <code>null</code> if the value
* is delimited by a whitespace only.
* @param dst destination buffer
*/
public void copyContent(final CharArrayBuffer buf, final ParserCursor cursor, final BitSet delimiters,
final StringBuilder dst) {
int pos = cursor.getPos();
final int indexFrom = cursor.getPos();
final int indexTo = cursor.getUpperBound();
for (int i = indexFrom; i < indexTo; i++) {
final char current = buf.charAt(i);
if ((delimiters != null && delimiters.get(current)) || isWhitespace(current)) {
break;
} else {
pos++;
dst.append(current);
}
}
cursor.updatePos(pos);
}
示例6: copyUnquotedContent
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* Transfers content into the destination buffer until a whitespace character, a quote,
* or any of the given delimiters is encountered.
*
* @param buf buffer with the sequence of chars to be parsed
* @param cursor defines the bounds and current position of the buffer
* @param delimiters set of delimiting characters. Can be <code>null</code> if the value
* is delimited by a whitespace or a quote only.
* @param dst destination buffer
*/
public void copyUnquotedContent(final CharArrayBuffer buf, final ParserCursor cursor,
final BitSet delimiters, final StringBuilder dst) {
int pos = cursor.getPos();
final int indexFrom = cursor.getPos();
final int indexTo = cursor.getUpperBound();
for (int i = indexFrom; i < indexTo; i++) {
final char current = buf.charAt(i);
if ((delimiters != null && delimiters.get(current))
|| isWhitespace(current) || current == DQUOTE) {
break;
} else {
pos++;
dst.append(current);
}
}
cursor.updatePos(pos);
}
示例7: parseParameter
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
NameValuePair parseParameter(final CharArrayBuffer buf, final ParserCursor cursor) {
final String name = parseToken(buf, cursor, EQUAL_OR_COMMA_OR_PLUS);
if (cursor.atEnd()) {
return new BasicNameValuePair(name, null);
}
final int delim = buf.charAt(cursor.getPos());
cursor.updatePos(cursor.getPos() + 1);
if (delim == ',') {
return new BasicNameValuePair(name, null);
}
final String value = parseValue(buf, cursor, COMMA_OR_PLUS);
if (!cursor.atEnd()) {
cursor.updatePos(cursor.getPos() + 1);
}
return new BasicNameValuePair(name, value);
}
示例8: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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;
}
示例9: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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;
}
示例10: parseNameValuePair
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
private NameValuePair parseNameValuePair(
final CharArrayBuffer buffer, final ParserCursor cursor) {
final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
if (cursor.atEnd()) {
return new BasicNameValuePair(name, null);
}
final int delim = buffer.charAt(cursor.getPos());
cursor.updatePos(cursor.getPos() + 1);
if (delim != '=') {
return new BasicNameValuePair(name, null);
}
final String value = tokenParser.parseToken(buffer, cursor, VALUE_DELIMS);
if (!cursor.atEnd()) {
cursor.updatePos(cursor.getPos() + 1);
}
return new BasicNameValuePair(name, value);
}
示例11: parseHeader
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
public HeaderElement parseHeader(
final CharArrayBuffer buffer,
final 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");
}
NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
List<NameValuePair> params = new ArrayList<NameValuePair>();
while (!cursor.atEnd()) {
NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS);
params.add(param);
}
return new BasicHeaderElement(
nvp.getName(),
nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
示例12: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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;
}
示例13: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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;
}
示例14: parse
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
/**
* 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;
}
示例15: parseChallenge
import org.apache.http.message.ParserCursor; //导入依赖的package包/类
@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());
}
}