public String getMediumFormat(long milliseconds) { return this.getMediumFormat(milliseconds, true); }
@Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { Local rename; do { String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.download.file.rename.format"), FilenameUtils.getBaseName(file.getName()), UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(local.getDelimiter(), '-').replace(':', '-'), StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY); rename = LocalFactory.get(local.getParent().getAbsolute(), proposal); } while(rename.exists()); if(log.isInfoEnabled()) { log.info(String.format("Rename existing file %s to %s", local, rename)); } local.rename(rename); if(log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", local)); } status.setExists(false); } super.apply(file, local, status, listener); } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); if(file.isFile()) { try { // This link will expire in four hours and afterwards you will get 410 Gone. final String link = new DbxUserFilesRequests(session.getClient()).getTemporaryLink(file.getAbsolute()).getLink(); // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.HOUR, 4); list.add(new DescriptiveUrl(URI.create(link), DescriptiveUrl.Type.http, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Temporary", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) )); } catch(DbxException e) { log.warn(String.format("Failure retrieving shared link. %s", e.getMessage())); } } return list; } }
/** * Rename existing file on server if there is a conflict. */ @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { // Rename existing file before putting new file in place if(status.isExists()) { Path rename; do { final String proposal = MessageFormat.format(PreferencesFactory.get().getProperty("queue.upload.file.rename.format"), FilenameUtils.getBaseName(file.getName()), UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis(), false).replace(Path.DELIMITER, '-').replace(':', '-'), StringUtils.isNotBlank(file.getExtension()) ? String.format(".%s", file.getExtension()) : StringUtils.EMPTY); rename = new Path(file.getParent(), proposal, file.getType()); } while(find.withCache(cache).find(rename)); if(log.isInfoEnabled()) { log.info(String.format("Rename existing file %s to %s", file, rename)); } move.move(file, rename, new TransferStatus().exists(false), new Delete.DisabledCallback(), new DisabledConnectionCallback()); if(log.isDebugEnabled()) { log.debug(String.format("Clear exist flag for file %s", file)); } status.setExists(false); } super.apply(file, local, status, listener); } }
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis() + expiresIn.toMillis())))); MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis() + expiresIn.toMillis())))); MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(System.currentTimeMillis() + expiresIn.toMillis()))));
@Override public DescriptiveUrl toDownloadUrl(final Path file, final Void none, final PasswordCallback callback) throws BackgroundException { if(file.isFile()) { final String download = String.format("%s/file/%s/%s", session.getClient().getDownloadUrl(), URIEncoder.encode(containerService.getContainer(file).getName()), URIEncoder.encode(containerService.getKey(file))); try { final int seconds = 604800; // Determine expiry time for URL final Calendar expiry = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiry.add(Calendar.SECOND, seconds); final String token = session.getClient().getDownloadAuthorization(fileid.getFileid(containerService.getContainer(file), new DisabledListProgressListener()), StringUtils.EMPTY, seconds); return new DescriptiveUrl(URI.create(String.format("%s?Authorization=%s", download, token)), DescriptiveUrl.Type.signed, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) ); } catch(B2ApiException e) { throw new B2ExceptionMappingService().map(e); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } return DescriptiveUrl.EMPTY; }
MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Pre-Signed", "S3")) + " (" + MessageFormat.format(LocaleFactory.localizedString("Expires {0}", "S3") + ")", UserDateFormatterFactory.get().getMediumFormat(expiry.getTimeInMillis())) );
@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()); } }