@Override
    public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        // Submit store run to background thread
        final DelayedHttpEntityCallable<StorageObject> command = new DelayedHttpEntityCallable<StorageObject>(file) {
            /**
             * @return The ETag returned by the server for the uploaded object
             */
            @Override
            public StorageObject call(final HttpEntity entity) throws BackgroundException {
                try {
                    // Previous
                    final HashMap<String, String> headers = new HashMap<>(status.getMetadata());
                    if(status.isExists()) {
                        // Remove any large object header read from metadata of existing file
                        headers.remove(Constants.X_STATIC_LARGE_OBJECT);
                    }
                    final Checksum checksum = status.getChecksum();
                    final String etag = session.getClient().storeObject(
                            regionService.lookup(file),
                            containerService.getContainer(file).getName(), containerService.getKey(file),
                            entity, headers, checksum.algorithm == HashAlgorithm.md5 ? checksum.hash : null);
                    if(log.isDebugEnabled()) {
                        log.debug(String.format("Saved object %s with checksum %s", file, etag));
                    }
                    final StorageObject stored = new StorageObject(containerService.getKey(file));
                    stored.setMd5sum(etag);
                    stored.setSize(status.getLength());
                    return stored;
                }
                catch(GenericException e) {
                    throw new SwiftExceptionMappingService().map("Upload {0} failed", e, file);
                }
                catch(IOException e) {
                    throw new DefaultIOExceptionMappingService().map("Upload {0} failed", e, file);
                }
            }

            @Override
            public long getContentLength() {
                return status.getLength();
            }
        };
        return this.write(file, status, command);
    }
@Test
    public void testWrite() throws Exception {
        final TransferStatus status = new TransferStatus();
        status.setMime("text/plain");
        final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
        status.setLength(content.length);
        final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
        container.attributes().setRegion("IAD");
        final Path test = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final SwiftRegionService regionService = new SwiftRegionService(session);
        status.setMetadata(Collections.singletonMap("C", "duck"));
        final StatusOutputStream<StorageObject> out = new SwiftWriteFeature(session, regionService).write(test, status, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
        out.close();
        assertEquals(new SwiftAttributesFinderFeature(session).toAttributes(out.getStatus()).getChecksum(), new SwiftAttributesFinderFeature(session).find(test).getChecksum());
        assertTrue(new SwiftFindFeature(session).find(test));
        final PathAttributes attributes = new SwiftListService(session, regionService).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
        assertEquals(content.length, attributes.getSize());
        final byte[] buffer = new byte[content.length];
        final InputStream in = new SwiftReadFeature(session, regionService).read(test, new TransferStatus(), new DisabledConnectionCallback());
        IOUtils.readFully(in, buffer);
        in.close();
        assertArrayEquals(content, buffer);
        final Map<String, String> metadata = new SwiftMetadataFeature(session).getMetadata(test);
        assertFalse(metadata.isEmpty());
        assertEquals("text/plain", metadata.get("Content-Type"));
        assertEquals("duck", metadata.get("X-Object-Meta-C"));
        final OutputStream overwrite = new SwiftWriteFeature(session, regionService).write(test, new TransferStatus().withLength(0L), new DisabledConnectionCallback());
        overwrite.close();
        new SwiftDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }