@Override
    public HttpResponseOutputStream<EueWriteFeature.Chunk> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        String uploadUri;
        String resourceId;
        if(status.isExists()) {
            resourceId = fileid.getFileId(file);
            uploadUri = EueUploadHelper.updateResource(session,
                    resourceId, status, UploadType.CHUNKED).getUploadURI();
        }
        else {
            final ResourceCreationResponseEntry resourceCreationResponseEntry =
                    EueUploadHelper.createResource(session, fileid.getFileId(file.getParent()), file.getName(),
                            status, UploadType.CHUNKED);
            resourceId = EueResourceIdProvider.getResourceIdFromResourceUri(resourceCreationResponseEntry.getHeaders().getLocation());
            uploadUri = resourceCreationResponseEntry.getEntity().getUploadURI();
        }
        final MultipartOutputStream proxy;
        try {
            proxy = new MultipartOutputStream(file, resourceId, uploadUri, status, callback);
        }
        catch(NoSuchAlgorithmException e) {
            throw new ChecksumException(LocaleFactory.localizedString("Checksum failure", "Error"), e);
        }
        return new HttpResponseOutputStream<EueWriteFeature.Chunk>(new MemorySegementingOutputStream(proxy,
                new HostPreferences(session.getHost()).getInteger("eue.upload.multipart.size")),
                new EueAttributesAdapter(), status) {
            @Override
            public EueWriteFeature.Chunk getStatus() {
                return proxy.getResult();
            }
        };
    }
@Test
    public void testWriteZeroLength() throws Exception {
        final EueResourceIdProvider fileid = new EueResourceIdProvider(session);
        final EueMultipartWriteFeature feature = new EueMultipartWriteFeature(session, fileid);
        final Path container = new EueDirectoryFeature(session, fileid).mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
        final byte[] content = RandomUtils.nextBytes(0);
        final TransferStatus status = new TransferStatus().withLength(-1L);
        final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final HttpResponseOutputStream<EueWriteFeature.Chunk> out = feature.write(file, status, new DisabledConnectionCallback());
        final ByteArrayInputStream in = new ByteArrayInputStream(content);
        assertEquals(content.length, IOUtils.copyLarge(in, out));
        in.close();
        out.close();
        assertTrue(new DefaultFindFeature(session).find(file));
        final byte[] compare = new byte[content.length];
        final InputStream stream = new EueReadFeature(session, fileid).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
        IOUtils.readFully(stream, compare);
        stream.close();
        assertArrayEquals(content, compare);
        new EueDeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }