Top Description Fields Constructors Methods
io.undertow.util

public Class DateUtils

extends Object
Class Inheritance
Imports
io.undertow.UndertowOptions, io.undertow.server.HttpServerExchange, java.text.ParsePosition, .SimpleDateFormat, java.util.Date, .Locale, .TimeZone, java.util.concurrent.TimeUnit, java.util.concurrent.atomic.AtomicReference

Utility for parsing and generating dates
Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private static final String
private static final AtomicReference<String>
private static final String
private static final ThreadLocal<SimpleDateFormat>
private static final TimeZone
private static final Runnable
INVALIDATE_TASK

Invalidates the current date

private static final Locale
private static final String
private static final String
private static final ThreadLocal<SimpleDateFormat>
RFC1123_PATTERN_FORMAT

Thread local cache of this date format.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
public static String
public static boolean
handleIfModifiedSince(final HttpServerExchange
the exchange
exchange
,
final Date
The last modified date
lastModified
)

Handles the if-modified-since header.

public static boolean
handleIfModifiedSince(final String
the modified since date
modifiedSince
,
final Date
The last modified date
lastModified
)

Handles the if-modified-since header.

public static boolean
handleIfUnmodifiedSince(final HttpServerExchange
the exchange
exchange
,
final Date
The last modified date
lastModified
)

Handles the if-unmodified-since header.

public static boolean
handleIfUnmodifiedSince(final String
the if unmodified since date
modifiedSince
,
final Date
The last modified date
lastModified
)

Handles the if-unmodified-since header.

public static Date

Returns:

The parsed date, or null if parsing failed
parseDate
(final String
The date to parse
date
)

Attempts to pass a HTTP date.

public static String
toCommonLogFormat(final Date date)

public static String

Returns:

The RFC-1123 formatted date
toDateString
(final Date
The date
date
)

Converts a date to a format suitable for use in a HTTP request

public static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASCITIME_PATTERNback to summary
private static final String ASCITIME_PATTERN
cachedDateStringback to summary
private static final AtomicReference<String> cachedDateString
COMMON_LOG_PATTERNback to summary
private static final String COMMON_LOG_PATTERN
COMMON_LOG_PATTERN_FORMATback to summary
private static final ThreadLocal<SimpleDateFormat> COMMON_LOG_PATTERN_FORMAT
GMT_ZONEback to summary
private static final TimeZone GMT_ZONE
INVALIDATE_TASKback to summary
private static final Runnable INVALIDATE_TASK

Invalidates the current date

LOCALE_USback to summary
private static final Locale LOCALE_US
RFC1036_PATTERNback to summary
private static final String RFC1036_PATTERN
RFC1123_PATTERNback to summary
private static final String RFC1123_PATTERN
RFC1123_PATTERN_FORMATback to summary
private static final ThreadLocal<SimpleDateFormat> RFC1123_PATTERN_FORMAT

Thread local cache of this date format. This is technically a small memory leak, however in practice it is fine, as it will only be used by server threads.

This is the most common date format, which is why we cache it.

Constructor Detail

DateUtilsback to summary
private DateUtils()

Method Detail

addDateHeaderIfRequiredback to summary
public static void addDateHeaderIfRequired(HttpServerExchange exchange)
getCurrentDateTimeback to summary
public static String getCurrentDateTime(HttpServerExchange exchange)
handleIfModifiedSinceback to summary
public static boolean handleIfModifiedSince(final HttpServerExchange exchange, final Date lastModified)

Handles the if-modified-since header. returns true if the request should proceed, false otherwise

Parameters
exchange:HttpServerExchange

the exchange

lastModified:Date

The last modified date

handleIfModifiedSinceback to summary
public static boolean handleIfModifiedSince(final String modifiedSince, final Date lastModified)

Handles the if-modified-since header. returns true if the request should proceed, false otherwise

Parameters
modifiedSince:String

the modified since date

lastModified:Date

The last modified date

handleIfUnmodifiedSinceback to summary
public static boolean handleIfUnmodifiedSince(final HttpServerExchange exchange, final Date lastModified)

Handles the if-unmodified-since header. returns true if the request should proceed, false otherwise

Parameters
exchange:HttpServerExchange

the exchange

lastModified:Date

The last modified date

handleIfUnmodifiedSinceback to summary
public static boolean handleIfUnmodifiedSince(final String modifiedSince, final Date lastModified)

Handles the if-unmodified-since header. returns true if the request should proceed, false otherwise

Parameters
modifiedSince:String

the if unmodified since date

lastModified:Date

The last modified date

parseDateback to summary
public static Date parseDate(final String date)

Attempts to pass a HTTP date.

Parameters
date:String

The date to parse

Returns:Date

The parsed date, or null if parsing failed

toCommonLogFormatback to summary
public static String toCommonLogFormat(final Date date)
toDateStringback to summary
public static String toDateString(final Date date)

Converts a date to a format suitable for use in a HTTP request

Parameters
date:Date

The date

Returns:String

The RFC-1123 formatted date

toOldCookieDateStringback to summary
public static String toOldCookieDateString(final Date date)