@Override
    public void write(final Path file, final Distribution distribution, final LoginCallback prompt) throws BackgroundException {
        final Path container = session.getFeature(PathContainerService.class).getContainer(file);
        try {
            if(null == distribution.getId()) {
                // No existing configuration
                if(log.isDebugEnabled()) {
                    log.debug(String.format("No existing distribution found for method %s", distribution.getMethod()));
                }
                if(distribution.getMethod().equals(Distribution.STREAMING)) {
                    distribution.setId(this.createStreamingDistribution(container, distribution).getId());
                }
                else if(distribution.getMethod().equals(Distribution.DOWNLOAD)) {
                    distribution.setId(this.createDownloadDistribution(container, distribution).getId());
                }
                else if(distribution.getMethod().equals(Distribution.CUSTOM)
                    || distribution.getMethod().equals(Distribution.WEBSITE_CDN)) {
                    distribution.setId(this.createCustomDistribution(container, distribution).getId());
                }
            }
            else {
                if(distribution.getMethod().equals(Distribution.DOWNLOAD)) {
                    distribution.setEtag(this.updateDownloadDistribution(container, distribution).getETag());
                }
                else if(distribution.getMethod().equals(Distribution.STREAMING)) {
                    distribution.setEtag(this.updateStreamingDistribution(container, distribution).getETag());
                }
                else if(distribution.getMethod().equals(Distribution.CUSTOM)
                    || distribution.getMethod().equals(Distribution.WEBSITE_CDN)) {
                    distribution.setEtag(this.updateCustomDistribution(container, distribution).getETag());
                }
            }
        }
        catch(AmazonClientException e) {
            throw new AmazonServiceExceptionMappingService().map("Cannot write CDN configuration", e);
        }
    }
@Test
    public void testWriteNewStreaming() throws Exception {
        final AtomicBoolean set = new AtomicBoolean();
        final CloudFrontDistributionConfiguration configuration = new CloudFrontDistributionConfiguration(session,
                new S3LocationFeature(session), new DisabledX509TrustManager(), new DefaultX509KeyManager()) {
            @Override
            protected UpdateStreamingDistributionResult updateStreamingDistribution(final Path container, final Distribution distribution) {
                fail();
                return null;
            }

            @Override
            protected StreamingDistribution createStreamingDistribution(final Path container, final Distribution distribution) {
                set.set(true);
                return new StreamingDistribution().withId("");
            }
        };
        final Path container = new Path(UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory, Path.Type.volume));
        final Distribution distribution = new Distribution(Distribution.STREAMING, true);
        configuration.write(container, distribution, new DisabledLoginCallback());
        assertTrue(set.get());
    }