@Override
    public HttpResponseOutputStream<Node> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        final DelayedHttpEntityCallable<Node> command = new DelayedHttpEntityCallable<Node>(file) {
            @Override
            public Node call(final HttpEntity entity) throws BackgroundException {
                try {
                    final HttpEntityEnclosingRequestBase request;
                    if(status.isExists()) {
                        request = new HttpPut(String.format("%s/api/v1/nodes/%s/revisions", session.getClient().getBasePath(), fileid.getFileId(file)));
                    }
                    else {
                        request = new HttpPost(String.format("%s/api/v1/deepBoxes/%s/boxes/%s/files/%s",
                                session.getClient().getBasePath(),
                                fileid.getDeepBoxNodeId(file),
                                fileid.getBoxNodeId(file),
                                fileid.getFileId(file.getParent())));
                    }
                    final Checksum checksum = status.getChecksum();
                    if(Checksum.NONE != checksum) {
                        switch(checksum.algorithm) {
                            case sha1:
                                request.addHeader(HttpHeaders.CONTENT_MD5, checksum.hash);
                        }
                    }
                    final MultipartEntityBuilder multipart = MultipartEntityBuilder.create();
                    multipart.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
                    multipart.setCharset(StandardCharsets.UTF_8);
                    final ByteArrayOutputStream out = new ByteArrayOutputStream();
                    entity.writeTo(out);
                    if(status.isExists()) {
                        multipart.addBinaryBody("file", out.toByteArray(),
                                null == status.getMime() ? ContentType.APPLICATION_OCTET_STREAM : ContentType.create(status.getMime()), file.getName());
                        request.setEntity(multipart.build());
                        return session.getClient().getClient().execute(request, new AbstractResponseHandler<Node>() {
                            @Override
                            public Node handleEntity(final HttpEntity entity) throws IOException {
                                final ObjectReader reader = new JSON().getContext(null).reader(Node.class);
                                return reader.readValue(entity.getContent());
                            }
                        });
                    }
                    else {
                        multipart.addBinaryBody("files", out.toByteArray(),
                                null == status.getMime() ? ContentType.APPLICATION_OCTET_STREAM : ContentType.create(status.getMime()), file.getName());
                        request.setEntity(multipart.build());
                        return session.getClient().getClient().execute(request, new AbstractResponseHandler<Node>() {
                            @Override
                            public Node handleEntity(final HttpEntity entity) throws IOException {
                                final ObjectReader reader = new JSON().getContext(null).readerForArrayOf(Node.class);
                                final Node[] node = reader.readValue(entity.getContent());
                                return node[0];
                            }
                        });
                    }
                }
                catch(HttpResponseException e) {
                    throw new DefaultHttpResponseExceptionMappingService().map("Upload {0} failed", e, file);
                }
                catch(IOException e) {
                    throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file);
                }
            }

            @Override
            public long getContentLength() {
                return -1L;
            }
        };
        return this.write(file, status, command);
    }
@Test
    public void testOverwrite() throws Exception {
        final DeepboxIdProvider nodeid = new DeepboxIdProvider(session);
        final Path documents = new Path("/ORG 4 - DeepBox Desktop App/ORG3:Box1/Documents/", EnumSet.of(Path.Type.directory, Path.Type.volume));

        final Path file = new Path(documents, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        new DeepboxTouchFeature(session, nodeid).touch(file, new TransferStatus());
        assertTrue(new DefaultFindFeature(session).find(file));
        try {
            final byte[] content = RandomUtils.nextBytes(2047);
            final HttpResponseOutputStream<Node> out = new DeepboxWriteFeature(session, nodeid).write(file,
                    new TransferStatus().exists(true), new DisabledConnectionCallback());
            final ByteArrayInputStream in = new ByteArrayInputStream(content);
            final TransferStatus progress = new TransferStatus();
            final BytecountStreamListener count = new BytecountStreamListener();
            new StreamCopier(progress, progress).withListener(count).transfer(in, out);
            assertEquals(content.length, count.getSent());
            in.close();
            out.close();
            assertTrue(new DefaultFindFeature(session).find(file));
            assertTrue(new DeepboxFindFeature(session, nodeid).find(file));
            assertEquals(content.length, new DeepboxAttributesFinderFeature(session, nodeid).find(file).getSize());
        }
        finally {
            new DeepboxDeleteFeature(session, nodeid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
        }
    }