I am using org.apache.http and I've this code:

DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);

HttpResponse resp = client.execute(get);
HttpEntity entity = resp.getEntity();

InputStream input = entity.getContent();

...
//Read the bytes from input stream

This is the code I am using to download files over Http, I want to cancel the connection(may be user chooses to) What is the graceful way to close the connection. I found 2 ways, Both cancels the download.

  1. Closing inputsteram, input.close(); which causes IOException.
  2. Aborting HttpGet object, get.abort() causes SocketException.

I have try catch, so no erros, but without throwing exception, is there a way to cancel or abort the connection?

What is the right way to go about it ?

Edit
Report