@Test public void testPrepareFile() throws Exception { final NullSession session = new NullTransferSession(new Host(new TestProtocol())); ResumeFilter f = new ResumeFilter(new DisabledDownloadSymlinkResolver(), session, new DownloadFilterOptions(), new DefaultDownloadFeature(session.getFeature(Read.class)) { @Override public boolean offset(final Path file) { return true; } }); Path p = new Path("a", EnumSet.of(Path.Type.file)); final NullLocal local = new NullLocal("~/Downloads", "a") { @Override public LocalAttributes attributes() { return new LocalAttributes("a") { @Override public long getSize() { return 1L; } }; } @Override public boolean isFile() { return true; } @Override public boolean exists() { return true; } }; p.attributes().setSize(2L); final TransferStatus status = f.prepare(p, local, new TransferStatus(), new DisabledProgressListener()); assertTrue(status.isAppend()); assertEquals(1L, status.getOffset(), 0L); }
@Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if(status.isSegmented()) { for(TransferStatus segmentStatus : status.getSegments()) { final Local segmentFile = segmentStatus.getRename().local; if(segmentFile.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Determine if part %s can be skipped", segmentStatus)); } if(segmentFile.attributes().getSize() > 0) { segmentStatus.setAppend(true); segmentStatus.setLength(segmentStatus.getLength() - segmentFile.attributes().getSize()); segmentStatus.setOffset(segmentStatus.getOffset() + segmentFile.attributes().getSize()); if(segmentStatus.getLength() == 0L) { segmentStatus.setComplete(); } status.setAppend(true); status.setLength(status.getLength() - segmentFile.attributes().getSize()); } } } } else { if(download.offset(file)) { if(local.isFile()) { if(local.exists()) { if(local.attributes().getSize() > 0) { status.setAppend(true); status.setLength(status.getLength() - local.attributes().getSize()); status.setOffset(status.getOffset() + local.attributes().getSize()); status.rename((Local) null); if(status.getLength() == 0L) { status.setComplete(); } } } } } } return status; }
ResumeFilter extends AbstractDownloadFilter { @Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if(status.isSegmented()) { for(TransferStatus segmentStatus : status.getSegments()) { final Local segmentFile = segmentStatus.getRename().local; if(segmentFile.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Determine if part %s can be skipped", segmentStatus)); } if(segmentFile.attributes().getSize() > 0) { segmentStatus.setAppend(true); segmentStatus.setLength(segmentStatus.getLength() - segmentFile.attributes().getSize()); segmentStatus.setOffset(segmentStatus.getOffset() + segmentFile.attributes().getSize()); if(segmentStatus.getLength() == 0L) { segmentStatus.setComplete(); } status.setAppend(true); status.setLength(status.getLength() - segmentFile.attributes().getSize()); } } } } else { if(download.offset(file)) { if(local.isFile()) { if(local.exists()) { if(local.attributes().getSize() > 0) { status.setAppend(true); status.setLength(status.getLength() - local.attributes().getSize()); status.setOffset(status.getOffset() + local.attributes().getSize()); status.rename((Local) null); if(status.getLength() == 0L) { status.setComplete(); } } } } } } return status; } }
ResumeFilter extends AbstractDownloadFilter { @Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if(status.isSegmented()) { for(TransferStatus segmentStatus : status.getSegments()) { final Local segmentFile = segmentStatus.getRename().local; if(segmentFile.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Determine if part %s can be skipped", segmentStatus)); } if(segmentFile.attributes().getSize() > 0) { segmentStatus.setAppend(true); segmentStatus.setLength(segmentStatus.getLength() - segmentFile.attributes().getSize()); segmentStatus.setOffset(segmentStatus.getOffset() + segmentFile.attributes().getSize()); if(segmentStatus.getLength() == 0L) { segmentStatus.setComplete(); } status.setAppend(true); status.setLength(status.getLength() - segmentFile.attributes().getSize()); } } } } else { if(download.offset(file)) { if(local.isFile()) { if(local.exists()) { if(local.attributes().getSize() > 0) { status.setAppend(true); status.setLength(status.getLength() - local.attributes().getSize()); status.setOffset(status.getOffset() + local.attributes().getSize()); status.rename((Local) null); if(status.getLength() == 0L) { status.setComplete(); } } } } } } return status; } ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options);  ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options, final Download download); }
ResumeFilter extends AbstractDownloadFilter { @Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if(status.isSegmented()) { for(TransferStatus segmentStatus : status.getSegments()) { final Local segmentFile = segmentStatus.getRename().local; if(segmentFile.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Determine if part %s can be skipped", segmentStatus)); } if(segmentFile.attributes().getSize() > 0) { segmentStatus.setAppend(true); segmentStatus.setLength(segmentStatus.getLength() - segmentFile.attributes().getSize()); segmentStatus.setOffset(segmentStatus.getOffset() + segmentFile.attributes().getSize()); if(segmentStatus.getLength() == 0L) { segmentStatus.setComplete(); } status.setAppend(true); status.setLength(status.getLength() - segmentFile.attributes().getSize()); } } } } else { if(download.offset(file)) { if(local.isFile()) { if(local.exists()) { if(local.attributes().getSize() > 0) { status.setAppend(true); status.setLength(status.getLength() - local.attributes().getSize()); status.setOffset(status.getOffset() + local.attributes().getSize()); status.rename((Local) null); if(status.getLength() == 0L) { status.setComplete(); } } } } } } return status; } ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options);  ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options, final Download download); @Override boolean accept(final Path file, final Local local, final TransferStatus parent); @Override TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress); }
ResumeFilter extends AbstractDownloadFilter { @Override public TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress) throws BackgroundException { final TransferStatus status = super.prepare(file, local, parent, progress); if(status.isSegmented()) { for(TransferStatus segmentStatus : status.getSegments()) { final Local segmentFile = segmentStatus.getRename().local; if(segmentFile.exists()) { if(log.isInfoEnabled()) { log.info(String.format("Determine if part %s can be skipped", segmentStatus)); } if(segmentFile.attributes().getSize() > 0) { segmentStatus.setAppend(true); segmentStatus.setLength(segmentStatus.getLength() - segmentFile.attributes().getSize()); segmentStatus.setOffset(segmentStatus.getOffset() + segmentFile.attributes().getSize()); if(segmentStatus.getLength() == 0L) { segmentStatus.setComplete(); } status.setAppend(true); status.setLength(status.getLength() - segmentFile.attributes().getSize()); } } } } else { if(download.offset(file)) { if(local.isFile()) { if(local.exists()) { if(local.attributes().getSize() > 0) { status.setAppend(true); status.setLength(status.getLength() - local.attributes().getSize()); status.setOffset(status.getOffset() + local.attributes().getSize()); status.rename((Local) null); if(status.getLength() == 0L) { status.setComplete(); } } } } } } return status; } ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session);  ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options);  ResumeFilter(final SymlinkResolver<Path> symlinkResolver, final Session<?> session,
                        final DownloadFilterOptions options, final Download download); @Override boolean accept(final Path file, final Local local, final TransferStatus parent); @Override TransferStatus prepare(final Path file, final Local local, final TransferStatus parent, final ProgressListener progress);  }