@Override
    public StatusOutputStream<Void> write(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
        final SMBSession.DiskShareWrapper share = session.openShare(file);
        try {
            final File entry = share.get().openFile(new SMBPathContainerService(session).getKey(file),
                    Collections.singleton(AccessMask.FILE_WRITE_DATA),
                    Collections.singleton(FileAttributes.FILE_ATTRIBUTE_NORMAL),
                    Collections.singleton(SMB2ShareAccess.FILE_SHARE_READ),
                    status.isExists() ? SMB2CreateDisposition.FILE_OVERWRITE : SMB2CreateDisposition.FILE_CREATE,
                    Collections.singleton(SMB2CreateOptions.FILE_NON_DIRECTORY_FILE));
            return new VoidStatusOutputStream(new SMBOutputStream(file, entry.getOutputStream(), entry));
        }
        catch(SMBRuntimeException e) {
            throw new SMBExceptionMappingService().map("Upload {0} failed", e, file);
        }
        finally {
            session.releaseShare(share);
        }
    }
@Test
    public void testWrite() throws Exception {
        final Path home = new DefaultHomeFinderService(session).find();
        final Path test = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
        {
            final TransferStatus status = new TransferStatus();
            final int length = 1048576;
            final byte[] content = RandomUtils.nextBytes(length);
            status.setLength(content.length);
            final Write writer = new SMBWriteFeature(session);
            status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
            final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
            assertNotNull(out);
            new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
            assertTrue(new SMBFindFeature(session).find(test));
            assertEquals(content.length, new SMBListService(session).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
            final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
            final InputStream in = new SMBReadFeature(session).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
            new StreamCopier(status, status).transfer(in, buffer);
            assertArrayEquals(content, buffer.toByteArray());
        }
        {
            final TransferStatus status = new TransferStatus().exists(true);
            final int length = 548576;
            final byte[] content = RandomUtils.nextBytes(length);
            status.setLength(content.length);
            final Write writer = new SMBWriteFeature(session);
            status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
            final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
            assertNotNull(out);
            new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
            assertTrue(new SMBFindFeature(session).find(test));
            assertEquals(content.length, new SMBListService(session).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
            final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
            final InputStream in = new SMBReadFeature(session).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
            new StreamCopier(status, status).transfer(in, buffer);
            assertArrayEquals(content, buffer.toByteArray());
        }
        new SMBDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    }