@Test public void testTryParseDate() { List<String> nonDates = Arrays.asList("not a date", null, "", "Abc Def 20 10:11:40 2014 XUL"); for (String nonDate : nonDates) { assertFalse("non-dates should fail the check: " + nonDate, RequestContent.tryParseDate(nonDate) != null); } List<String> dates = Arrays.asList( "Fri Jun 1 10:11:40 2014 GMT", "Fri Jun 20 10:11:40 2014 GMT", "Thu, 01 Dec 1994 16:00:00 GMT", "Tue, 07 Jun 2014 20:51:35 GMT" ); for (String date : dates) { assertTrue("real dates should pass the check: " + date, RequestContent.tryParseDate(date) != null); } }
protected static Date tryParseDate(String date) { if (date != null) { for (String formatString : SUPPORTED_DATE_FORMATS) { try { DateFormat dateFormat = new SimpleDateFormat(formatString, Locale.US); dateFormat.setTimeZone(getGMT()); return dateFormat.parse(date); } catch (ParseException e) { LOGGER.warning("[tryParseDate] date string " + date + " does not match format " + formatString); } } } return null; }
RequestContent implements Serializable { protected static Date tryParseDate(String date) { if (date != null) { for (String formatString : SUPPORTED_DATE_FORMATS) { try { DateFormat dateFormat = new SimpleDateFormat(formatString, Locale.US); dateFormat.setTimeZone(getGMT()); return dateFormat.parse(date); } catch (ParseException e) { LOGGER.warning("[tryParseDate] date string " + date + " does not match format " + formatString); } } } return null; } }
RequestContent implements Serializable { protected static Date tryParseDate(String date) { if (date != null) { for (String formatString : SUPPORTED_DATE_FORMATS) { try { DateFormat dateFormat = new SimpleDateFormat(formatString, Locale.US); dateFormat.setTimeZone(getGMT()); return dateFormat.parse(date); } catch (ParseException e) { LOGGER.warning("[tryParseDate] date string " + date + " does not match format " + formatString); } } } return null; } private  RequestContent(final String requestLine, final String method, final String path, final Map<String, List<String>> headers); }
RequestContent implements Serializable { protected static Date tryParseDate(String date) { if (date != null) { for (String formatString : SUPPORTED_DATE_FORMATS) { try { DateFormat dateFormat = new SimpleDateFormat(formatString, Locale.US); dateFormat.setTimeZone(getGMT()); return dateFormat.parse(date); } catch (ParseException e) { LOGGER.warning("[tryParseDate] date string " + date + " does not match format " + formatString); } } } return null; } private  RequestContent(final String requestLine, final String method, final String path, final Map<String, List<String>> headers); @Deprecated byte[] getContent(List<String> headers, Charset charset); @Deprecated String getContentString(List<String> headers); String getStringToSign(List<String> headers); byte[] getBytesToSign(List<String> headers, Charset charset); @Override String toString(); List<String> getHeaderNames(); @Deprecated String getRequestLine(); String getRequestTarget(); String getDate(); List<String> getHeaderValues(String name); Date getDateGMT(); Calendar getDateTZ(TimeZone timeZone); }
RequestContent implements Serializable { protected static Date tryParseDate(String date) { if (date != null) { for (String formatString : SUPPORTED_DATE_FORMATS) { try { DateFormat dateFormat = new SimpleDateFormat(formatString, Locale.US); dateFormat.setTimeZone(getGMT()); return dateFormat.parse(date); } catch (ParseException e) { LOGGER.warning("[tryParseDate] date string " + date + " does not match format " + formatString); } } } return null; } private  RequestContent(final String requestLine, final String method, final String path, final Map<String, List<String>> headers); @Deprecated byte[] getContent(List<String> headers, Charset charset); @Deprecated String getContentString(List<String> headers); String getStringToSign(List<String> headers); byte[] getBytesToSign(List<String> headers, Charset charset); @Override String toString(); List<String> getHeaderNames(); @Deprecated String getRequestLine(); String getRequestTarget(); String getDate(); List<String> getHeaderValues(String name); Date getDateGMT(); Calendar getDateTZ(TimeZone timeZone); @Deprecated
    static final String DATE_FORMAT; static final String DATE_FORMAT_RFC1123; }