Example usage for org.apache.http.util CharArrayBuffer length

List of usage examples for org.apache.http.util CharArrayBuffer length

Introduction

In this page you can find the example usage for org.apache.http.util CharArrayBuffer length.

Prototype

public int length() 

Source Link

Usage

From source file:android.net.http.CharArrayBuffers.java

/**
 * Returns true if the buffer contains the given string. Ignores leading
 * whitespace and case./*from   ww w  . ja va 2s  . c o  m*/
 *
 * @param buffer to search
 * @param beginIndex index at which we should start
 * @param str to search for
 */
static boolean containsIgnoreCaseTrimmed(CharArrayBuffer buffer, int beginIndex, final String str) {
    int len = buffer.length();
    char[] chars = buffer.buffer();
    while (beginIndex < len && HTTP.isWhitespace(chars[beginIndex])) {
        beginIndex++;
    }
    int size = str.length();
    boolean ok = len >= beginIndex + size;
    for (int j = 0; ok && (j < size); j++) {
        char a = chars[beginIndex + j];
        char b = str.charAt(j);
        if (a != b) {
            a = toLower(a);
            b = toLower(b);
            ok = a == b;
        }
    }
    return ok;
}

From source file:com.jana.android.net.CharArrayBuffers.java

/**
 * Returns index of first occurence ch. Lower cases characters leading up to
 * first occurrence of ch.// ww  w .  ja  va 2s . c om
 */
static int setLowercaseIndexOf(CharArrayBuffer buffer, final int ch) {
    int beginIndex = 0;
    int endIndex = buffer.length();
    char[] chars = buffer.buffer();
    for (int i = beginIndex; i < endIndex; i++) {
        char current = chars[i];
        if (current == ch) {
            return i;
        } else if (current >= 'A' && current <= 'Z') {
            // make lower case
            current += uppercaseAddon;
            chars[i] = current;
        }
    }
    return -1;
}

From source file:android.net.http.CharArrayBuffers.java

/**
 * Returns index of first occurence ch. Lower cases characters leading up
 * to first occurrence of ch./*from  w w w .ja v  a  2 s  .  c  o m*/
 */
static int setLowercaseIndexOf(CharArrayBuffer buffer, final int ch) {

    int beginIndex = 0;
    int endIndex = buffer.length();
    char[] chars = buffer.buffer();

    for (int i = beginIndex; i < endIndex; i++) {
        char current = chars[i];
        if (current == ch) {
            return i;
        } else if (current >= 'A' && current <= 'Z') {
            // make lower case
            current += uppercaseAddon;
            chars[i] = current;
        }
    }
    return -1;
}

From source file:Main.java

/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed.
 *
 * @param s text to parse.// w ww .  java2 s  .c o  m
 * @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;
}

From source file:com.sina.cloudstorage.util.URLEncodedUtils.java

/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string
 * using the given character encoding.//from  w ww . j  a v  a2 s.  c  o m
 *
 * @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(decode(nvp.getName(), charset), decode(nvp.getValue(), charset)));
        }
    }
    return list;
}

From source file:org.vietspider.net.apache.DefaultResponseParser.java

public static Header[] parseHeaders(final SessionInputBuffer inbuffer, int maxHeaderCount, int maxLineLen,
        LineParser parser) throws HttpException, IOException {

    if (inbuffer == null) {
        throw new IllegalArgumentException("Session input buffer may not be null");
    }/*from www.  j a v  a2  s.c  om*/

    if (parser == null)
        parser = BasicLineParser.DEFAULT;

    ArrayList<CharArrayBuffer> headerLines = new ArrayList<CharArrayBuffer>();

    CharArrayBuffer current = null;
    CharArrayBuffer previous = null;
    for (;;) {
        if (current == null) {
            current = new CharArrayBuffer(64);
        } else {
            current.clear();
        }
        int l = inbuffer.readLine(current);
        if (l == -1 || current.length() < 1) {
            break;
        }
        // Parse the header name and value
        // Check for folded headers first
        // Detect LWS-char see HTTP/1.0 or HTTP/1.1 Section 2.2
        // discussion on folded headers
        if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) {
            // we have continuation folded header
            // so append value
            int i = 0;
            while (i < current.length()) {
                char ch = current.charAt(i);
                if (ch != ' ' && ch != '\t') {
                    break;
                }
                i++;
            }
            if (maxLineLen > 0 && previous.length() + 1 + current.length() - i > maxLineLen) {
                throw new IOException("Maximum line length limit exceeded");
            }
            previous.append(' ');
            previous.append(current, i, current.length() - i);
        } else {
            headerLines.add(current);
            previous = current;
            current = null;
        }

        if (maxHeaderCount > 0 && headerLines.size() >= maxHeaderCount) {
            throw new IOException("Maximum header count exceeded");
        }
    }

    Header[] headers = new Header[headerLines.size()];
    for (int i = 0; i < headerLines.size(); i++) {
        CharArrayBuffer buffer = headerLines.get(i);
        try {
            headers[i] = parser.parseHeader(buffer);
        } catch (ParseException ex) {
            throw new ProtocolException(ex.getMessage());
        }
    }
    return headers;
}

From source file:com.android.idtt.http.client.util.URLEncodedUtils.java

/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed from the given string
 * using the given character encoding.//from www. j a v a  2 s  .com
 *
 * @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;
}

From source file:com.gistlabs.mechanize.util.apache.URLEncodedUtils.java

/**
 * Returns a list of {@link NameValuePair NameValuePairs} as parsed from the given string
 * using the given character encoding.//  ww w .  j  a  v a  2 s  . c  om
 *
 * @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;
}

From source file:com.mcxiaoke.next.http.util.URLUtils.java

/**
 * Returns a list of {@link org.apache.http.NameValuePair NameValuePairs} as parsed from the given string using the given character
 * encoding./*from w  w w  .  j  av  a2 s. c  o m*/
 *
 * @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 org.apache.http.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 BasicHeaderValueParser parser = BasicHeaderValueParser.DEFAULT;
    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;
}

From source file:com.subgraph.vega.ui.httpeditor.parser.HttpResponseParser.java

/**
 * Parse a HTTP response in a string./*ww  w. j a v  a  2  s .  com*/
 * 
 * @param content HTTP response string.
 * @return HttpResponse, or null if the given HTTP response was empty. 
 * @throws UnsupportedEncodingException
 */
public void parseResponse(final String content) throws UnsupportedEncodingException {
    final CharArrayBuffer buf = new CharArrayBuffer(0);
    buf.append(content);
    final ParserCursor bufCursor = new ParserCursor(0, buf.length());
    final LineParser parser = new BasicLineParser();

    if (parseStatusLine(parser, builder, buf, bufCursor) < 0) {
        return;
    }
    builder.clearHeaders();
    parseHeaders(parser, builder, buf, bufCursor);
    if (!bufCursor.atEnd() && parseInlineEntities) {
        StringEntity entity = new StringEntity(buf.substring(bufCursor.getPos(), bufCursor.getUpperBound()));
        builder.setEntity(entity);
    }
}