@Override
    public HttpResponseOutputStream<Void> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        try {
            return this.write(file, this.toHeaders(file, status, expect), status);
        }
        catch(ConflictException e) {
            if(expect) {
                if(null != status.getLockId()) {
                    // Handle 412 Precondition Failed with expired token
                    log.warn(String.format("Retry failure %s with lock id %s removed", e, status.getLockId()));
                    return this.write(file, this.toHeaders(file, status.withLockId(null), expect), status);
                }
            }
            throw e;
        }
        catch(InteroperabilityException e) {
            if(expect) {
                // Handle 417 Expectation Failed
                log.warn(String.format("Retry failure %s with Expect: Continue removed", e));
                return this.write(file, this.toHeaders(file, status.withLockId(null), false), status);
            }
            throw e;
        }
    }
@Test
    public void testReplaceContent() throws Exception {
        final Local local = new Local(System.getProperty("java.io.tmpdir"), new AlphanumericRandomStringService().random());
        final Path folder = new DAVDirectoryFeature(session).mkdir(new Path(new DefaultHomeFinderService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)), new TransferStatus());
        final Path test = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        final HttpUploadFeature upload = new DAVUploadFeature(session);
        {
            final String folderEtag = new DAVAttributesFinderFeature(session).find(folder).getETag();
            final byte[] content = RandomUtils.nextBytes(100);
            final OutputStream out = local.getOutputStream(false);
            IOUtils.write(content, out);
            out.close();
            final TransferStatus status = new TransferStatus();
            status.setLength(content.length);
            upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
                    new DisabledStreamListener(), status, new DisabledConnectionCallback());
            assertNotEquals(folderEtag, new DAVAttributesFinderFeature(session).find(folder).getETag());
        }
        final PathAttributes attr1 = new DAVAttributesFinderFeature(session).find(test);
        {
            final String folderEtag = new DAVAttributesFinderFeature(session).find(folder).getETag();
            final String fileEtag = new DAVAttributesFinderFeature(session).find(test).getETag();
            final byte[] content = RandomUtils.nextBytes(101);
            final OutputStream out = local.getOutputStream(false);
            IOUtils.write(content, out);
            out.close();
            final TransferStatus status = new TransferStatus();
            status.setLength(content.length);
            upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED),
                    new DisabledStreamListener(), status, new DisabledConnectionCallback());
            assertEquals(folderEtag, new DAVAttributesFinderFeature(session).find(folder).getETag());
            assertNotEquals(fileEtag, new DAVAttributesFinderFeature(session).find(test).getETag());
        }
        final PathAttributes attr2 = new DAVAttributesFinderFeature(session).find(test);
        assertEquals(101L, attr2.getSize());
        assertNotEquals(attr1.getETag(), attr2.getETag());
        new DAVDeleteFeature(session).delete(Arrays.asList(test, folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }