mobile/android/thirdparty/ch/boye/httpclientandroidlib/message/LineParser.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/ch/boye/httpclientandroidlib/message/LineParser.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,137 @@
     1.4 +/*
     1.5 + * ====================================================================
     1.6 + * Licensed to the Apache Software Foundation (ASF) under one
     1.7 + * or more contributor license agreements.  See the NOTICE file
     1.8 + * distributed with this work for additional information
     1.9 + * regarding copyright ownership.  The ASF licenses this file
    1.10 + * to you under the Apache License, Version 2.0 (the
    1.11 + * "License"); you may not use this file except in compliance
    1.12 + * with the License.  You may obtain a copy of the License at
    1.13 + *
    1.14 + *   http://www.apache.org/licenses/LICENSE-2.0
    1.15 + *
    1.16 + * Unless required by applicable law or agreed to in writing,
    1.17 + * software distributed under the License is distributed on an
    1.18 + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    1.19 + * KIND, either express or implied.  See the License for the
    1.20 + * specific language governing permissions and limitations
    1.21 + * under the License.
    1.22 + * ====================================================================
    1.23 + *
    1.24 + * This software consists of voluntary contributions made by many
    1.25 + * individuals on behalf of the Apache Software Foundation.  For more
    1.26 + * information on the Apache Software Foundation, please see
    1.27 + * <http://www.apache.org/>.
    1.28 + *
    1.29 + */
    1.30 +
    1.31 +package ch.boye.httpclientandroidlib.message;
    1.32 +
    1.33 +import ch.boye.httpclientandroidlib.ProtocolVersion;
    1.34 +import ch.boye.httpclientandroidlib.ParseException;
    1.35 +import ch.boye.httpclientandroidlib.RequestLine;
    1.36 +import ch.boye.httpclientandroidlib.StatusLine;
    1.37 +import ch.boye.httpclientandroidlib.Header;
    1.38 +import ch.boye.httpclientandroidlib.util.CharArrayBuffer;
    1.39 +
    1.40 +/**
    1.41 + * Interface for parsing lines in the HEAD section of an HTTP message.
    1.42 + * There are individual methods for parsing a request line, a
    1.43 + * status line, or a header line.
    1.44 + * The lines to parse are passed in memory, the parser does not depend
    1.45 + * on any specific IO mechanism.
    1.46 + * Instances of this interface are expected to be stateless and thread-safe.
    1.47 + *
    1.48 + * @since 4.0
    1.49 + */
    1.50 +public interface LineParser {
    1.51 +
    1.52 +    /**
    1.53 +     * Parses the textual representation of a protocol version.
    1.54 +     * This is needed for parsing request lines (last element)
    1.55 +     * as well as status lines (first element).
    1.56 +     *
    1.57 +     * @param buffer    a buffer holding the protocol version to parse
    1.58 +     * @param cursor    the parser cursor containing the current position and
    1.59 +     *                  the bounds within the buffer for the parsing operation
    1.60 +     *
    1.61 +     * @return  the parsed protocol version
    1.62 +     *
    1.63 +     * @throws ParseException        in case of a parse error
    1.64 +     */
    1.65 +    ProtocolVersion parseProtocolVersion(
    1.66 +            CharArrayBuffer buffer,
    1.67 +            ParserCursor cursor) throws ParseException;
    1.68 +
    1.69 +    /**
    1.70 +     * Checks whether there likely is a protocol version in a line.
    1.71 +     * This method implements a <i>heuristic</i> to check for a
    1.72 +     * likely protocol version specification. It does <i>not</i>
    1.73 +     * guarantee that {@link #parseProtocolVersion} would not
    1.74 +     * detect a parse error.
    1.75 +     * This can be used to detect garbage lines before a request
    1.76 +     * or status line.
    1.77 +     *
    1.78 +     * @param buffer    a buffer holding the line to inspect
    1.79 +     * @param cursor    the cursor at which to check for a protocol version, or
    1.80 +     *                  negative for "end of line". Whether the check tolerates
    1.81 +     *                  whitespace before or after the protocol version is
    1.82 +     *                  implementation dependent.
    1.83 +     *
    1.84 +     * @return  <code>true</code> if there is a protocol version at the
    1.85 +     *          argument index (possibly ignoring whitespace),
    1.86 +     *          <code>false</code> otherwise
    1.87 +     */
    1.88 +    boolean hasProtocolVersion(
    1.89 +            CharArrayBuffer buffer,
    1.90 +            ParserCursor cursor);
    1.91 +
    1.92 +    /**
    1.93 +     * Parses a request line.
    1.94 +     *
    1.95 +     * @param buffer    a buffer holding the line to parse
    1.96 +     * @param cursor    the parser cursor containing the current position and
    1.97 +     *                  the bounds within the buffer for the parsing operation
    1.98 +     *
    1.99 +     * @return  the parsed request line
   1.100 +     *
   1.101 +     * @throws ParseException        in case of a parse error
   1.102 +     */
   1.103 +    RequestLine parseRequestLine(
   1.104 +            CharArrayBuffer buffer,
   1.105 +            ParserCursor cursor) throws ParseException;
   1.106 +
   1.107 +    /**
   1.108 +     * Parses a status line.
   1.109 +     *
   1.110 +     * @param buffer    a buffer holding the line to parse
   1.111 +     * @param cursor    the parser cursor containing the current position and
   1.112 +     *                  the bounds within the buffer for the parsing operation
   1.113 +     *
   1.114 +     * @return  the parsed status line
   1.115 +     *
   1.116 +     * @throws ParseException        in case of a parse error
   1.117 +     */
   1.118 +    StatusLine parseStatusLine(
   1.119 +            CharArrayBuffer buffer,
   1.120 +            ParserCursor cursor) throws ParseException;
   1.121 +
   1.122 +    /**
   1.123 +     * Creates a header from a line.
   1.124 +     * The full header line is expected here. Header continuation lines
   1.125 +     * must be joined by the caller before invoking this method.
   1.126 +     *
   1.127 +     * @param buffer    a buffer holding the full header line.
   1.128 +     *                  This buffer MUST NOT be re-used afterwards, since
   1.129 +     *                  the returned object may reference the contents later.
   1.130 +     *
   1.131 +     * @return  the header in the argument buffer.
   1.132 +     *          The returned object MAY be a wrapper for the argument buffer.
   1.133 +     *          The argument buffer MUST NOT be re-used or changed afterwards.
   1.134 +     *
   1.135 +     * @throws ParseException        in case of a parse error
   1.136 +     */
   1.137 +    Header parseHeader(CharArrayBuffer buffer)
   1.138 +        throws ParseException;
   1.139 +
   1.140 +}

mercurial