/** * Parse the timestamp using the MTDM format * * @param timestamp Date string * @return Milliseconds */ protected long parseTimestamp(final String timestamp) { if(null == timestamp) { return -1; } try { final Date parsed = new MDTMSecondsDateFormatter().parse(timestamp); return parsed.getTime(); } catch(InvalidDateException e) { log.warn("Failed to parse timestamp:" + e.getMessage()); try { final Date parsed = new MDTMMillisecondsDateFormatter().parse(timestamp); return parsed.getTime(); } catch(InvalidDateException f) { log.warn("Failed to parse timestamp:" + f.getMessage()); } } log.error(String.format("Failed to parse timestamp %s", timestamp)); return -1; }
@Override public Date parse(final String input) throws InvalidDateException { if(StringUtils.isBlank(input)) { throw new InvalidDateException(); } synchronized(format) { try { return format.parse(input); } catch(ParseException e) { throw new InvalidDateException(e.getMessage(), e); } } } }
protected PathAttributes toAttributes(final StorageObject object) { final PathAttributes attributes = new PathAttributes(); if(StringUtils.isNotBlank(object.getMd5sum())) { // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of // the concatenated string of ETags for each of the segments in the manifest. attributes.setChecksum(Checksum.parse(object.getMd5sum())); } attributes.setSize(object.getSize()); final String lastModified = object.getLastModified(); if(lastModified != null) { try { attributes.setModificationDate(iso8601DateParser.parse(lastModified).getTime()); } catch(InvalidDateException e) { log.warn(String.format("%s is not ISO 8601 format %s", lastModified, e.getMessage())); try { attributes.setModificationDate(rfc1123DateFormatter.parse(lastModified).getTime()); } catch(InvalidDateException f) { log.warn(String.format("%s is not RFC 1123 format %s", lastModified, f.getMessage())); } } } return attributes; }
private boolean check(final StringTokenizer st, final String token) throws InvalidDateException { try { if(st.nextToken().equals(token)) { return true; } else { throw new InvalidDateException(String.format("Missing [%s]", token)); } } catch(NoSuchElementException ex) { return false; } }
protected PathAttributes toAttributes(final ObjectMetadata metadata) { final PathAttributes attributes = new PathAttributes(); attributes.setSize(Long.valueOf(metadata.getContentLength())); final String lastModified = metadata.getLastModified(); try { attributes.setModificationDate(rfc1123DateFormatter.parse(lastModified).getTime()); } catch(InvalidDateException e) { log.warn(String.format("%s is not RFC 1123 format %s", lastModified, e.getMessage())); } if(StringUtils.isNotBlank(metadata.getETag())) { final String etag = StringUtils.removePattern(metadata.getETag(), "\""); attributes.setETag(etag); if(metadata.getMetaData().containsKey(Constants.X_STATIC_LARGE_OBJECT)) { // For manifest files, the ETag in the response for a GET or HEAD on the manifest file is the MD5 sum of // the concatenated string of ETags for each of the segments in the manifest. attributes.setChecksum(Checksum.NONE); } else { attributes.setChecksum(Checksum.parse(etag)); } } return attributes; } }
/** * Parse the given string in ISO 8601 format and build a Date object. * * @param input the date in ISO 8601 format * @return a Date instance * @throws InvalidDateException if the date is not valid */ public Date parse(final String input) throws InvalidDateException { if(StringUtils.isBlank(input)) { throw new InvalidDateException(); } return this.getCalendar(input).getTime(); } }
log.warn(String.format("%s is not RFC 1123 format %s", headers.get(HttpHeaders.LAST_MODIFIED), p.getMessage()));
throw new InvalidDateException("No seconds specified"); throw new InvalidDateException("only Z, + or - allowed"); throw new InvalidDateException("Missing hour field"); throw new InvalidDateException("Missing minute field"); throw new InvalidDateException(String.format("[%s] is not an integer", ex.getMessage()), ex);
log.warn(String.format("Failed to parse timestamp from %s %s", elementText, e.getMessage()));
log.warn(String.format("%s is not ISO 8601 format %s", s.getLastModified(), e.getMessage()));