Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] Looking for Jetty HttpClient that downloads large zip files ...

Hi,

On Wed, Sep 14, 2016 at 7:46 PM, Alan Nexus <alan.nexus.6@xxxxxxxxx> wrote:
> Hi Simone, Yes any help would be appreciated ... See my comment in code
> below:  // ***
> Thanks, -Alan
>
>
> import org.eclipse.jetty.client.api.AuthenticationStore;
> import org.eclipse.jetty.client.HttpClient;
> import org.eclipse.jetty.client.api.Result;
> import org.eclipse.jetty.client.util.BasicAuthentication;
> import org.eclipse.jetty.client.util.BufferingResponseListener;
> import java.net.URI;
>
> /*
>  * Testcode driver
>  */
> final public class App {
>     public static void main(String[] args) throws Exception {
>         HttpClient httpClient = new HttpClient();
>         httpClient.start();
>
>         String url = "http://localhost:8080/largefile.zip";;
>         URI uri = new URI(url);
>
>         String realm = "MyRealm";
>         String u = "u1";
>         String p = "p1";
>
>         AuthenticationStore auth = httpClient.getAuthenticationStore();
>         auth.addAuthentication(new BasicAuthentication(uri, realm, u, p));
>
>         httpClient.newRequest(uri)
>                 // Buffer response content up to 8 MiB
>                 .send(new BufferingResponseListener(8 * 1024 * 1024)

So with this you tell HttpClient to buffer up to 8 MiB in memory, then
to blow up to avoid resource exhaustion.

For 1 GiB downloads, you want to save to a file.
I will expand the documentation.

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.


Back to the top