Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.http
Class HttpVersion  view HttpVersion download HttpVersion.java

java.lang.Object
  extended byorg.apache.http.HttpVersion
All Implemented Interfaces:
java.lang.Comparable

public class HttpVersion
extends java.lang.Object
implements java.lang.Comparable

HTTP version, as specified in RFC 2616.

HTTP uses a "<major>.<minor>" numbering scheme to indicate versions of the protocol. The protocol versioning policy is intended to allow the sender to indicate the format of a message and its capacity for understanding further HTTP communication, rather than the features obtained via that communication. No change is made to the version number for the addition of message components which do not affect communication behavior or which only add to extensible field values. The <minor> number is incremented when the changes made to the protocol add features which do not change the general message parsing algorithm, but which may add to the message semantics and imply additional capabilities of the sender. The <major> number is incremented when the format of a message within the protocol is changed. See RFC 2145 [36] for a fuller explanation.

The version of an HTTP message is indicated by an HTTP-Version field in the first line of the message.

     HTTP-Version   = "HTTP" "/" 1*DIGIT "." 1*DIGIT
  

Note that the major and minor numbers MUST be treated as separate integers and that each MAY be incremented higher than a single digit. Thus, HTTP/2.4 is a lower version than HTTP/2.13, which in turn is lower than HTTP/12.3. Leading zeros MUST be ignored by recipients and MUST NOT be sent.

Since:
3.0
Version:
$Revision: 389604 $ $Date: 2006-03-28 23:03:47 +0200 (Tue, 28 Mar 2006) $

Field Summary
static HttpVersion HTTP_0_9
          HTTP protocol version 0.9
static HttpVersion HTTP_1_0
          HTTP protocol version 1.0
static HttpVersion HTTP_1_1
          HTTP protocol version 1.1
private  int major
          Major version number of the HTTP protocol
private  int minor
          Minor version number of the HTTP protocol
 
Constructor Summary
HttpVersion(int major, int minor)
          Create an HTTP protocol version designator.
 
Method Summary
 int compareTo(HttpVersion anotherVer)
          Compares this HTTP protocol version with another one.
 int compareTo(java.lang.Object o)
          Compares this object with another, and returns a numerical result based on the comparison.
 boolean equals(HttpVersion version)
          Test if the HTTP protocol version is equal to the given number.
 boolean equals(java.lang.Object obj)
          Determine whether this Object is semantically equal to another Object.
static void format(org.apache.http.io.CharArrayBuffer buffer, HttpVersion ver)
           
static java.lang.String format(HttpVersion ver)
           
 int getMajor()
          Returns the major version number of the HTTP protocol.
 int getMinor()
          Returns the minor version number of the HTTP protocol.
 boolean greaterEquals(HttpVersion version)
          Test if the HTTP protocol version is greater or equal to the given number.
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
 boolean lessEquals(HttpVersion version)
          Test if the HTTP protocol version is less or equal to the given number.
static HttpVersion parse(org.apache.http.io.CharArrayBuffer buffer, int indexFrom, int indexTo)
          Parses the textual representation of the given HTTP protocol version.
static HttpVersion parse(java.lang.String s)
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

major

private int major
Major version number of the HTTP protocol


minor

private int minor
Minor version number of the HTTP protocol


HTTP_0_9

public static final HttpVersion HTTP_0_9
HTTP protocol version 0.9


HTTP_1_0

public static final HttpVersion HTTP_1_0
HTTP protocol version 1.0


HTTP_1_1

public static final HttpVersion HTTP_1_1
HTTP protocol version 1.1

Constructor Detail

HttpVersion

public HttpVersion(int major,
                   int minor)
Create an HTTP protocol version designator.

Method Detail

getMajor

public int getMajor()
Returns the major version number of the HTTP protocol.


getMinor

public int getMinor()
Returns the minor version number of the HTTP protocol.


hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


equals

public boolean equals(java.lang.Object obj)
Description copied from class: java.lang.Object
Determine whether this Object is semantically equal to another Object.

There are some fairly strict requirements on this method which subclasses must follow:

  • It must be transitive. If a.equals(b) and b.equals(c), then a.equals(c) must be true as well.
  • It must be symmetric. a.equals(b) and b.equals(a) must have the same value.
  • It must be reflexive. a.equals(a) must always be true.
  • It must be consistent. Whichever value a.equals(b) returns on the first invocation must be the value returned on all later invocations.
  • a.equals(null) must be false.
  • It must be consistent with hashCode(). That is, a.equals(b) must imply a.hashCode() == b.hashCode(). The reverse is not true; two objects that are not equal may have the same hashcode, but that has the potential to harm hashing performance.

This is typically overridden to throw a java.lang.ClassCastException if the argument is not comparable to the class performing the comparison, but that is not a requirement. It is legal for a.equals(b) to be true even though a.getClass() != b.getClass(). Also, it is typical to never cause a java.lang.NullPointerException.

In general, the Collections API (java.util) use the equals method rather than the == operator to compare objects. However, java.util.IdentityHashMap is an exception to this rule, for its own good reasons.

The default implementation returns this == o.


compareTo

public int compareTo(HttpVersion anotherVer)
Compares this HTTP protocol version with another one.


compareTo

public int compareTo(java.lang.Object o)
Description copied from interface: java.lang.Comparable
Compares this object with another, and returns a numerical result based on the comparison. If the result is negative, this object sorts less than the other; if 0, the two are equal, and if positive, this object sorts greater than the other. To translate this into boolean, simply perform o1.compareTo(o2) <op> 0, where op is one of <, <=, =, !=, >, or >=.

You must make sure that the comparison is mutual, ie. sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) (where sgn() is defined as -1, 0, or 1 based on the sign). This includes throwing an exception in either direction if the two are not comparable; hence, compareTo(null) should always throw an Exception.

You should also ensure transitivity, in two forms: x.compareTo(y) > 0 && y.compareTo(z) > 0 implies x.compareTo(z) > 0; and x.compareTo(y) == 0 implies x.compareTo(z) == y.compareTo(z).

Specified by:
compareTo in interface java.lang.Comparable

equals

public boolean equals(HttpVersion version)
Test if the HTTP protocol version is equal to the given number.


greaterEquals

public boolean greaterEquals(HttpVersion version)
Test if the HTTP protocol version is greater or equal to the given number.


lessEquals

public boolean lessEquals(HttpVersion version)
Test if the HTTP protocol version is less or equal to the given number.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


parse

public static HttpVersion parse(org.apache.http.io.CharArrayBuffer buffer,
                                int indexFrom,
                                int indexTo)
                         throws ProtocolException
Parses the textual representation of the given HTTP protocol version.


parse

public static final HttpVersion parse(java.lang.String s)
                               throws ProtocolException

format

public static void format(org.apache.http.io.CharArrayBuffer buffer,
                          HttpVersion ver)

format

public static java.lang.String format(HttpVersion ver)