You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Monica Ruiu <mo...@gmail.com> on 2006/09/04 11:50:16 UTC

[vfs] newbie - extract zip files

Hi,

I need to extract the files contained in a zip after a web upload.

I use Commons Fileupload to get the file

and then I'd like to use VFS to navigate the zip.

I used the VFS to navigate a zip on local filesystem and it is great.

Using FileUpload I get an InputStream,
how can I objtain a ZipFileObject from that InputStream ?

The web application can't access local file system to store data in
temporary files.

Thanks in advance

Monica

Re: [vfs] newbie - extract zip files

Posted by Monica Ruiu <mo...@gmail.com>.
Done! It works fine!

Thanks again for your help

Monica

On 9/4/06, Mario Ivankovits <ma...@ops.co.at> wrote:
>
> Hi Monica!
> > I need to extract the files contained in a zip after a web upload.
> If you have a InputStream only you can feed this stream to the tmp:
> filesystem with something like this:
>
>         FileObject foZip =
> VFS.getManager().resolveFile("tmp:/xml-rpc.net.0.9.2.zip");
>         OutputStream os = foZip.getContent().getOutputStream();
>         byte[] buf = new byte[4096];
>         int read;
>         while ((read = is.read(buf)) > -1)
>         {
>             os.write(buf, 0, read);
>         }
>         os.close();
>         FileObject foZipContent =
> VFS.getManager().resolveFile("zip:tmp:/xml-rpc.net.0.9.2.zip!/");
>         System.err.println(foZipContent.getChildren().length);
>
> But for sure, this requires at least a writable temporary filespace (by
> default the os tmpdir as you can find in java system environment
> "java.io.tmpdir").
> If it is really absolutely not possible to write to the local disk you
> can replace the "tmp:/" in the above example (two times) with "ram:/",
> though, that requires you to have enough memory available to hold the
> zipped data.
>
> Ciao,
> Mario
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: [vfs] newbie - extract zip files

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi Monica!
> I need to extract the files contained in a zip after a web upload.
If you have a InputStream only you can feed this stream to the tmp:
filesystem with something like this:

        FileObject foZip =
VFS.getManager().resolveFile("tmp:/xml-rpc.net.0.9.2.zip");
        OutputStream os = foZip.getContent().getOutputStream();
        byte[] buf = new byte[4096];
        int read;
        while ((read = is.read(buf)) > -1)
        {
            os.write(buf, 0, read);
        }
        os.close();
        FileObject foZipContent =
VFS.getManager().resolveFile("zip:tmp:/xml-rpc.net.0.9.2.zip!/");
        System.err.println(foZipContent.getChildren().length);

But for sure, this requires at least a writable temporary filespace (by
default the os tmpdir as you can find in java system environment
"java.io.tmpdir").
If it is really absolutely not possible to write to the local disk you
can replace the "tmp:/" in the above example (two times) with "ram:/",
though, that requires you to have enough memory available to hold the
zipped data.

Ciao,
Mario


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org