~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/LineFormatter.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/LineFormatter.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.RequestLine;
 
36
import org.apache.http.StatusLine;
 
37
import org.apache.http.Header;
 
38
import org.apache.http.util.CharArrayBuffer;
 
39
 
 
40
/**
 
41
 * Interface for formatting elements of the HEAD section of an HTTP message.
 
42
 * This is the complement to {@link LineParser}.
 
43
 * There are individual methods for formatting a request line, a
 
44
 * status line, or a header line. The formatting does <i>not</i> include the
 
45
 * trailing line break sequence CR-LF.
 
46
 * Instances of this interface are expected to be stateless and thread-safe.
 
47
 *
 
48
 * <p>
 
49
 * The formatted lines are returned in memory, the formatter does not depend
 
50
 * on any specific IO mechanism.
 
51
 * In order to avoid unnecessary creation of temporary objects,
 
52
 * a buffer can be passed as argument to all formatting methods.
 
53
 * The implementation may or may not actually use that buffer for formatting.
 
54
 * If it is used, the buffer will first be cleared by the
 
55
 * <code>formatXXX</code> methods.
 
56
 * The argument buffer can always be re-used after the call. The buffer
 
57
 * returned as the result, if it is different from the argument buffer,
 
58
 * MUST NOT be modified.
 
59
 * </p>
 
60
 *
 
61
 *
 
62
 *
 
63
 *
 
64
 * <!-- empty lines above to avoid 'svn diff' context problems -->
 
65
 * @version $Revision: 744527 $ $Date: 2009-02-14 18:06:25 +0100 (Sat, 14 Feb 2009) $
 
66
 *
 
67
 * @since 4.0
 
68
 */
 
69
public interface LineFormatter {
 
70
 
 
71
    /**
 
72
     * Formats a protocol version.
 
73
     * This method does <i>not</i> follow the general contract for
 
74
     * <code>buffer</code> arguments.
 
75
     * It does <i>not</i> clear the argument buffer, but appends instead.
 
76
     * The returned buffer can always be modified by the caller.
 
77
     * Because of these differing conventions, it is not named
 
78
     * <code>formatProtocolVersion</code>.
 
79
     *
 
80
     * @param buffer    a buffer to which to append, or <code>null</code>
 
81
     * @param version   the protocol version to format
 
82
     *
 
83
     * @return  a buffer with the formatted protocol version appended.
 
84
     *          The caller is allowed to modify the result buffer.
 
85
     *          If the <code>buffer</code> argument is not <code>null</code>,
 
86
     *          the returned buffer is the argument buffer.
 
87
     */
 
88
    CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer,
 
89
                                          ProtocolVersion version);
 
90
 
 
91
    /**
 
92
     * Formats a request line.
 
93
     *
 
94
     * @param buffer    a buffer available for formatting, or
 
95
     *                  <code>null</code>.
 
96
     *                  The buffer will be cleared before use.
 
97
     * @param reqline   the request line to format
 
98
     *
 
99
     * @return  the formatted request line
 
100
     */
 
101
    CharArrayBuffer formatRequestLine(CharArrayBuffer buffer,
 
102
                                      RequestLine reqline);
 
103
 
 
104
    /**
 
105
     * Formats a status line.
 
106
     *
 
107
     * @param buffer    a buffer available for formatting, or
 
108
     *                  <code>null</code>.
 
109
     *                  The buffer will be cleared before use.
 
110
     * @param statline  the status line to format
 
111
     *
 
112
     * @return  the formatted status line
 
113
     *
 
114
     * @throws ParseException        in case of a parse error
 
115
     */
 
116
    CharArrayBuffer formatStatusLine(CharArrayBuffer buffer,
 
117
                                     StatusLine statline);
 
118
 
 
119
    /**
 
120
     * Formats a header.
 
121
     * Due to header continuation, the result may be multiple lines.
 
122
     * In order to generate well-formed HTTP, the lines in the result
 
123
     * must be separated by the HTTP line break sequence CR-LF.
 
124
     * There is <i>no</i> trailing CR-LF in the result.
 
125
     * <br/>
 
126
     * See the class comment for details about the buffer argument.
 
127
     *
 
128
     * @param buffer    a buffer available for formatting, or
 
129
     *                  <code>null</code>.
 
130
     *                  The buffer will be cleared before use.
 
131
     * @param header    the header to format
 
132
     *
 
133
     * @return  a buffer holding the formatted header, never <code>null</code>.
 
134
     *          The returned buffer may be different from the argument buffer.
 
135
     *
 
136
     * @throws ParseException        in case of a parse error
 
137
     */
 
138
    CharArrayBuffer formatHeader(CharArrayBuffer buffer,
 
139
                                 Header header);
 
140
 
 
141
}