package synapticloop.b2.io;

/*
 * Copyright (c) 2016 Synapticloop.
 * 
 * All rights reserved.
 * 
 * This code may contain contributions from other parties which, where 
 * applicable, will be listed in the default build file for the project 
 * ~and/or~ in a file named CONTRIBUTORS.txt in the root of the project.
 * 
 * This source code and any derived binaries are covered by the terms and 
 * conditions of the Licence agreement ("the Licence").  You may not use this 
 * source code or any derived binaries except in compliance with the Licence.  
 * A copy of the Licence is available in the file named LICENSE.txt shipped with 
 * this source code or binaries.
 */

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.io.input.CountingInputStream;
import org.apache.http.HttpConnection;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;

public class HttpMethodReleaseInputStream extends CountingInputStream {
	private static final Logger LOGGER = Logger.getLogger(HttpMethodReleaseInputStream.class.getName());

	private HttpResponse response;

	/**
	 * Create a HTTP method release input Stream
	 * 
	 * @param response The HTTP response to read from
	 * 
	 * @throws IOException If there is a problem reading from the response
	 * @throws NullPointerException If the response has no message entity
	 */
	public HttpMethodReleaseInputStream(final HttpResponse response) throws IOException {
		super(response.getEntity().getContent());
		this.response = response;
	}

	/**
	 * This will force close the connection if the content has not been fully consumed
	 *
	 * @throws IOException if an I/O error occurs
	 * @see CloseableHttpResponse#close()
	 * @see HttpConnection#shutdown()
	 */
	@Override
	public void close() throws IOException {
		if(response instanceof CloseableHttpResponse) {
			long read = this.getByteCount();
			if(read == response.getEntity().getContentLength()) {
				// Fully consumed
				super.close();
			} else {
				if(LOGGER.isLoggable(Level.WARNING)) {
					LOGGER.warning(String.format("Abort connection for response '{}'", response));
				}

				// Close an HTTP response as quickly as possible, avoiding consuming
				// response data unnecessarily though at the expense of making underlying
				// connections unavailable for reuse.
				// The response proxy will force close the connection.
				((CloseableHttpResponse) response).close();
			}
		} else {
			// Consume and close
			super.close();
		}
	}
}

@@ -673,102 +673,8 @@
 */%0A%0A
-import java.io.IOException;%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0A
 impo
@@ -861,16 +861,102 @@
 esponse;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport java.io.IOException;
 %0A%0Apublic
@@ -1065,16 +1065,23 @@
 = Logger
+Factory
 .getLogg
@@ -1121,18 +1121,8 @@
 lass
-.getName()
 );%0A%0A
@@ -2053,80 +2053,19 @@
 %09%09%09%09
-if(LOGGER.isLoggable(Level.WARNING)) %7B%0A%09%09%09%09%09LOGGER.warning(String.format
+LOGGER.warn
 (%22Ab
@@ -2112,17 +2112,9 @@
 nse)
-);%0A%09%09%09%09%7D%0A
+;
 %0A%09%09%09

Fix logger usage.