Top Description Fields Constructors Methods
org.glassfish.grizzly.http.util

public final Class HttpDateFormat

extends Object
Class Inheritance
Imports
org.glassfish.grizzly.utils.Charsets, java.io.UnsupportedEncodingException, java.time.Instant, .ZoneId, .ZonedDateTime, java.time.format.DateTimeFormatter, .DateTimeParseException, java.util.Locale, .Objects, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.atomic.AtomicBoolean

Utility class to generate HTTP dates. This class is based on FastHttpDateFormat, but uses java.time API instead of the old java.util.Date/Calendar and java.text.DateFormat/SimpleDateFormat API.
Author
Bongjae Chang

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
private static String
cachedStringDate

Current formatted date.

private static byte[]
currentDateBytes

Current formatted date as byte[].

private static volatile byte[]
private static final ConcurrentMap<Long, String>
formatCache

Formatter cache.

private static final DateTimeFormatter
private static final DateTimeFormatter[]
private static final ZoneId
private static final AtomicBoolean
private static volatile long
nextGeneration

Instant on which the currentDate object was generated.

private static final ConcurrentMap<String, Long>
parseCache

Parser cache.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String
formatDate(long
in milli-seconds
value
,
DateTimeFormatter
the DateTimeFormatter used if cache value was not found
formatter
)

Get the HTTP format of the specified date.

public static String
getCurrentDate()

Get the current date in HTTP format.

public static byte[]
getCurrentDateBytes()

Get the current date in HTTP format.

private static long
internalParseDate(final String value, final DateTimeFormatter[] formatters)

Parse date with given formatters.

public static long
parseDate(final String value, final DateTimeFormatter[] formatters)

Try to parse the given date as a HTTP date.

private static void
updateFormatCache(Long key, String value)

Update cache.

private static void
updateParseCache(String key, Long value)

Update cache.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ASCII_CHARSET_NAMEback to summary
private static final String ASCII_CHARSET_NAME
CACHE_SIZEback to summary
private static final int CACHE_SIZE
cachedStringDateback to summary
private static String cachedStringDate

Current formatted date.

currentDateBytesback to summary
private static byte[] currentDateBytes

Current formatted date as byte[].

dateBytesForCachedStringDateback to summary
private static volatile byte[] dateBytesForCachedStringDate
formatCacheback to summary
private static final ConcurrentMap<Long, String> formatCache

Formatter cache.

FORMATTERback to summary
private static final DateTimeFormatter FORMATTER
FORMATTERSback to summary
private static final DateTimeFormatter[] FORMATTERS
GMT_ZONE_IDback to summary
private static final ZoneId GMT_ZONE_ID
isGeneratingNowback to summary
private static final AtomicBoolean isGeneratingNow
nextGenerationback to summary
private static volatile long nextGeneration

Instant on which the currentDate object was generated.

parseCacheback to summary
private static final ConcurrentMap<String, Long> parseCache

Parser cache.

Constructor Detail

HttpDateFormatback to summary
public HttpDateFormat()

Method Detail

formatDateback to summary
public static String formatDate(long value, DateTimeFormatter formatter)

Get the HTTP format of the specified date.
http spec only require second precision http://tools.ietf.org/html/rfc2616#page-20
therefore we don't use the millisecond precision , but second . truncation is done in the same way for second precision in SimpleDateFormat:
(999 millisec. = 0 sec.)

Parameters
value:long

in milli-seconds

formatter:DateTimeFormatter

the DateTimeFormatter used if cache value was not found

getCurrentDateback to summary
public static String getCurrentDate()

Get the current date in HTTP format.

getCurrentDateBytesback to summary
public static byte[] getCurrentDateBytes()

Get the current date in HTTP format.

internalParseDateback to summary
private static long internalParseDate(final String value, final DateTimeFormatter[] formatters)

Parse date with given formatters.

parseDateback to summary
public static long parseDate(final String value, final DateTimeFormatter[] formatters)

Try to parse the given date as a HTTP date.

updateFormatCacheback to summary
private static void updateFormatCache(Long key, String value)

Update cache.

updateParseCacheback to summary
private static void updateParseCache(String key, Long value)

Update cache.