@Override
    public StatusOutputStream<Void> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        try {
            final java.nio.file.Path p = session.toPath(file);
            final Set<OpenOption> options = new HashSet<>();
            options.add(StandardOpenOption.WRITE);
            if(status.isAppend()) {
                if(!status.isExists()) {
                    options.add(StandardOpenOption.CREATE);
                }
            }
            else {
                if(status.isExists()) {
                    if(file.isSymbolicLink()) {
                        Files.delete(p);
                        options.add(StandardOpenOption.CREATE);
                    }
                    else {
                        options.add(StandardOpenOption.TRUNCATE_EXISTING);
                    }
                }
                else {
                    options.add(StandardOpenOption.CREATE_NEW);
                }
            }
            final FileChannel channel = FileChannel.open(session.toPath(file), options.stream().toArray(OpenOption[]::new));
            channel.position(status.getOffset());
            return new VoidStatusOutputStream(Channels.newOutputStream(channel));
        }
        catch(IOException e) {
            throw new LocalExceptionMappingService().map("Upload {0} failed", e, file);
        }
    }
@Test(expected = NotfoundException.class)
    public void testWriteNotFound() throws Exception {
        final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname()));
        session.open(new DisabledProxyFinder(), new DisabledHostKeyCallback(), new DisabledLoginCallback(), new DisabledCancelCallback());
        session.login(new DisabledLoginCallback(), new DisabledCancelCallback());
        final Path workdir = new LocalHomeFinderFeature().find();
        final Path test = new Path(workdir.getAbsolute() + "/nosuchdirectory/" + UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
        new LocalWriteFeature(session).write(test, new TransferStatus(), new DisabledConnectionCallback());
    }