You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Kalyan Enganti <ka...@gmail.com> on 2012/09/23 17:50:11 UTC

Writing Zipoutputstream to outputstream blocking requests

Hi I am working on an android file explorer application. When a large folder is requested for download I am zipping the folder and writing its contents to the outputstream using the code below.But any further requests are blocked until the file is downloaded.The createZipFile() method takes file name and ouputstream and returns OutPutStreamWriter object.What could be the problem ?Should I consider moving this to a thread?I have tried many variations already and none seem to work.Any pointers in the right direction would be greatly appreciated.

        if(f.isDirectory()&& action.equalsIgnoreCase("download")){        File zip=new File(file);        entity = new EntityTemplate(new ContentProducer() {            public void writeTo(final OutputStream outstream) throws IOException {                action=null;                OutputStreamWriter writer=fileop.createZipFile(file, outstream);                writer.flush();            }        });response.setHeader("Content-Type", "application/zip");        response.setHeader("Content-Disposition","attachment; filename=\"" +zip.getName()+".zip\"");        response.setEntity(entity);    }Thanks Kalz

Re: Writing Zipoutputstream to outputstream blocking requests

Posted by kalyan enganti <ka...@gmail.com>.
HI David.I could find an example after looking around for a bit.Thanks for
you help.

On Mon, Sep 24, 2012 at 3:55 PM, David Motes <da...@gmail.com> wrote:

> I assume you are trying to do the comm on your main thread. Which is
> going to hang the app.
>
>  I have not messed with Android in a while. There are several ways to
> not hang your app, I have used a couple.
>
>  If you  want to do comm and still allow user interaction do the comm
> in another thread and use a CountDownLatch to detect when the comm is
> complete.
>
>  If you just want to avoid blocking do the code as a Task extends
> AsyncTask. There are a few methods you have to implement and you can
> show a "task processing" dialog until the comm is complete.
>
> If you cannot find an example I might be able to scrounge one up...
>
>
>
> On Mon, Sep 24, 2012 at 10:26 AM, kalyan enganti
> <ka...@gmail.com> wrote:
> > Hi David.Thanks for getting back.I have implemented the server using http
> > components on android which serves content based on the uri requested.The
> > idea is to create a wifi-file explorer.The code is running on the
>  android
> > device.
> > Thanks
> > Kalyan
> >
> > On Mon, Sep 24, 2012 at 2:52 PM, David Motes <da...@gmail.com>
> wrote:
> >
> >> Where is this code running? On a server or on the Android device?
> >> Where is the blocking occurring? on server or android?
> >>
> >> On Sun, Sep 23, 2012 at 11:50 AM, Kalyan Enganti
> >> <ka...@gmail.com> wrote:
> >> > Hi I am working on an android file explorer application. When a large
> >> folder is requested for download I am zipping the folder and writing its
> >> contents to the outputstream using the code below.But any further
> requests
> >> are blocked until the file is downloaded.The createZipFile() method
> takes
> >> file name and ouputstream and returns OutPutStreamWriter object.What
> could
> >> be the problem ?Should I consider moving this to a thread?I have tried
> many
> >> variations already and none seem to work.Any pointers in the right
> >> direction would be greatly appreciated.
> >> >
> >> >         if(f.isDirectory()&& action.equalsIgnoreCase("download")){
> >>  File zip=new File(file);        entity = new EntityTemplate(new
> >> ContentProducer() {            public void writeTo(final OutputStream
> >> outstream) throws IOException {                action=null;
> >>  OutputStreamWriter writer=fileop.createZipFile(file, outstream);
> >>      writer.flush();            }
> >>  });response.setHeader("Content-Type", "application/zip");
> >>  response.setHeader("Content-Disposition","attachment; filename=\""
> >> +zip.getName()+".zip\"");        response.setEntity(entity);    }Thanks
> Kalz
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> >> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >>
> >>
> >
> >
> > --
> > Thanks and Regards
> > Kalyan Enganti
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
Thanks and Regards
Kalyan Enganti

Re: Writing Zipoutputstream to outputstream blocking requests

Posted by David Motes <da...@gmail.com>.
I assume you are trying to do the comm on your main thread. Which is
going to hang the app.

 I have not messed with Android in a while. There are several ways to
not hang your app, I have used a couple.

 If you  want to do comm and still allow user interaction do the comm
in another thread and use a CountDownLatch to detect when the comm is
complete.

 If you just want to avoid blocking do the code as a Task extends
AsyncTask. There are a few methods you have to implement and you can
show a "task processing" dialog until the comm is complete.

If you cannot find an example I might be able to scrounge one up...



