Fields Summary |
---|
protected static final int | CACHE_SIZE |
protected static final SimpleDateFormat | formatHTTP date format. |
protected static final SimpleDateFormat[] | formatsThe set of SimpleDateFormat formats to use in getDateHeader(). |
protected static final TimeZone | gmtZone |
protected static long | currentDateGeneratedInstant on which the currentDate object was generated. |
protected static String | currentDateCurrent formatted date. |
protected static final ConcurrentHashMap | formatCacheFormatter cache. |
protected static final ConcurrentHashMap | parseCacheParser cache. |
Methods Summary |
---|
public static final java.lang.String | formatDate(long value, java.text.DateFormat threadLocalformat)Get the HTTP format of the specified date.
Long longValue = new Long(value);
String cachedDate = formatCache.get(longValue);
if (cachedDate != null)
return cachedDate;
String newDate = null;
Date dateValue = new Date(value);
if (threadLocalformat != null) {
newDate = threadLocalformat.format(dateValue);
updateFormatCache(longValue, newDate);
} else {
synchronized (formatCache) {
synchronized (format) {
newDate = format.format(dateValue);
}
updateFormatCache(longValue, newDate);
}
}
return newDate;
|
public static final java.lang.String | getCurrentDate()Get the current date in HTTP format.
// --------------------------------------------------------- Public Methods
long now = System.currentTimeMillis();
if ((now - currentDateGenerated) > 1000) {
synchronized (format) {
if ((now - currentDateGenerated) > 1000) {
currentDateGenerated = now;
currentDate = format.format(new Date(now));
}
}
}
return currentDate;
|
private static final java.lang.Long | internalParseDate(java.lang.String value, java.text.DateFormat[] formats)Parse date with given formatters.
Date date = null;
for (int i = 0; (date == null) && (i < formats.length); i++) {
try {
date = formats[i].parse(value);
} catch (ParseException e) {
;
}
}
if (date == null) {
return null;
}
return new Long(date.getTime());
|
public static final long | parseDate(java.lang.String value, java.text.DateFormat[] threadLocalformats)Try to parse the given date as a HTTP date.
Long cachedDate = parseCache.get(value);
if (cachedDate != null)
return cachedDate.longValue();
Long date = null;
if (threadLocalformats != null) {
date = internalParseDate(value, threadLocalformats);
updateParseCache(value, date);
} else {
synchronized (parseCache) {
date = internalParseDate(value, formats);
updateParseCache(value, date);
}
}
if (date == null) {
return (-1L);
} else {
return date.longValue();
}
|
private static void | updateFormatCache(java.lang.Long key, java.lang.String value)Update cache.
if (value == null) {
return;
}
if (formatCache.size() > CACHE_SIZE) {
formatCache.clear();
}
formatCache.put(key, value);
|
private static void | updateParseCache(java.lang.String key, java.lang.Long value)Update cache.
if (value == null) {
return;
}
if (parseCache.size() > CACHE_SIZE) {
parseCache.clear();
}
parseCache.put(key, value);
|