@Test public void testApplyRename() throws Exception { RenameExistingFilter f = new RenameExistingFilter(new DisabledDownloadSymlinkResolver(), new NullTransferSession(new Host(new TestProtocol()))); final String name = new AsciiRandomStringService().random(); final Local local = LocalFactory.get(System.getProperty("java.io.tmpdir"), name); new DefaultLocalTouchFeature().touch(local); new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(RandomUtils.nextBytes(1)), local.getOutputStream(false)); final Path p = new Path(name, EnumSet.of(Path.Type.file)); final TransferStatus status = f.prepare(p, local, new TransferStatus().exists(true), new DisabledProgressListener()); assertTrue(status.isExists()); assertNull(status.getRename().local); f.apply(p, local, status, new DisabledProgressListener()); assertEquals(name, local.getName()); assertFalse(status.isExists()); }
@Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { if(local.attributes().getSize() == 0) { log.warn(String.format("Skip renaming placeholder file %s", local)); } else { 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)); } LocalFactory.get(local.getAbsolute()).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); }
RenameExistingFilter extends AbstractDownloadFilter { @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { if(local.attributes().getSize() == 0) { log.warn(String.format("Skip renaming placeholder file %s", local)); } else { 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)); } LocalFactory.get(local.getAbsolute()).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); } }
RenameExistingFilter extends AbstractDownloadFilter { @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { if(local.attributes().getSize() == 0) { log.warn(String.format("Skip renaming placeholder file %s", local)); } else { 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)); } LocalFactory.get(local.getAbsolute()).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); } RenameExistingFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  RenameExistingFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                                final DownloadFilterOptions options); }
RenameExistingFilter extends AbstractDownloadFilter { @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { if(local.attributes().getSize() == 0) { log.warn(String.format("Skip renaming placeholder file %s", local)); } else { 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)); } LocalFactory.get(local.getAbsolute()).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); } RenameExistingFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  RenameExistingFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                                final DownloadFilterOptions options); @Override void apply(final Path file, final Local local, final TransferStatus status,
                      final ProgressListener listener); }
RenameExistingFilter extends AbstractDownloadFilter { @Override public void apply(final Path file, final Local local, final TransferStatus status, final ProgressListener listener) throws BackgroundException { if(status.isExists()) { if(local.attributes().getSize() == 0) { log.warn(String.format("Skip renaming placeholder file %s", local)); } else { 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)); } LocalFactory.get(local.getAbsolute()).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); } RenameExistingFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  RenameExistingFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                                final DownloadFilterOptions options); @Override void apply(final Path file, final Local local, final TransferStatus status,
                      final ProgressListener listener);  }