Java 类org.apache.http.message.ParserCursor 实例源码

项目:lams    文件:NetscapeDraftHeaderParser.java   
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()]));
}
项目:Hotspot-master-devp    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:lams    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:remote-files-sync    文件:URLEncodedUtilsHC4.java   
/**
 * 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;
}
项目:remote-files-sync    文件:TokenParser.java   
/**
 * 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();
}
项目:remote-files-sync    文件:TokenParser.java   
/**
 * 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);
}
项目:remote-files-sync    文件:TokenParser.java   
/**
 * 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);
}
项目:remote-files-sync    文件:DistinguishedNameParser.java   
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);
}
项目:BigApp_Discuz_Android    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:RenewPass    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:android-open-project-demo-master    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:purecloud-iot    文件:NetscapeDraftHeaderParser.java   
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);
}
项目:Visit    文件:URLEncodedUtilsHC4.java   
/**
 * 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;
}
项目:Visit    文件:TokenParser.java   
/**
 * 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();
}
项目:Visit    文件:TokenParser.java   
/**
 * 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);
}
项目:Visit    文件:TokenParser.java   
/**
 * 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);
}
项目:Visit    文件:DistinguishedNameParser.java   
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);
}
项目:AndroidDevFramework    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:CouldBooks    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:cJUnit-mc626    文件:NetscapeDraftHeaderParser.java   
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()]));
}
项目:android-open-project-demo    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:ZTLib    文件:URLEncodedUtilsHC4.java   
/**
 * 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;
}
项目:ZTLib    文件:TokenParser.java   
/**
 * 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();
}
项目:ZTLib    文件:TokenParser.java   
/**
 * 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);
}
项目:ZTLib    文件:TokenParser.java   
/**
 * 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);
}
项目:ZTLib    文件:DistinguishedNameParser.java   
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);
}
项目:RoboZombie    文件:URLEncodedUtils.java   
/**
 * 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;
}
项目:box-java-sdk-v2    文件:HttpClientURLEncodedUtils.java   
/**
 * 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;
}
项目:lams    文件:RFC2617Scheme.java   
@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());
    }
}
项目:lams    文件:HttpResponseParser.java   
@Override
protected HttpMessage parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new NoHttpResponseException("The target server failed to respond");
    }
    //create the status line from the status string
    ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
    return this.responseFactory.newHttpResponse(statusline, null);
}
项目:lams    文件:DefaultHttpResponseParser.java   
@Override
protected HttpResponse parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new NoHttpResponseException("The target server failed to respond");
    }
    //create the status line from the status string
    ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
    return this.responseFactory.newHttpResponse(statusline, null);
}
项目:lams    文件:DefaultHttpRequestParser.java   
@Override
protected HttpRequest parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new ConnectionClosedException("Client closed connection");
    }
    ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    RequestLine requestline = this.lineParser.parseRequestLine(this.lineBuf, cursor);
    return this.requestFactory.newHttpRequest(requestline);
}
项目:lams    文件:HttpRequestParser.java   
@Override
protected HttpMessage parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new ConnectionClosedException("Client closed connection");
    }
    ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    RequestLine requestline = this.lineParser.parseRequestLine(this.lineBuf, cursor);
    return this.requestFactory.newHttpRequest(requestline);
}
项目:BUbiNG    文件:AbstractWarcReader.java   
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);
    }
}
项目:remote-files-sync    文件:ContentType.java   
/**
 * 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.
 * @throws UnsupportedCharsetException Thrown when the named charset is not available in
 * this instance of the Java virtual machine
 */
public static ContentType parse(
        final String s) throws ParseException, UnsupportedCharsetException {
    Args.notNull(s, "Content type");
    final CharArrayBuffer buf = new CharArrayBuffer(s.length());
    buf.append(s);
    final ParserCursor cursor = new ParserCursor(0, s.length());
    final HeaderElement[] elements = BasicHeaderValueParserHC4.INSTANCE.parseElements(buf, cursor);
    if (elements.length > 0) {
        return create(elements[0]);
    } else {
        throw new ParseException("Invalid content type: " + s);
    }
}
项目:remote-files-sync    文件:NetscapeDraftHeaderParserHC4.java   
public HeaderElement parseHeader(
        final CharArrayBuffer buffer,
        final ParserCursor cursor) throws ParseException {
    Args.notNull(buffer, "Char array buffer");
    Args.notNull(cursor, "Parser cursor");
    final NameValuePair nvp = parseNameValuePair(buffer, cursor);
    final List<NameValuePair> params = new ArrayList<NameValuePair>();
    while (!cursor.atEnd()) {
        final NameValuePair param = parseNameValuePair(buffer, cursor);
        params.add(param);
    }
    return new BasicHeaderElement(
            nvp.getName(),
            nvp.getValue(), params.toArray(new NameValuePair[params.size()]));
}
项目:remote-files-sync    文件:RFC2617SchemeHC4.java   
@Override
protected void parseChallenge(
        final CharArrayBuffer buffer, final int pos, final int len) throws MalformedChallengeException {
    final HeaderValueParser parser = BasicHeaderValueParserHC4.INSTANCE;
    final ParserCursor cursor = new ParserCursor(pos, buffer.length());
    final HeaderElement[] elements = parser.parseElements(buffer, cursor);
    if (elements.length == 0) {
        throw new MalformedChallengeException("Authentication challenge is empty");
    }
    this.params.clear();
    for (final HeaderElement element : elements) {
        this.params.put(element.getName().toLowerCase(Locale.ENGLISH), element.getValue());
    }
}
项目:remote-files-sync    文件:DefaultHttpResponseParser.java   
@Override
protected HttpResponse parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    final int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new NoHttpResponseException("The target server failed to respond");
    }
    //create the status line from the status string
    final ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    final StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
    return this.responseFactory.newHttpResponse(statusline, null);
}
项目:remote-files-sync    文件:DefaultHttpRequestParser.java   
@Override
protected HttpRequest parseHead(
        final SessionInputBuffer sessionBuffer)
    throws IOException, HttpException, ParseException {

    this.lineBuf.clear();
    final int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new ConnectionClosedException("Client closed connection");
    }
    final ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    final RequestLine requestline = this.lineParser.parseRequestLine(this.lineBuf, cursor);
    return this.requestFactory.newHttpRequest(requestline);
}
项目:remote-files-sync    文件:TokenParser.java   
/**
 * Extracts from the sequence of chars a value which can be enclosed in quote marks and
 * 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 value
 *  is not delimited by any character.
 */
public String parseValue(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 (current == DQUOTE) {
            if (whitespace && dst.length() > 0) {
                dst.append(' ');
            }
            copyQuotedContent(buf, cursor, dst);
            whitespace = false;
        } else {
            if (whitespace && dst.length() > 0) {
                dst.append(' ');
            }
            copyUnquotedContent(buf, cursor, delimiters, dst);
            whitespace = false;
        }
    }
    return dst.toString();
}