com.limegroup.gnutella.http
Class HTTPUtils

java.lang.Object
  extended by com.limegroup.gnutella.http.HTTPUtils

public final class HTTPUtils
extends java.lang.Object

This class supplies general facilities for handling HTTP, such as writing headers, extracting header values, etc..


Method Summary
static java.lang.String extractHeaderValue(java.lang.String header)
          Parses out the header value from the HTTP header string.
static float parseFeatureToken(java.lang.String token)
          Utility method for extracting the version from a feature token.
static void writeDate(java.io.OutputStream stream)
          Utility method for writing the "Date" header, as specified in RFC 2616 section 14.18, to a OutputStream.
static void writeDate(java.io.Writer writer)
          Utility method for writing the "Date" header, as specified in RFC 2616 section 14.18, to a Writer.
static void writeFeatures(java.io.OutputStream stream)
          Utility method for writing the currently supported features to the OutputStream.
static void writeFeatures(java.io.Writer writer)
          Utility method for writing the currently supported features to the Writer.
static void writeHeader(HTTPHeaderName name, int value, java.io.OutputStream stream)
          Utility method for writing a header with an integer value.
static void writeHeader(HTTPHeaderName name, int value, java.io.Writer writer)
          Utility method for writing a header with an integer value.
static void writeHeader(HTTPHeaderName name, java.lang.String value, java.io.OutputStream os)
          Writes an single http header to the specified OutputStream instance, with the specified header name and the specified header value.
static void writeHeader(HTTPHeaderName name, java.lang.String value, java.io.Writer out)
          Writes an single http header to the specified OutputStream instance, with the specified header name and the specified header value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeHeader

public static void writeHeader(HTTPHeaderName name,
                               java.lang.String value,
                               java.io.OutputStream os)
                        throws java.io.IOException
Writes an single http header to the specified OutputStream instance, with the specified header name and the specified header value.

Parameters:
name - the HTTPHeaderName instance containing the header name to write to the stream
value - the String instance containing the header value to write to the stream
os - the OutputStream instance to write to
Throws:
java.io.IOException

writeHeader

public static void writeHeader(HTTPHeaderName name,
                               java.lang.String value,
                               java.io.Writer out)
                        throws java.io.IOException
Writes an single http header to the specified OutputStream instance, with the specified header name and the specified header value.

Parameters:
name - the HTTPHeaderName instance containing the header name to write to the stream
value - the HTTPHeaderValue instance containing the header value to write to the stream
out - the Writer instance to write to
Throws:
java.io.IOException

extractHeaderValue

public static java.lang.String extractHeaderValue(java.lang.String header)
Parses out the header value from the HTTP header string.

Returns:
the header value for the specified full header string, or null if the value could not be extracted

writeHeader

public static void writeHeader(HTTPHeaderName name,
                               int value,
                               java.io.Writer writer)
                        throws java.io.IOException
Utility method for writing a header with an integer value. This removes the burden to the caller of converting integer HTTP values to strings.

Parameters:
name - the HTTPHeaderName of the header to write
value - the int value of the header
writer - the Writer instance to write the header to
Throws:
java.io.IOException - if an IO error occurs during the write

writeHeader

public static void writeHeader(HTTPHeaderName name,
                               int value,
                               java.io.OutputStream stream)
                        throws java.io.IOException
Utility method for writing a header with an integer value. This removes the burden to the caller of converting integer HTTP values to strings.

Parameters:
name - the HTTPHeaderName of the header to write
value - the int value of the header
stream - the OutputStream instance to write the header to
Throws:
java.io.IOException - if an IO error occurs during the write

writeDate

public static void writeDate(java.io.Writer writer)
                      throws java.io.IOException
Utility method for writing the "Date" header, as specified in RFC 2616 section 14.18, to a Writer.

Parameters:
writer - the Writer to write the header to
Throws:
java.io.IOException - if a write error occurs

writeDate

public static void writeDate(java.io.OutputStream stream)
                      throws java.io.IOException
Utility method for writing the "Date" header, as specified in RFC 2616 section 14.18, to a OutputStream.

Parameters:
stream - the OutputStream to write the header to
Throws:
java.io.IOException - if a write error occurs

writeFeatures

public static void writeFeatures(java.io.Writer writer)
                          throws java.io.IOException
Utility method for writing the currently supported features to the Writer.

Throws:
java.io.IOException

writeFeatures

public static void writeFeatures(java.io.OutputStream stream)
                          throws java.io.IOException
Utility method for writing the currently supported features to the OutputStream.

Throws:
java.io.IOException

parseFeatureToken

public static float parseFeatureToken(java.lang.String token)
                               throws java.lang.Exception
Utility method for extracting the version from a feature token.

Throws:
java.lang.Exception