public String getShortFormat(long milliseconds) { return this.getShortFormat(milliseconds, true); }
public String getLongFormat(long milliseconds) { return this.getLongFormat(milliseconds, true); } }
public String getMediumFormat(long milliseconds) { return this.getMediumFormat(milliseconds, true); }
/** * 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; }
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; }
protected Map<QName, String> getCustomProperties(final DavResource resource, final Long modified) { return Collections.singletonMap(LAST_MODIFIED_WIN32_CUSTOM_NAMESPACE, new RFC1123DateFormatter().format(modified, TimeZone.getTimeZone("GMT"))); } }
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(); } }
@Override public void progress(final Integer seconds) { progress.message(MessageFormat.format(LocaleFactory.localizedString("Retry again in {0} ({1} more attempts)", "Status"), new RemainingPeriodFormatter().format(seconds), retry - count)); } }, delay);
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; } }
public TimestampComparisonService(final TimeZone tz) { this.calendarService = new CalendarService(tz); }
@Override public Comparison compare(final Attributes remote, final Attributes local) { if(log.isDebugEnabled()) { log.debug(String.format("Compare timestamp for %s with %s", remote, local)); } if(-1 == remote.getModificationDate()) { log.warn(String.format("No remote modification date available for comparison for %s", remote)); return Comparison.unknown; } if(-1 == local.getModificationDate()) { log.warn(String.format("No local modification date available for comparison for %s", local)); return Comparison.unknown; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).before( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.remote; } if(calendarService.asDate(local.getModificationDate(), Instant.SECOND).after( calendarService.asDate(remote.getModificationDate(), Instant.SECOND))) { return Comparison.local; } // Same timestamp return Comparison.equal; } }
@Override public void visit(final AttributedList<Path> list, final int index, final Path file) { if(l) { if(file.isSymbolicLink()) { console.printf("%n%sl%s\t%s\t%s -> %s%s", Ansi.ansi().bold(), file.attributes().getPermission().getSymbol(), formatter.getMediumFormat( file.attributes().getModificationDate()), file.getName(), file.getSymlinkTarget().getAbsolute(), Ansi.ansi().reset()); } else { console.printf("%n%s%s%s\t%s\t%s\t%s%s", Ansi.ansi().bold(), file.isDirectory() ? "d" : "-", file.attributes().getPermission().getSymbol(), formatter.getMediumFormat( file.attributes().getModificationDate()), StringUtils.isNotBlank(file.attributes().getRegion()) ? file.attributes().getRegion() : StringUtils.EMPTY, file.getName(), Ansi.ansi().reset()); } } else { console.printf("%n%s%s%s", Ansi.ansi().bold(), file.getName(), Ansi.ansi().reset()); } }
@Override public NSView getAccessoryView(final NSAlert alert) { final NSView view = super.getAccessoryView(alert); String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("browser.duplicate.format"), FilenameUtils.getBaseName(selected.getName()), UserDateFormatterFactory.get().getShortFormat(System.currentTimeMillis(), false).replace(Path.DELIMITER, ':'), StringUtils.isNotBlank(selected.getExtension()) ? String.format(".%s", selected.getExtension()) : StringUtils.EMPTY); this.updateField(inputField, proposal); return view; }
protected Map<QName, String> getCustomProperties(final DavResource resource, final Long modified) { final HashMap<QName, String> props = new HashMap<>(); if(resource.getModified() != null) { props.put(LAST_MODIFIED_SERVER_CUSTOM_NAMESPACE, new RFC1123DateFormatter().format(resource.getModified(), TimeZone.getTimeZone("UTC"))); } props.put(LAST_MODIFIED_CUSTOM_NAMESPACE, new RFC1123DateFormatter().format(modified, TimeZone.getTimeZone("UTC"))); return props; } }
@Override public String getComment(final Host host) { Date timestamp = host.getTimestamp(); if(null != timestamp) { // Set comment to timestamp when server was last accessed return UserDateFormatterFactory.get().getLongFormat(timestamp.getTime()); } // There might be files from previous versions that have no timestamp yet. return null; }
@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); } } } }
@Action public void metadataAddExpiresClicked(ID sender) { final Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.add(Calendar.SECOND, preferences.getInteger("s3.cache.seconds")); this.addMetadataItem("Expires", new RFC1123DateFormatter().format(time.getTime(), TimeZone.getTimeZone("UTC"))); }
public void setMessage(final String message) { final String text; if(StringUtils.isBlank(message)) { // Do not display any progress text when transfer is stopped final Date timestamp = transfer.getTimestamp(); if(null != timestamp) { text = UserDateFormatterFactory.get().getLongFormat(timestamp.getTime(), false); } else { text = StringUtils.EMPTY; } } else { text = message; } messageField.setAttributedStringValue(NSAttributedString.attributedStringWithAttributes( text, TRUNCATE_MIDDLE_ATTRIBUTES)); }
protected void add(final String fullname, final String hostname, final int port, final String user, final String password, final String path) { final Protocol protocol = this.getProtocol(fullname); if(null == protocol) { log.warn(String.format("Unknown service type for %s", fullname)); return; } final Host host = new Host(protocol, hostname, port); host.getCredentials().setUsername(user); host.getCredentials().setPassword(password); if(StringUtils.isNotBlank(path)) { host.setDefaultPath(PathNormalizer.normalize(path)); } host.setComment(UserDateFormatterFactory.get().getLongFormat(new Date().getTime())); this.add(fullname, host); }