org.faceless.util
Class HttpResponseReader

java.lang.Object
  extended by org.faceless.util.HttpResponseReader

public class HttpResponseReader
extends Object

Represents an incoming HTTP Response, as created by an HttpRequestWriter

See Also:
HttpRequestWriter, HttpResponseWriter

Method Summary
 void close()
          Close the connection and free any resources associated with it
 void finalize()
           
 String getContentType()
          Returns the MIME type of the body of the request, or null if the type is not known.
 long getDateHeader(String key)
           Returns the value of the specified response header as a long value that represents a Date object.
 String getHeader(String key)
          Returns the value of the specified response header as a String.
 Iterator getHeaderNames()
          Returns an iterator of all the header names this response contains.
 Iterator getHeaders(String key)
           Returns all the values of the specified response header as an Iterator of String objects.
 InputStream getInputStream()
          Returns the body of the response as binary data using an InputStream.
 int getIntHeader(String key)
           Returns the value of the specified response header as an int.
 String getProtocol()
          Get the protocol used for this response (eg.
 BufferedReader getReader()
          Returns the body of the response as character data using a BufferedReader.
 HttpRequestWriter getRequestWriter()
          Return the HttpRequestWriter object that created this Response
 int getStatus()
          Return the status code returned from the response.
 String getStatusMessage()
          Get the status message returned from the response
 String getURL()
          Get the URL that the response came from.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStatus

public int getStatus()
Return the status code returned from the response. A code of between 200-299 indicates a normal response, 400-599 an error.


getStatusMessage

public String getStatusMessage()
Get the status message returned from the response


getProtocol

public String getProtocol()
Get the protocol used for this response (eg. HTTP/1.0)


getURL

public String getURL()
Get the URL that the response came from. This may be different to the requesting URL if redirects were followed


getHeaders

public Iterator getHeaders(String key)

Returns all the values of the specified response header as an Iterator of String objects.

Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.

If the response did not include any headers of the specified name, this method returns an empty Iterator. The header name is case insensitive. You can use this method with any response header.

Parameters:
key - a String specifying the header name
Returns:
an Iterator containing the values of the requested header. If the response does not have any headers of that name return an empty iterator.

getHeaderNames

public Iterator getHeaderNames()
Returns an iterator of all the header names this response contains. If the response has no headers, this method returns an empty iterator.


getHeader

public String getHeader(String key)
Returns the value of the specified response header as a String. If the response did not include a header of the specified name, this method returns null. The header name is case insensitive. You can use this method with any response header.

Parameters:
key - a String specifying the name of a response header
Returns:
a String containing the value of the requested header, or null if the response does not have a header of that name

getIntHeader

public int getIntHeader(String key)
                 throws NumberFormatException

Returns the value of the specified response header as an int. If the response does not have a header of the specified name, this method returns -1. If the header cannot be converted to an integer, this method throws a NumberFormatException.

The header name is case insensitive.

Parameters:
key - a String specifying the name of a response header
Returns:
an integer expressing the value of the response header or -1 if the response doesn't have a header of this name
Throws:
NumberFormatException - if the header value can't be converted to an int

getDateHeader

public long getDateHeader(String key)

Returns the value of the specified response header as a long value that represents a Date object. Use this method with headers that contain dates, such as Last-Modified.

The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.

If the response did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an IllegalArgumentException.

Parameters:
key - a String specifying the name of a response header
Returns:
a long value representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the reqest
Throws:
IllegalArgumentException - if the header can't be converted to a date

getContentType

public String getContentType()
Returns the MIME type of the body of the request, or null if the type is not known. Same as the value of the CGI variable CONTENT_TYPE.

Returns:
a String containing the name of the MIME type of the request

getInputStream

public InputStream getInputStream()
Returns the body of the response as binary data using an InputStream. Either this method or getReader() may be called to read the body, but not both.

Returns:
an InputStream containing the body of the response
Throws:
IllegalStateException - if the getReader() method has already been called.

getReader

public BufferedReader getReader()
                         throws UnsupportedEncodingException
Returns the body of the response as character data using a BufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method or getInputStream() may be called to read the body, but not both.

Returns:
a BufferedReader containing the body of the response
Throws:
IllegalStateException - if the getInputStream() method has already been called.
UnsupportedEncodingException - if the character encoding is not supported

close

public void close()
Close the connection and free any resources associated with it


finalize

public void finalize()
Overrides:
finalize in class Object

getRequestWriter

public HttpRequestWriter getRequestWriter()
Return the HttpRequestWriter object that created this Response



Copyright © 2001-2004 Big Faceless Organization