On Mon, Sep 24, 2012 at 10:26 AM, kalyan enganti
<ka...@gmail.com> wrote:
> Hi David.Thanks for getting back.I have implemented the server using http
> components on android which serves content based on the uri requested.The
> idea is to create a wifi-file explorer.The code is running on the  android
> device.
> Thanks
> Kalyan
>
> On Mon, Sep 24, 2012 at 2:52 PM, David Motes <da...@gmail.com> wrote:
>
>> Where is this code running? On a server or on the Android device?
>> Where is the blocking occurring? on server or android?
>>
>> On Sun, Sep 23, 2012 at 11:50 AM, Kalyan Enganti
>> <ka...@gmail.com> wrote:
>> > Hi I am working on an android file explorer application. When a large
>> folder is requested for download I am zipping the folder and writing its
>> contents to the outputstream using the code below.But any further requests
>> are blocked until the file is downloaded.The createZipFile() method takes
>> file name and ouputstream and returns OutPutStreamWriter object.What could
>> be the problem ?Should I consider moving this to a thread?I have tried many
>> variations already and none seem to work.Any pointers in the right
>> direction would be greatly appreciated.
>> >
>> >         if(f.isDirectory()&& action.equalsIgnoreCase("download")){
>>  File zip=new File(file);        entity = new EntityTemplate(new
>> ContentProducer() {            public void writeTo(final OutputStream
>> outstream) throws IOException {                action=null;
>>  OutputStreamWriter writer=fileop.createZipFile(file, outstream);
>>      writer.flush();            }
>>  });response.setHeader("Content-Type", "application/zip");
>>  response.setHeader("Content-Disposition","attachment; filename=\""
>> +zip.getName()+".zip\"");        response.setEntity(entity);    }Thanks Kalz
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>>
>
>
> --
> Thanks and Regards
> Kalyan Enganti

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: Writing Zipoutputstream to outputstream blocking requests

Posted by kalyan enganti <ka...@gmail.com>.
Hi David.Thanks for getting back.I have implemented the server using http
components on android which serves content based on the uri requested.The
idea is to create a wifi-file explorer.The code is running on the  android
device.
Thanks
Kalyan

On Mon, Sep 24, 2012 at 2:52 PM, David Motes <da...@gmail.com> wrote:

> Where is this code running? On a server or on the Android device?
> Where is the blocking occurring? on server or android?
>
> On Sun, Sep 23, 2012 at 11:50 AM, Kalyan Enganti
> <ka...@gmail.com> wrote:
> > Hi I am working on an android file explorer application. When a large
> folder is requested for download I am zipping the folder and writing its
> contents to the outputstream using the code below.But any further requests
> are blocked until the file is downloaded.The createZipFile() method takes
> file name and ouputstream and returns OutPutStreamWriter object.What could
> be the problem ?Should I consider moving this to a thread?I have tried many
> variations already and none seem to work.Any pointers in the right
> direction would be greatly appreciated.
> >
> >         if(f.isDirectory()&& action.equalsIgnoreCase("download")){
>  File zip=new File(file);        entity = new EntityTemplate(new
> ContentProducer() {            public void writeTo(final OutputStream
> outstream) throws IOException {                action=null;
>  OutputStreamWriter writer=fileop.createZipFile(file, outstream);
>      writer.flush();            }
>  });response.setHeader("Content-Type", "application/zip");
>  response.setHeader("Content-Disposition","attachment; filename=\""
> +zip.getName()+".zip\"");        response.setEntity(entity);    }Thanks Kalz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>


-- 
Thanks and Regards
Kalyan Enganti

Re: Writing Zipoutputstream to outputstream blocking requests

Posted by David Motes <da...@gmail.com>.
Where is this code running? On a server or on the Android device?
Where is the blocking occurring? on server or android?

On Sun, Sep 23, 2012 at 11:50 AM, Kalyan Enganti
<ka...@gmail.com> wrote:
> Hi I am working on an android file explorer application. When a large folder is requested for download I am zipping the folder and writing its contents to the outputstream using the code below.But any further requests are blocked until the file is downloaded.The createZipFile() method takes file name and ouputstream and returns OutPutStreamWriter object.What could be the problem ?Should I consider moving this to a thread?I have tried many variations already and none seem to work.Any pointers in the right direction would be greatly appreciated.
>
>         if(f.isDirectory()&& action.equalsIgnoreCase("download")){        File zip=new File(file);        entity = new EntityTemplate(new ContentProducer() {            public void writeTo(final OutputStream outstream) throws IOException {                action=null;                OutputStreamWriter writer=fileop.createZipFile(file, outstream);                writer.flush();            }        });response.setHeader("Content-Type", "application/zip");        response.setHeader("Content-Disposition","attachment; filename=\"" +zip.getName()+".zip\"");        response.setEntity(entity);    }Thanks Kalz

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org