package com.yammer.metrics.reporting;

import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class HttpTransport implements Transport {
    private final CloseableHttpClient client;
    private final String seriesUrl;

    public HttpTransport(String host, String apiKey) {
        this.client = HttpClients.createDefault();
        this.seriesUrl = String.format("https://%s/api/v1/series?api_key=%s", host, apiKey);
    }

    public Request prepare() throws IOException {
        return new HttpRequest(this);
    }

    public static class HttpRequest implements Transport.Request {
        private final HttpTransport transport;
        private final HttpPost request;
        private final ByteArrayOutputStream out;

        public HttpRequest(HttpTransport transport) throws IOException {
            this.transport = transport;
            this.request = new HttpPost(this.transport.seriesUrl);
            this.out = new ByteArrayOutputStream();
        }

        public OutputStream getBodyWriter() {
            return out;
        }

        public void send() throws Exception {
            this.out.flush();
            this.out.close();
            this.request.setEntity(new ByteArrayEntity(out.toByteArray(), ContentType.APPLICATION_JSON));

            org.apache.http.client.fluent.Request.Post(this.transport.seriesUrl)
                    .addHeader("Content-Type", "application/json")
                    .bodyByteArray(this.out.toByteArray())
                    .execute();
        }
    }
}

@@ -173,112 +173,8 @@
 ype;
-%0Aimport org.apache.http.impl.client.CloseableHttpClient;%0Aimport org.apache.http.impl.client.HttpClients;
 %0A%0Aim
@@ -321,54 +321,8 @@
 t %7B%0A
-    private final CloseableHttpClient client;%0A
     
@@ -413,59 +413,8 @@
 ) %7B%0A
-        this.client = HttpClients.createDefault();%0A
     

Clean up unused variables