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

项目: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;
}
项目: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;
}
项目: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;
}
项目: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    文件: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());
    }
}
项目:Visit    文件: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);
    }
}
项目:Visit    文件: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());
    }
}
项目:ZTLib    文件: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);
    }
}
项目:ZTLib    文件: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());
    }
}