net.sf.ehcache.constructs.web
Class HttpDateFormatter

java.lang.Object
  extended by net.sf.ehcache.constructs.web.HttpDateFormatter

public class HttpDateFormatter
extends java.lang.Object

RFC 2616 - HTTP/1.1 Protocol

Section 3.3.1 defines the preferred full date and time as:

 HTTP-date    = rfc1123-date
 rfc1123-date = wkday "," SP date1 SP time SP "GMT"
 date1        = 2DIGIT SP month SP 4DIGIT
 ; day month year (e.g., 02 Jun 1982)
 time         = 2DIGIT ":" 2DIGIT ":" 2DIGIT
 ; 00:00:00 - 23:59:59
 wkday        = "Mon" | "Tue" | "Wed"
 | "Thu" | "Fri" | "Sat" | "Sun"
 month        = "Jan" | "Feb" | "Mar" | "Apr"
 | "May" | "Jun" | "Jul" | "Aug"
 | "Sep" | "Oct" | "Nov" | "Dec"
 

An example is Sun, 06 Nov 1994 08:49:37 GMT

These are used in request and response headers.

Author:
Greg Luck

Constructor Summary
HttpDateFormatter()
          Constructs a new formatter.
 
Method Summary
 java.lang.String formatHttpDate(java.util.Date date)
           
 java.util.Date parseDateFromHttpDate(java.lang.String date)
          Parses dates supplied in accordance with Section 3.3.1 of RFC 2616
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpDateFormatter

public HttpDateFormatter()
Constructs a new formatter.

Note that this class is not thread-safe for use by multiple threads, as SimpleDateFormat is not. Each thread should create their own instance of this class.

Method Detail

formatHttpDate

public java.lang.String formatHttpDate(java.util.Date date)
Parameters:
date -
Returns:
A date formatted in accordance with Section 3.3.1 of RFC 2616

parseDateFromHttpDate

public java.util.Date parseDateFromHttpDate(java.lang.String date)
Parses dates supplied in accordance with Section 3.3.1 of RFC 2616

Parameters:
date - a date formatted in accordance with Section 3.3.1 of RFC 2616
Returns:
the parsed Date. If the date cannot be parsed, the start of POSIX time, 1/1/1970 is returned, which will have the effect of expiring the content.


Copyright ? 2003-2010 Terracotta, Inc.. All Rights Reserved.