You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/08/25 16:17:14 UTC

svn commit: r569678 - in /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message: BasicLineFormatter.java LineFormatter.java

Author: rolandw
Date: Sat Aug 25 07:17:14 2007
New Revision: 569678

URL: http://svn.apache.org/viewvc?rev=569678&view=rev
Log:
added formatting of protocol version to LineFormatter

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java?rev=569678&r1=569677&r2=569678&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java Sat Aug 25 07:17:14 2007
@@ -90,6 +90,51 @@
     }
 
 
+    /**
+     * Formats a protocol version.
+     *
+     * @param version           the protocol version to format
+     * @param formatter         the formatter to use, or
+     *                          <code>null</code> for the
+     *                          {@link #DEFAULT default}
+     *
+     * @return  the formatted protocol version
+     */
+    public final static
+        String formatProtocolVersion(final HttpVersion version,
+                                     LineFormatter formatter) {
+        if (formatter == null)
+            formatter = BasicLineFormatter.DEFAULT;
+        return formatter.appendProtocolVersion(null, version).toString();
+    }
+
+
+    // non-javadoc, see interface LineFormatter
+    public CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer,
+                                                 HttpVersion version) {
+        if (version == null) {
+            throw new IllegalArgumentException
+                ("Protocol version must not be null.");
+        }
+
+        // can't use initBuffer, that would clear the argument!
+        CharArrayBuffer result = buffer;
+        final int len = 8; // room for "HTTP/1.1"
+        if (result == null) {
+            result = new CharArrayBuffer(len);
+        } else {
+            result.ensureCapacity(len);
+        }
+
+        result.append("HTTP/"); 
+        result.append(Integer.toString(version.getMajor())); 
+        result.append('.'); 
+        result.append(Integer.toString(version.getMinor())); 
+
+        return result;
+    }
+
+
     // non-javadoc, see interface LineFormatter
     public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer,
                                              RequestLine reqline) {

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java?rev=569678&r1=569677&r2=569678&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineFormatter.java Sat Aug 25 07:17:14 2007
@@ -53,7 +53,8 @@
  * In order to avoid unnecessary creation of temporary objects,
  * a buffer can be passed as argument to all formatting methods.
  * The implementation may or may not actually use that buffer for formatting.
- * If it is used, the buffer will first be cleared.
+ * If it is used, the buffer will first be cleared by the
+ * <code>formatXXX</code> methods.
  * The argument buffer can always be re-used after the call. The buffer
  * returned as the result, if it is different from the argument buffer,
  * MUST NOT be modified.
@@ -69,6 +70,27 @@
  * @since 4.0
  */
 public interface LineFormatter {
+
+
+
+    /**
+     * Formats a protocol version.
+     * This method does <i>not</i> follow the general contract for
+     * <code>buffer</code> arguments.
+     * It does <i>not</i> clear the argument buffer, but appends instead.
+     * The returned buffer can always be modified by the caller.
+     * Because of these differing conventions, it is not named
+     * <code>formatProtocolVersion</code>.
+     *
+     * @param buffer    a buffer to which to append, or <code>null</code>
+     * @param version   the protocol version to format
+     *
+     * @return  a buffer with the formatted protocol version appended.
+     *          The caller is allowed to modify the result buffer.
+     */
+    CharArrayBuffer appendProtocolVersion(CharArrayBuffer buffer,
+                                          HttpVersion version)
+        ;
 
 
     /**