~ubuntu-branches/ubuntu/trusty/httpcomponents-core/trusty

« back to all changes in this revision

Viewing changes to httpcore/src/main/java/org/apache/http/message/LineParser.java

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2010-06-12 08:37:34 UTC
  • Revision ID: james.westby@ubuntu.com-20100612083734-1y8kp6qm4sjk60az
Tags: upstream-4.0.1
ImportĀ upstreamĀ versionĀ 4.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $HeadURL: https://svn.apache.org/repos/asf/httpcomponents/httpcore/tags/4.0.1/httpcore/src/main/java/org/apache/http/message/LineParser.java $
 
3
 * $Revision: 744527 $
 
4
 * $Date: 2009-02-14 18:06:25 +0100 (Sat, 14 Feb 2009) $
 
5
 *
 
6
 * ====================================================================
 
7
 * Licensed to the Apache Software Foundation (ASF) under one
 
8
 * or more contributor license agreements.  See the NOTICE file
 
9
 * distributed with this work for additional information
 
10
 * regarding copyright ownership.  The ASF licenses this file
 
11
 * to you under the Apache License, Version 2.0 (the
 
12
 * "License"); you may not use this file except in compliance
 
13
 * with the License.  You may obtain a copy of the License at
 
14
 *
 
15
 *   http://www.apache.org/licenses/LICENSE-2.0
 
16
 *
 
17
 * Unless required by applicable law or agreed to in writing,
 
18
 * software distributed under the License is distributed on an
 
19
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 
20
 * KIND, either express or implied.  See the License for the
 
21
 * specific language governing permissions and limitations
 
22
 * under the License.
 
23
 * ====================================================================
 
24
 *
 
25
 * This software consists of voluntary contributions made by many
 
26
 * individuals on behalf of the Apache Software Foundation.  For more
 
27
 * information on the Apache Software Foundation, please see
 
28
 * <http://www.apache.org/>.
 
29
 *
 
30
 */
 
31
 
 
32
package org.apache.http.message;
 
33
 
 
34
import org.apache.http.ProtocolVersion;
 
35
import org.apache.http.ParseException;
 
36
import org.apache.http.RequestLine;
 
37
import org.apache.http.StatusLine;
 
38
import org.apache.http.Header;
 
39
import org.apache.http.util.CharArrayBuffer;
 
40
 
 
41
/**
 
42
 * Interface for parsing lines in the HEAD section of an HTTP message.
 
43
 * There are individual methods for parsing a request line, a
 
44
 * status line, or a header line.
 
45
 * The lines to parse are passed in memory, the parser does not depend
 
46
 * on any specific IO mechanism.
 
47
 * Instances of this interface are expected to be stateless and thread-safe.
 
48
 *
 
49
 *
 
50
 *
 
51
 * <!-- empty lines above to avoid 'svn diff' context problems -->
 
52
 * @version $Revision: 744527 $ $Date: 2009-02-14 18:06:25 +0100 (Sat, 14 Feb 2009) $
 
53
 *
 
54
 * @since 4.0
 
55
 */
 
56
public interface LineParser {
 
57
 
 
58
    /**
 
59
     * Parses the textual representation of a protocol version.
 
60
     * This is needed for parsing request lines (last element)
 
61
     * as well as status lines (first element).
 
62
     *
 
63
     * @param buffer    a buffer holding the protocol version to parse
 
64
     * @param cursor    the parser cursor containing the current position and 
 
65
     *                  the bounds within the buffer for the parsing operation
 
66
     * 
 
67
     * @return  the parsed protocol version
 
68
     *
 
69
     * @throws ParseException        in case of a parse error
 
70
     */
 
71
    ProtocolVersion parseProtocolVersion(
 
72
            CharArrayBuffer buffer,
 
73
            ParserCursor cursor) throws ParseException;
 
74
 
 
75
    /**
 
76
     * Checks whether there likely is a protocol version in a line.
 
77
     * This method implements a <i>heuristic</i> to check for a
 
78
     * likely protocol version specification. It does <i>not</i>
 
79
     * guarantee that {@link #parseProtocolVersion} would not
 
80
     * detect a parse error.
 
81
     * This can be used to detect garbage lines before a request
 
82
     * or status line.
 
83
     *
 
84
     * @param buffer    a buffer holding the line to inspect
 
85
     * @param cursor    the cursor at which to check for a protocol version, or
 
86
     *                  negative for "end of line". Whether the check tolerates
 
87
     *                  whitespace before or after the protocol version is
 
88
     *                  implementation dependent.
 
89
     *
 
90
     * @return  <code>true</code> if there is a protocol version at the
 
91
     *          argument index (possibly ignoring whitespace),
 
92
     *          <code>false</code> otherwise
 
93
     */
 
94
    boolean hasProtocolVersion(
 
95
            CharArrayBuffer buffer, 
 
96
            ParserCursor cursor);
 
97
 
 
98
    /**
 
99
     * Parses a request line.
 
100
     *
 
101
     * @param buffer    a buffer holding the line to parse
 
102
     * @param cursor    the parser cursor containing the current position and 
 
103
     *                  the bounds within the buffer for the parsing operation
 
104
     *
 
105
     * @return  the parsed request line
 
106
     *
 
107
     * @throws ParseException        in case of a parse error
 
108
     */
 
109
    RequestLine parseRequestLine(
 
110
            CharArrayBuffer buffer,
 
111
            ParserCursor cursor) throws ParseException;
 
112
 
 
113
    /**
 
114
     * Parses a status line.
 
115
     *
 
116
     * @param buffer    a buffer holding the line to parse
 
117
     * @param cursor    the parser cursor containing the current position and 
 
118
     *                  the bounds within the buffer for the parsing operation
 
119
     *
 
120
     * @return  the parsed status line
 
121
     *
 
122
     * @throws ParseException        in case of a parse error
 
123
     */
 
124
    StatusLine parseStatusLine(
 
125
            CharArrayBuffer buffer,
 
126
            ParserCursor cursor) throws ParseException;
 
127
 
 
128
    /**
 
129
     * Creates a header from a line.
 
130
     * The full header line is expected here. Header continuation lines
 
131
     * must be joined by the caller before invoking this method.
 
132
     *
 
133
     * @param buffer    a buffer holding the full header line.
 
134
     *                  This buffer MUST NOT be re-used afterwards, since
 
135
     *                  the returned object may reference the contents later.
 
136
     *
 
137
     * @return  the header in the argument buffer.
 
138
     *          The returned object MAY be a wrapper for the argument buffer.
 
139
     *          The argument buffer MUST NOT be re-used or changed afterwards.
 
140
     *
 
141
     * @throws ParseException        in case of a parse error
 
142
     */
 
143
    Header parseHeader(CharArrayBuffer buffer)
 
144
        throws ParseException;
 
145
 
 
146
}