@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() == segmentStatus.getLength()) {
                        segmentStatus.setComplete();
                        status.setLength(status.getLength() - segmentStatus.getLength());
                        status.setOffset(status.getOffset() + segmentStatus.getLength());
                    }
                }
            }
        }
        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.withRename((Local) null);
                            if(status.getLength() == 0L) {
                                status.setComplete();
                            }
                        }
                    }
                }
            }
        }
        return status;
    }
@Test
    public void testPrepareDirectoryExists() throws Exception {
        final Host host = new Host(new TestProtocol());
        final NullSession session = new NullTransferSession(host);
        ResumeFilter f = new ResumeFilter(new DisabledDownloadSymlinkResolver(), session,
            new DownloadFilterOptions(host), new DefaultDownloadFeature(session.getFeature(Read.class)) {
            @Override
            public boolean offset(final Path file) {
                return true;
            }
        });
        Path p = new Path("a", EnumSet.of(Path.Type.directory));
        final NullLocal local = new NullLocal("a") {
            @Override
            public boolean exists() {
                return true;
            }

            @Override
            public boolean isFile() {
                return false;
            }

            @Override
            public boolean isDirectory() {
                return true;
            }
        };
        final TransferStatus status = f.prepare(p, local, new TransferStatus().exists(true), new DisabledProgressListener());
        assertTrue(status.isExists());
    }