/** * Parses a date value. The formats used for parsing the date value are retrieved from * the default http params. * * @param dateValue the date value to parse * @return the parsed date * @throws DateParseException if the value could not be parsed using any of the * supported date formats */ public static Date parseDate(String dateValue) throws DateParseException { return parseDate(dateValue, null, null); }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Parses the date value using the given date formats. * * @param dateValue the date value to parse * @param dateFormats the date formats to use * @return the parsed date * @throws DateParseException if none of the dataFormats could parse the dateValue */ public static Date parseDate(String dateValue, Collection dateFormats) throws DateParseException { return parseDate(dateValue, dateFormats, null); }
@Override public String toString(Date value) { if (value == null) throw new IllegalArgumentException(Messages.MESSAGES.paramNull()); return DateUtil.formatDate(value); } }
@Override public Date getDate() { String date = requestHeaders.getFirst(DATE); if (date == null) return null; return DateUtil.parseDate(date); }
b.append(DateUtil.formatDate(cookie.getExpiry(), OLD_COOKIE_PATTERN));
public Response.ResponseBuilder ifModifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return Response.notModified(); } return null; }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
public Response.ResponseBuilder ifUnmodifiedSince(String strDate, Date lastModified) { Date date = DateUtil.parseDate(strDate); if (date.getTime() >= lastModified.getTime()) { return null; } return Response.status(SC_PRECONDITION_FAILED).lastModified(lastModified); }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
@Override public Date getDate() { Object d = metadata.getFirst(HttpHeaders.DATE); if (d == null) return null; if (d instanceof Date) return (Date) d; return DateUtil.parseDate(d.toString()); }
@Override public String toString(Date value) { if (value == null) throw new IllegalArgumentException(Messages.MESSAGES.paramNull()); return DateUtil.formatDate(value); } }
@Override public Date getLastModified() { Object d = metadata.getFirst(HttpHeaders.LAST_MODIFIED); if (d == null) return null; if (d instanceof Date) return (Date) d; return DateUtil.parseDate(d.toString()); }
@Override public String toString(Date value) { if (value == null) throw new IllegalArgumentException(Messages.MESSAGES.paramNull()); return DateUtil.formatDate(value); } }
@Override public Date fromString(String value) { if (value == null) throw new IllegalArgumentException(Messages.MESSAGES.paramNull()); return DateUtil.parseDate(value); }
b.append(DateUtil.formatDate(cookie.getExpiry(), OLD_COOKIE_PATTERN));
public Date getDate() { Object d = headers.getFirst(HttpHeaders.DATE); if (d == null) return null; if (d instanceof Date) return (Date) d; return DateUtil.parseDate(d.toString()); }
b.append(DateUtil.formatDate(cookie.getExpiry(), OLD_COOKIE_PATTERN));
public void cacheIfPossible(ClientRequestContext request, ClientResponseContext response) throws IOException { String cc = (String) response.getHeaderString(HttpHeaders.CACHE_CONTROL); String exp = (String) response.getHeaderString(HttpHeaders.EXPIRES); int expires = -1; if (cc != null) { CacheControl cacheControl = CacheControl.valueOf(cc); if (cacheControl.isNoCache()) return; expires = cacheControl.getMaxAge(); } else if (exp != null) { Date date = DateUtil.parseDate(exp); expires = (int) ((date.getTime() - System.currentTimeMillis()) / 1000); } String lastModified = (String) response.getHeaderString(HttpHeaders.LAST_MODIFIED); String etag = (String) response.getHeaderString(HttpHeaders.ETAG); String contentType = (String) response.getHeaderString(HttpHeaders.CONTENT_TYPE); String accept = (String) request.getHeaderString(HttpHeaders.ACCEPT); byte[] cached = ReadFromStream.readFromStream(1024, response.getEntityStream()); // if Accept is present, use it, if not fallback to response Content-Type MediaType mediaType = accept != null ? MediaType.valueOf(accept) : MediaType.valueOf(contentType); final BrowserCache.Entry entry = cache.put(request.getUri().toString(), mediaType, response.getHeaders(), cached, expires, etag, lastModified); response.setEntityStream(new ByteArrayInputStream(cached)); }
/** * Parses a date value. The formats used for parsing the date value are retrieved from * the default http params. * * @param dateValue the date value to parse * @return the parsed date * @throws DateParseException if the value could not be parsed using any of the * supported date formats */ public static Date parseDate(String dateValue) throws DateParseException { return parseDate(dateValue, null, null); }