@Override
    public HttpResponseOutputStream<File> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        final String location = new StoregateWriteFeature(session, fileid).start(file, status);
        final MultipartOutputStream proxy = new MultipartOutputStream(location, file, status);
        return new HttpResponseOutputStream<File>(new MemorySegementingOutputStream(proxy,
                new HostPreferences(session.getHost()).getInteger("storegate.upload.multipart.chunksize")),
                new StoregateAttributesFinderFeature(session, fileid), status) {
            @Override
            public File getStatus() {
                return proxy.getResult();
            }
        };
    }
@Test
    public void testWriteWithLock() throws Exception {
        final StoregateIdProvider nodeid = new StoregateIdProvider(session);
        final Path room = new StoregateDirectoryFeature(session, nodeid).mkdir(
            new Path(String.format("/My files/%s", new AlphanumericRandomStringService().random()),
                EnumSet.of(Path.Type.directory, Path.Type.volume)), new TransferStatus());
        final byte[] content = RandomUtils.nextBytes(32769);
        final Path test = new StoregateTouchFeature(session, nodeid).touch(
            new Path(room, String.format("%s", new AlphanumericRandomStringService().random()), EnumSet.of(Path.Type.file)), new TransferStatus());
        final String lockId = new StoregateLockFeature(session, nodeid).lock(test);
        final TransferStatus status = new TransferStatus().withLength(-1L);
        final StoregateMultipartWriteFeature writer = new StoregateMultipartWriteFeature(session, nodeid);
        try {
            final HttpResponseOutputStream<File> out = writer.write(test, status, new DisabledConnectionCallback());
            fail();
        }
        catch(LockedException e) {
            //
        }
        status.setLockId(lockId);
        final HttpResponseOutputStream<File> out = writer.write(test, status, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
        out.close();
        new StoregateLockFeature(session, nodeid).unlock(test, lockId);
        new StoregateDeleteFeature(session, nodeid).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }