The problem is this: You are using a ResponseHandler
that simply reads the entire HTTP response into a byte array in memory. You don't have that much memory.
You need to get the underlying InputStream
and loop, reading a reasonable amount of data from the stream then writing to your output file.
The InputStream
is inside the HttpEntity
which you get from the HttpResponse
You can either:
A) Write a custom ResponseHandler
whose constructor you pass your File
to and it does all the work.
or
B) Just call client.execute(getMethod)
. This will return the HttpResponse
directly.