@Override
    public HttpResponseOutputStream<StorageObject> write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
        final LargeUploadOutputStream proxy = new LargeUploadOutputStream(file, status);
        return new HttpResponseOutputStream<StorageObject>(new MemorySegementingOutputStream(proxy,
                new HostPreferences(session.getHost()).getInteger("openstack.upload.largeobject.size.minimum")),
                new SwiftAttributesFinderFeature(session, regionService), status) {
            @Override
            public StorageObject getStatus() {
                return proxy.getResponse();
            }
        };
    }
@Test
    public void testTruncate() throws Exception {
        final SwiftRegionService regionService = new SwiftRegionService(session);
        final Path container = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.directory, Path.Type.volume));
        container.attributes().setRegion("IAD");
        final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final SwiftLargeUploadWriteFeature feature = new SwiftLargeUploadWriteFeature(session, regionService,
                new SwiftSegmentService(session, ".segments-test/"));
        {
            final TransferStatus status = new TransferStatus();
            status.setLength(-1L);
            final HttpResponseOutputStream<StorageObject> out = feature.write(file, status, new DisabledConnectionCallback());
            final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
            final ByteArrayInputStream in = new ByteArrayInputStream(content);
            final TransferStatus progress = new TransferStatus();
            final BytecountStreamListener count = new BytecountStreamListener();
            new StreamCopier(new TransferStatus(), progress).withListener(count).transfer(in, out);
            assertEquals(content.length, count.getSent());
            assertEquals(content.length, out.getStatus().getSize(), 0L);
            assertTrue(new SwiftFindFeature(session).find(file));
            final byte[] compare = new byte[content.length];
            final InputStream stream = new SwiftReadFeature(session, regionService).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
            IOUtils.readFully(stream, compare);
            stream.close();
            assertArrayEquals(content, compare);
        }
        {
            final byte[] content = RandomUtils.nextBytes(0);
            final TransferStatus status = new TransferStatus();
            status.setLength(-1L);
            status.setExists(true);
            status.setMetadata(new SwiftAttributesFinderFeature(session, regionService).find(file).getMetadata());
            final HttpResponseOutputStream<StorageObject> out = feature.write(file, status, new DisabledConnectionCallback());
            final ByteArrayInputStream in = new ByteArrayInputStream(content);
            assertEquals(content.length, IOUtils.copyLarge(in, out));
            in.close();
            out.close();
            assertNotNull(out.getStatus());
            assertEquals(0L, out.getStatus().getSize(), 0L);
            assertTrue(new DefaultFindFeature(session).find(file));
            final byte[] compare = new byte[content.length];
            final InputStream stream = new SwiftReadFeature(session, regionService).read(file, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
            IOUtils.readFully(stream, compare);
            stream.close();
            assertArrayEquals(content, compare);
            new SwiftDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
        }
    }